X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=src%2Fthreads%2Fthreadlist.cpp;h=0350a1620b150f24aabcda1ca07462c671cc7bb3;hb=faf9ced36a84879b43e9b41783ba891cce356dd0;hp=70ad276835fb61cb07e10f95bf53e122172faa53;hpb=e17ec955bb142b2049d0ffb2ccb65e799d1c6557;p=cacao.git diff --git a/src/threads/threadlist.cpp b/src/threads/threadlist.cpp index 70ad27683..0350a1620 100644 --- a/src/threads/threadlist.cpp +++ b/src/threads/threadlist.cpp @@ -64,7 +64,7 @@ void ThreadList::dump_threads() // Lock the thread lists. lock(); - printf("Full thread dump CACAO "VERSION":\n"); + printf("Full thread dump CACAO "VERSION_FULL":\n"); // Iterate over all started threads. threadobject* self = THREADOBJECT; @@ -158,13 +158,17 @@ threadobject* ThreadList::get_free_thread() { threadobject* t = NULL; + lock(); + // Do we have free threads in the free-list? if (_free_thread_list.empty() == false) { // Yes, get the index and remove it from the free list. - threadobject* t = _free_thread_list.front(); + t = _free_thread_list.front(); _free_thread_list.remove(t); } + unlock(); + return t; } @@ -178,6 +182,8 @@ int32_t ThreadList::get_free_thread_index() { int32_t index; + lock(); + // Do we have free indexes in the free-list? if (_free_index_list.empty() == false) { // Yes, get the index and remove it from the free list. @@ -189,6 +195,8 @@ int32_t ThreadList::get_free_thread_index() index = _active_thread_list.size() + 1; } + unlock(); + return index; } @@ -313,18 +321,28 @@ threadobject* ThreadList::get_thread_from_java_object(java_handle_t* h) return NULL; } +void ThreadList::deactivate_thread(threadobject *t) +{ + ThreadListLocker lock; + remove_from_active_thread_list(t); + threads_impl_clear_heap_pointers(t); // allow it to be garbage collected +} /** * Release the thread. * * @return free thread index */ -void ThreadList::release_thread(threadobject* t) +void ThreadList::release_thread(threadobject* t, bool needs_deactivate) { lock(); - // Move thread from active thread list to free thread list. - remove_from_active_thread_list(t); + if (needs_deactivate) + // Move thread from active thread list to free thread list. + remove_from_active_thread_list(t); + else + assert(!t->is_in_active_list); + add_to_free_thread_list(t); // Add thread index to free index list. @@ -340,7 +358,6 @@ extern "C" { void ThreadList_lock() { ThreadList::lock(); } void ThreadList_unlock() { ThreadList::unlock(); } void ThreadList_dump_threads() { ThreadList::dump_threads(); } - void ThreadList_release_thread(threadobject* t) { ThreadList::release_thread(t); } threadobject* ThreadList_get_free_thread() { return ThreadList::get_free_thread(); } int32_t ThreadList_get_free_thread_index() { return ThreadList::get_free_thread_index(); } void ThreadList_add_to_active_thread_list(threadobject* t) { ThreadList::add_to_active_thread_list(t); }