From 9c1aaf5e763988911dc3c22c8a52e1cb31c2727c Mon Sep 17 00:00:00 2001 From: Stefan Ring Date: Mon, 18 Apr 2011 21:07:45 +0200 Subject: [PATCH] * src/threads/thread.cpp: thread_new no longer adds to active list. * src/threads/threadlist.hpp (add_to_active_thread_list): Take the thread list lock when changing the thread list. --- src/threads/thread.cpp | 35 ++++++++++++++++++++++------------- src/threads/threadlist.hpp | 5 +++-- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/src/threads/thread.cpp b/src/threads/thread.cpp index c8c3abcd8..15bd67c58 100644 --- a/src/threads/thread.cpp +++ b/src/threads/thread.cpp @@ -139,6 +139,10 @@ void threads_preinit(void) 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) @@ -280,6 +284,10 @@ static threadobject *thread_new(int32_t flags) t = ThreadList::get_free_thread(); + /* Unlock the thread lists. */ + + ThreadList::unlock(); + 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); - /* Add the thread to the thread list. */ - - ThreadList::add_to_active_thread_list(t); - - /* Unlock the thread lists. */ - - ThreadList::unlock(); - return t; } @@ -403,6 +403,10 @@ bool threads_thread_start_internal(utf *name, functionptr f) 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. */ @@ -454,15 +458,16 @@ void threads_thread_start(java_handle_t *object) 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); + /* 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 @@ -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. */ + /* Add the thread to the thread list. */ + + ThreadList::add_to_active_thread_list(t); + threads_mutex_join_unlock(); DEBUGTHREADS("attaching", t); diff --git a/src/threads/threadlist.hpp b/src/threads/threadlist.hpp index fdcdd6e5f..0d6043aa7 100644 --- a/src/threads/threadlist.hpp +++ b/src/threads/threadlist.hpp @@ -1,6 +1,6 @@ /* 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. @@ -75,7 +75,6 @@ public: 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. @@ -113,6 +112,7 @@ struct ThreadListLocker { inline void ThreadList::add_to_active_thread_list(threadobject* t) { + lock(); _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); } + unlock(); } inline void ThreadList::remove_from_active_thread_list(threadobject* t) -- 2.25.1