From 307adaa624b4ace4011171ab3926e27a94d3ea67 Mon Sep 17 00:00:00 2001 From: Michael Starzinger Date: Fri, 22 Aug 2008 13:14:07 +0200 Subject: [PATCH] * src/vm/finalizer.c (finalizer_thread_mutex, finalizer_thread_cond): Use mutex and condition instead of java object for synchronization. * src/vm/jit/optimizing/recompile.c (recompile_thread_mutex): Likewise. (recompile_thread_cond) Likewise. --- src/vm/finalizer.c | 29 ++++++++++++------------ src/vm/jit/optimizing/recompile.c | 37 ++++++++++++++++--------------- 2 files changed, 34 insertions(+), 32 deletions(-) diff --git a/src/vm/finalizer.c b/src/vm/finalizer.c index b96743ed4..ea331ec96 100644 --- a/src/vm/finalizer.c +++ b/src/vm/finalizer.c @@ -31,7 +31,8 @@ #include "mm/memory.h" -#include "threads/lock-common.h" +#include "threads/condition.hpp" +#include "threads/mutex.hpp" #include "threads/thread.hpp" #include "vm/jit/builtin.hpp" @@ -46,7 +47,8 @@ /* global variables ***********************************************************/ #if defined(ENABLE_THREADS) -static java_object_t *lock_thread_finalizer; +static Mutex *finalizer_thread_mutex; +static Condition *finalizer_thread_cond; #endif @@ -61,9 +63,8 @@ bool finalizer_init(void) TRACESUBSYSTEMINITIALIZATION("finalizer_init"); #if defined(ENABLE_THREADS) - lock_thread_finalizer = NEW(java_object_t); - - LOCK_INIT_OBJECT_LOCK(lock_thread_finalizer); + finalizer_thread_mutex = Mutex_new(); + finalizer_thread_cond = Condition_new(); #endif /* everything's ok */ @@ -84,17 +85,17 @@ bool finalizer_init(void) static void finalizer_thread(void) { while (true) { - /* get the lock on the finalizer lock object, so we can call wait */ + /* get the lock on the finalizer mutex, so we can call wait */ - LOCK_MONITOR_ENTER(lock_thread_finalizer); + Mutex_lock(finalizer_thread_mutex); - /* wait forever on that object till we are signaled */ + /* wait forever on that condition till we are signaled */ - LOCK_WAIT_FOREVER(lock_thread_finalizer); + Condition_wait(finalizer_thread_cond, finalizer_thread_mutex); /* leave the lock */ - LOCK_MONITOR_EXIT(lock_thread_finalizer); + Mutex_unlock(finalizer_thread_mutex); #if !defined(NDEBUG) if (opt_DebugFinalizer) @@ -154,15 +155,15 @@ void finalizer_notify(void) #if defined(ENABLE_THREADS) /* get the lock on the finalizer lock object, so we can call wait */ - LOCK_MONITOR_ENTER(lock_thread_finalizer); + Mutex_lock(finalizer_thread_mutex); /* signal the finalizer thread */ - - LOCK_NOTIFY(lock_thread_finalizer); + + Condition_signal(finalizer_thread_cond); /* leave the lock */ - LOCK_MONITOR_EXIT(lock_thread_finalizer); + Mutex_unlock(finalizer_thread_mutex); #else /* if we don't have threads, just run the finalizers */ diff --git a/src/vm/jit/optimizing/recompile.c b/src/vm/jit/optimizing/recompile.c index 39e75a5e7..4cd12cd86 100644 --- a/src/vm/jit/optimizing/recompile.c +++ b/src/vm/jit/optimizing/recompile.c @@ -32,7 +32,8 @@ #include "mm/memory.h" -#include "threads/lock-common.h" +#include "threads/condition.hpp" +#include "threads/mutex.hpp" #include "threads/thread.hpp" #include "toolbox/list.h" @@ -51,8 +52,9 @@ /* global variables ***********************************************************/ -static java_object_t *lock_thread_recompile; -static list_t *list_recompile_methods; +static Mutex *recompile_thread_mutex; +static Condition *recompile_thread_cond; +static list_t *list_recompile_methods; /* recompile_init ************************************************************** @@ -65,11 +67,10 @@ bool recompile_init(void) { TRACESUBSYSTEMINITIALIZATION("recompile_init"); - /* initialize the recompile lock object */ + /* initialize the recompile thread mutex and condition */ - lock_thread_recompile = NEW(java_object_t); - - LOCK_INIT_OBJECT_LOCK(lock_thread_recompile); + recompile_thread_mutex = Mutex_new(); + recompile_thread_cond = Condition_new(); /* create method list */ @@ -162,17 +163,17 @@ static void recompile_thread(void) list_method_entry *lme; while (true) { - /* get the lock on the recompile lock object, so we can call wait */ + /* get the lock on the recompile mutex, so we can call wait */ + + Mutex_lock(recompile_thread_mutex); - LOCK_MONITOR_ENTER(lock_thread_recompile); + /* wait forever on that condition till we are signaled */ - /* wait forever on that object till we are signaled */ - - LOCK_WAIT_FOREVER(lock_thread_recompile); + Condition_wait(recompile_thread_cond, recompile_thread_mutex); /* leave the lock */ - LOCK_MONITOR_EXIT(lock_thread_recompile); + Mutex_unlock(recompile_thread_mutex); /* get the next method and recompile it */ @@ -243,17 +244,17 @@ void recompile_queue_method(methodinfo *m) list_add_last(list_recompile_methods, lme); - /* get the lock on the recompile lock object, so we can call notify */ + /* get the lock on the recompile mutex, so we can call notify */ - LOCK_MONITOR_ENTER(lock_thread_recompile); + Mutex_lock(recompile_thread_mutex); /* signal the recompiler thread */ - - LOCK_NOTIFY(lock_thread_recompile); + + Condition_signal(recompile_thread_cond); /* leave the lock */ - LOCK_MONITOR_EXIT(lock_thread_recompile); + Mutex_unlock(recompile_thread_mutex); } -- 2.25.1