#endif
/* global mutex and condition for joining threads on exit */
-static Mutex* mutex_join;
static Condition* cond_join;
#if defined(ENABLE_GC_CACAO)
/* initialize exit mutex and condition (on exit we join all
threads) */
- mutex_join = new Mutex();
cond_join = new Condition();
#if defined(ENABLE_GC_CACAO)
}
#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.
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. */
/* 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();
/* 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();
}
{
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);
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)) {
{
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);
ThreadList::add_to_active_thread_list(t);
- threads_mutex_join_unlock();
+ Atomic::write_memory_barrier();
ThreadRuntime::setup_thread_vmdata(jlt, t);
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. */
ThreadList::add_to_active_thread_list(t);
- threads_mutex_join_unlock();
-
DEBUGTHREADS("attaching", t);
/* Get the thread name. */