X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=src%2Fthreads%2Fposix%2Fthread-posix.cpp;h=058a3bda94522821d1b4bd600e21c667137f17cb;hb=faf9ced36a84879b43e9b41783ba891cce356dd0;hp=ce67723f47f6a73839a2e647013393f9f51ba5b7;hpb=e6571845c0eb52b0f784d2b0b7a6af2233d237c4;p=cacao.git diff --git a/src/threads/posix/thread-posix.cpp b/src/threads/posix/thread-posix.cpp index ce67723f4..058a3bda9 100644 --- a/src/threads/posix/thread-posix.cpp +++ b/src/threads/posix/thread-posix.cpp @@ -1,6 +1,6 @@ /* src/threads/posix/thread-posix.cpp - POSIX thread functions - Copyright (C) 1996-2005, 2006, 2007, 2008, 2010 + Copyright (C) 1996-2011 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO This file is part of CACAO. @@ -459,6 +459,7 @@ void threads_impl_thread_clear(threadobject *t) t->index = 0; t->flags = 0; t->state = 0; + t->is_in_active_list = false; t->tid = 0; @@ -532,6 +533,11 @@ void threads_impl_thread_reuse(threadobject *t) #endif } +void threads_impl_clear_heap_pointers(threadobject *t) +{ + t->object = 0; + t->flc_object = 0; +} /* threads_impl_preinit ******************************************************** @@ -767,36 +773,14 @@ static void *threads_startup_thread(void *arg) /* find and run the Thread.run()V method if no other function was passed */ if (function == NULL) { -#if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH) - /* We need to start the run method of - java.lang.VMThread. Since this is a final class, we can use - the class object directly. */ - - c = class_java_lang_VMThread; -#elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK) || defined(WITH_JAVA_RUNTIME_LIBRARY_CLDC1_1) - LLNI_class_get(object, c); -#else -# error unknown classpath configuration -#endif + c = ThreadRuntime::get_thread_class_from_object(object); m = class_resolveclassmethod(c, utf_run, utf_void__void, c, true); if (m == NULL) vm_abort("threads_startup_thread: run() method not found in class"); -#if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH) - - // We need to start the run method of java.lang.VMThread. - java_lang_VMThread jlvmt(jlt.get_vmThread()); - java_handle_t* h = jlvmt.get_handle(); - -#elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK) || defined(WITH_JAVA_RUNTIME_LIBRARY_CLDC1_1) - - java_handle_t* h = jlt.get_handle(); - -#else -# error unknown classpath configuration -#endif + java_handle_t *h = ThreadRuntime::get_vmthread_handle(jlt); /* Run the thread. */ @@ -959,15 +943,7 @@ bool thread_detach_current_thread(void) to build the java_lang_Thread_UncaughtExceptionHandler header file with cacaoh. */ -# if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH) - - java_handle_t* handler = jlt.get_exceptionHandler(); - -# elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK) - - java_handle_t* handler = jlt.get_uncaughtExceptionHandler(); - -# endif + java_handle_t *handler = ThreadRuntime::get_thread_exception_handler(jlt); classinfo* c; java_handle_t* h; @@ -1004,21 +980,7 @@ bool thread_detach_current_thread(void) classinfo* c; LLNI_class_get(group, c); -# if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH) - methodinfo* m = class_resolveclassmethod(c, - utf_removeThread, - utf_java_lang_Thread__V, - class_java_lang_ThreadGroup, - true); -# elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK) - methodinfo* m = class_resolveclassmethod(c, - utf_remove, - utf_java_lang_Thread__V, - class_java_lang_ThreadGroup, - true); -# else -# error unknown classpath configuration -# endif + methodinfo *m = ThreadRuntime::get_threadgroup_remove_method(c); if (m == NULL) return false; @@ -1049,6 +1011,10 @@ bool thread_detach_current_thread(void) /* XXX Care about exceptions? */ (void) lock_monitor_exit(jlt.get_handle()); + t->waitmutex->lock(); + 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. */ @@ -1064,6 +1030,9 @@ bool thread_detach_current_thread(void) cond_join->signal(); threads_mutex_join_unlock(); + t->suspendmutex->lock(); + t->suspendmutex->unlock(); + return true; } @@ -1096,7 +1065,8 @@ static void threads_suspend_self() #endif // Release the suspension mutex and wait till we are resumed. - thread->suspendcond->wait(thread->suspendmutex); + while (thread->suspend_reason != SUSPEND_REASON_NONE) + thread->suspendcond->wait(thread->suspendmutex); #if defined(ENABLE_GC_CACAO) // XXX This is propably not ok! @@ -1116,7 +1086,7 @@ static void threads_suspend_self() /** * Suspend the passed thread. Execution of that thread stops until the thread - * is explicitly resumend again. + * is explicitly resumed again. * * @param thread The thread to be suspended. * @param reason Reason for suspending the given thread. @@ -1148,13 +1118,14 @@ bool threads_suspend_thread(threadobject *thread, int32_t reason) } else { // Send the suspend signal to the other thread. + if (!thread->tid) + return false; if (pthread_kill(thread->tid, SIGUSR1) != 0) os::abort_errno("threads_suspend_thread: pthread_kill failed"); // Wait for the thread to acknowledge the suspension. - // XXX A possible optimization would be to not wait here, but you - // better think this through twice before trying it! - thread->suspendcond->wait(thread->suspendmutex); + while (!thread->suspended) + thread->suspendcond->wait(thread->suspendmutex); } return true; @@ -1445,7 +1416,8 @@ void threads_thread_interrupt(threadobject *t) /* Interrupt blocking system call using a signal. */ - pthread_kill(t->tid, Signal_INTERRUPT_SYSTEM_CALL); + if (t->tid) + pthread_kill(t->tid, Signal_INTERRUPT_SYSTEM_CALL); t->waitcond->signal();