* src/threads/thread.cpp: thread_new no longer adds to active list.
authorStefan Ring <stefan@complang.tuwien.ac.at>
Mon, 18 Apr 2011 19:07:45 +0000 (21:07 +0200)
committerStefan Ring <stefan@complang.tuwien.ac.at>
Mon, 18 Apr 2011 19:07:45 +0000 (21:07 +0200)
* src/threads/threadlist.hpp (add_to_active_thread_list): Take the thread list
lock when changing the thread list.

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

index c8c3abcd808529d7ee6714051bd2b2a2177b6717..15bd67c5898826a6025cd91ea238c058cec4be1e 100644 (file)
@@ -139,6 +139,10 @@ void threads_preinit(void)
 
        mainthread = thread_new(THREAD_FLAG_JAVA);
 
 
        mainthread = thread_new(THREAD_FLAG_JAVA);
 
+       /* Add the thread to the thread list. */
+
+       ThreadList::add_to_active_thread_list(mainthread);
+
        /* The main thread should always have index 1. */
 
        if (mainthread->index != 1)
        /* The main thread should always have index 1. */
 
        if (mainthread->index != 1)
@@ -280,6 +284,10 @@ static threadobject *thread_new(int32_t flags)
 
        t = ThreadList::get_free_thread();
 
 
        t = ThreadList::get_free_thread();
 
+       /* Unlock the thread lists. */
+
+       ThreadList::unlock();
+
        if (t != NULL) {
                /* Equivalent of MZERO on the else path */
 
        if (t != NULL) {
                /* Equivalent of MZERO on the else path */
 
@@ -343,14 +351,6 @@ static threadobject *thread_new(int32_t flags)
 
        threads_impl_thread_reuse(t);
 
 
        threads_impl_thread_reuse(t);
 
-       /* Add the thread to the thread list. */
-
-       ThreadList::add_to_active_thread_list(t);
-
-       /* Unlock the thread lists. */
-
-       ThreadList::unlock();
-
        return t;
 }
 
        return t;
 }
 
@@ -403,6 +403,10 @@ bool threads_thread_start_internal(utf *name, functionptr f)
 
        t = thread_new(THREAD_FLAG_INTERNAL | THREAD_FLAG_DAEMON);
 
 
        t = thread_new(THREAD_FLAG_INTERNAL | THREAD_FLAG_DAEMON);
 
+       /* Add the thread to the thread list. */
+
+       ThreadList::add_to_active_thread_list(t);
+
        /* The thread is flagged as (non-)daemon thread, we can leave the
           mutex. */
 
        /* The thread is flagged as (non-)daemon thread, we can leave the
           mutex. */
 
@@ -454,15 +458,16 @@ void threads_thread_start(java_handle_t *object)
                t->flags |= THREAD_FLAG_DAEMON;
 #endif
 
                t->flags |= THREAD_FLAG_DAEMON;
 #endif
 
-       /* The thread is flagged and (non-)daemon thread, we can leave the
-          mutex. */
-
-       threads_mutex_join_unlock();
-
        /* Link the two objects together. */
 
        thread_set_object(t, object);
 
        /* Link the two objects together. */
 
        thread_set_object(t, object);
 
+       /* Add the thread to the thread list. */
+
+       ThreadList::add_to_active_thread_list(t);
+
+       threads_mutex_join_unlock();
+
        ThreadRuntime::setup_thread_vmdata(jlt, t);
 
        /* Start the thread.  Don't pass a function pointer (NULL) since
        ThreadRuntime::setup_thread_vmdata(jlt, t);
 
        /* Start the thread.  Don't pass a function pointer (NULL) since
@@ -517,6 +522,10 @@ bool thread_attach_current_thread(JavaVMAttachArgs *vm_aargs, bool isdaemon)
        /* The thread is flagged and (non-)daemon thread, we can leave the
           mutex. */
 
        /* The thread is flagged and (non-)daemon thread, we can leave the
           mutex. */
 
+       /* Add the thread to the thread list. */
+
+       ThreadList::add_to_active_thread_list(t);
+
        threads_mutex_join_unlock();
 
        DEBUGTHREADS("attaching", t);
        threads_mutex_join_unlock();
 
        DEBUGTHREADS("attaching", t);
index fdcdd6e5ffbb3019463e74e25d1f4981beda2bcc..0d6043aa72f0bf3499f80f2e25e11e12ff640b9b 100644 (file)
@@ -1,6 +1,6 @@
 /* src/threads/threadlist.hpp - different thread-lists
 
 /* src/threads/threadlist.hpp - different thread-lists
 
-   Copyright (C) 2008, 2009
+   Copyright (C) 1996-2011
    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
 
    This file is part of CACAO.
    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
 
    This file is part of CACAO.
@@ -75,7 +75,6 @@ public:
        static void                 lock()   { _mutex.lock(); }
        static void                 unlock() { _mutex.unlock(); }
 
        static void                 lock()   { _mutex.lock(); }
        static void                 unlock() { _mutex.unlock(); }
 
-       // TODO make private
        static void                 add_to_active_thread_list(threadobject* t);
 
        // Thread management methods.
        static void                 add_to_active_thread_list(threadobject* t);
 
        // Thread management methods.
@@ -113,6 +112,7 @@ struct ThreadListLocker {
 
 inline void ThreadList::add_to_active_thread_list(threadobject* t)
 {
 
 inline void ThreadList::add_to_active_thread_list(threadobject* t)
 {
+       lock();
        _active_thread_list.push_back(t);
 
        // Update counter variables.
        _active_thread_list.push_back(t);
 
        // Update counter variables.
@@ -121,6 +121,7 @@ inline void ThreadList::add_to_active_thread_list(threadobject* t)
                _number_of_active_java_threads++;
                _peak_of_active_java_threads = MAX(_peak_of_active_java_threads, _number_of_active_java_threads);
        }
                _number_of_active_java_threads++;
                _peak_of_active_java_threads = MAX(_peak_of_active_java_threads, _number_of_active_java_threads);
        }
+       unlock();
 }
 
 inline void ThreadList::remove_from_active_thread_list(threadobject* t)
 }
 
 inline void ThreadList::remove_from_active_thread_list(threadobject* t)