* src/threads/posix/thread-posix.cpp: Removed mutex_join. The thread list
authorStefan Ring <stefan@complang.tuwien.ac.at>
Mon, 18 Apr 2011 20:03:04 +0000 (22:03 +0200)
committerStefan Ring <stefan@complang.tuwien.ac.at>
Mon, 18 Apr 2011 20:03:04 +0000 (22:03 +0200)
lock serves the same purpose now.
* src/threads/thread.cpp: Likewise, adapted.
* src/threads/thread.hpp: Likewise.
* src/threads/threadlist.hpp: Likewise.

src/threads/posix/thread-posix.cpp
src/threads/thread.cpp
src/threads/thread.hpp
src/threads/threadlist.hpp

index 9b238ce419ab891fcae41cf5ce90df0ae9feb9c4..ce03f801636ba8632a11cc2831ea393155d40c4e 100644 (file)
@@ -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();
 }
 
 
index 98945a5db9edd4f8a13db9db43c8f99a2f43e596..ab0e05e2fe7315bf9dfd2578aafe702199075130 100644 (file)
@@ -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. */
index 0804b81f7c3172bdea73a9f87efd231d818fa03b..30eee48f3f944cc525b4fc0bf822946af56f101b 100644 (file)
@@ -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);
index 76cd7c5538f5dcc58ad80db775337bdf53e078fb..4ca60a85dea0f13c5780d854c2ec4a3e29ec1e3f 100644 (file)
@@ -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);