From: Stefan Ring Date: Mon, 18 Apr 2011 20:03:04 +0000 (+0200) Subject: * src/threads/posix/thread-posix.cpp: Removed mutex_join. The thread list X-Git-Url: http://wien.tomnetworks.com/gitweb/?p=cacao.git;a=commitdiff_plain;h=dd9e483108a6445825b7b0ec93bd58b6f3639983 * src/threads/posix/thread-posix.cpp: Removed mutex_join. The thread list lock serves the same purpose now. * src/threads/thread.cpp: Likewise, adapted. * src/threads/thread.hpp: Likewise. * src/threads/threadlist.hpp: Likewise. --- diff --git a/src/threads/posix/thread-posix.cpp b/src/threads/posix/thread-posix.cpp index 9b238ce41..ce03f8016 100644 --- a/src/threads/posix/thread-posix.cpp +++ b/src/threads/posix/thread-posix.cpp @@ -209,7 +209,6 @@ static Mutex* mutex_gc; #endif /* global mutex and condition for joining threads on exit */ -static Mutex* mutex_join; static Condition* cond_join; #if defined(ENABLE_GC_CACAO) @@ -555,7 +554,6 @@ void threads_impl_preinit(void) /* initialize exit mutex and condition (on exit we join all threads) */ - mutex_join = new Mutex(); cond_join = new Condition(); #if defined(ENABLE_GC_CACAO) @@ -600,30 +598,6 @@ void threads_mutex_gc_unlock(void) } #endif -/* threads_mutex_join_lock ***************************************************** - - Enter the join mutex. - -*******************************************************************************/ - -void threads_mutex_join_lock(void) -{ - mutex_join->lock(); -} - - -/* threads_mutex_join_unlock *************************************************** - - Leave the join mutex. - -*******************************************************************************/ - -void threads_mutex_join_unlock(void) -{ - mutex_join->unlock(); -} - - /* threads_impl_init *********************************************************** Initializes the implementation specific bits. @@ -1015,11 +989,7 @@ bool thread_detach_current_thread(void) t->tid = 0; t->waitmutex->unlock(); - /* Enter the join-mutex before calling thread_free, so - threads_join_all_threads gets the correct number of non-daemon - threads. */ - - threads_mutex_join_lock(); + ThreadList::lock(); /* Free the internal thread data-structure. */ @@ -1028,7 +998,7 @@ bool thread_detach_current_thread(void) /* Signal that this thread has finished and leave the mutex. */ cond_join->signal(); - threads_mutex_join_unlock(); + ThreadList::unlock(); t->suspendmutex->lock(); t->suspendmutex->unlock(); @@ -1201,18 +1171,18 @@ void threads_join_all_threads(void) /* enter join mutex */ - threads_mutex_join_lock(); + ThreadList::lock(); /* Wait for condition as long as we have non-daemon threads. We compare against 1 because the current (main thread) is also a non-daemon thread. */ while (ThreadList::get_number_of_non_daemon_threads() > 1) - cond_join->wait(mutex_join); + ThreadList::wait_cond(cond_join); /* leave join mutex */ - threads_mutex_join_unlock(); + ThreadList::unlock(); } diff --git a/src/threads/thread.cpp b/src/threads/thread.cpp index 98945a5db..ab0e05e2f 100644 --- a/src/threads/thread.cpp +++ b/src/threads/thread.cpp @@ -398,12 +398,6 @@ bool threads_thread_start_internal(utf *name, functionptr f) { threadobject *t; - /* Enter the join-mutex, so if the main-thread is currently - waiting to join all threads, the number of non-daemon threads - is correct. */ - - threads_mutex_join_lock(); - /* Create internal thread data-structure. */ t = thread_new(THREAD_FLAG_INTERNAL | THREAD_FLAG_DAEMON); @@ -412,11 +406,6 @@ bool threads_thread_start_internal(utf *name, functionptr f) ThreadList::add_to_active_thread_list(t); - /* The thread is flagged as (non-)daemon thread, we can leave the - mutex. */ - - threads_mutex_join_unlock(); - /* Create the Java thread object. */ if (!thread_create_object(t, javastring_new(name), threadgroup_system)) { @@ -450,23 +439,18 @@ void threads_thread_start(java_handle_t *object) { java_lang_Thread jlt(object); - /* Enter the join-mutex, so if the main-thread is currently - waiting to join all threads, the number of non-daemon threads - is correct. */ - - threads_mutex_join_lock(); - /* Create internal thread data-structure. */ - threadobject* t = thread_new(THREAD_FLAG_JAVA); - + u4 flags = THREAD_FLAG_JAVA; #if defined(ENABLE_JAVASE) /* Is this a daemon thread? */ - if (jlt.get_daemon() == true) - t->flags |= THREAD_FLAG_DAEMON; + if (jlt.get_daemon()) + flags |= THREAD_FLAG_DAEMON; #endif + threadobject* t = thread_new(flags); + /* Link the two objects together. */ t->object = LLNI_DIRECT(object); @@ -475,7 +459,7 @@ void threads_thread_start(java_handle_t *object) ThreadList::add_to_active_thread_list(t); - threads_mutex_join_unlock(); + Atomic::write_memory_barrier(); ThreadRuntime::setup_thread_vmdata(jlt, t); @@ -513,18 +497,13 @@ bool thread_attach_current_thread(JavaVMAttachArgs *vm_aargs, bool isdaemon) if (result == true) return true; - /* Enter the join-mutex, so if the main-thread is currently - waiting to join all threads, the number of non-daemon threads - is correct. */ - - threads_mutex_join_lock(); - /* Create internal thread data structure. */ - t = thread_new(THREAD_FLAG_JAVA); - + u4 flags = THREAD_FLAG_JAVA; if (isdaemon) - t->flags |= THREAD_FLAG_DAEMON; + flags |= THREAD_FLAG_DAEMON; + + t = thread_new(flags); /* Store the internal thread data-structure in the TSD. */ @@ -537,8 +516,6 @@ bool thread_attach_current_thread(JavaVMAttachArgs *vm_aargs, bool isdaemon) ThreadList::add_to_active_thread_list(t); - threads_mutex_join_unlock(); - DEBUGTHREADS("attaching", t); /* Get the thread name. */ diff --git a/src/threads/thread.hpp b/src/threads/thread.hpp index 0804b81f7..30eee48f3 100644 --- a/src/threads/thread.hpp +++ b/src/threads/thread.hpp @@ -248,9 +248,6 @@ void threads_mutex_gc_lock(void); void threads_mutex_gc_unlock(void); #endif -void threads_mutex_join_lock(void); -void threads_mutex_join_unlock(void); - void threads_impl_thread_clear(threadobject *t); void threads_impl_thread_reuse(threadobject *t); void threads_impl_clear_heap_pointers(threadobject *t); diff --git a/src/threads/threadlist.hpp b/src/threads/threadlist.hpp index 76cd7c553..4ca60a85d 100644 --- a/src/threads/threadlist.hpp +++ b/src/threads/threadlist.hpp @@ -74,6 +74,7 @@ private: public: static void lock() { _mutex.lock(); } static void unlock() { _mutex.unlock(); } + static void wait_cond(Condition *cond) { cond->wait(_mutex); } static void add_to_active_thread_list(threadobject* t);