* src/threads/threads-common.c (threads_thread_state_runnable): Don't
authorChristian Thalinger <twisti@complang.tuwien.ac.at>
Fri, 14 Sep 2007 18:24:51 +0000 (20:24 +0200)
committerChristian Thalinger <twisti@complang.tuwien.ac.at>
Fri, 14 Sep 2007 18:24:51 +0000 (20:24 +0200)
change the state if the current state is THREAD_STATE_TERMINATED.
(threads_thread_state_waiting): Likewise.
(threads_thread_state_timed_waiting): Likewise.
(threads_thread_is_alive): Smaller changes.
* src/threads/threads-common.h (threads_thread_is_alive): Likewise.

src/threads/threads-common.c
src/threads/threads-common.h

index 33691910e3b2aeccf89e96aae7fd64b2dc8dff86..1212c0b0aeb48df69aa3285f26de6474a97eb026 100644 (file)
@@ -628,15 +628,19 @@ ptrint threads_get_current_tid(void)
 
    Set the current state of the given thread to THREAD_STATE_RUNNABLE.
 
+   NOTE: If the thread has already terminated, don't set the state.
+         This is important for threads_detach_thread.
+
 *******************************************************************************/
 
 void threads_thread_state_runnable(threadobject *t)
 {
-       /* set the state inside the lock */
+       /* Set the state inside a lock. */
 
        threads_list_lock();
 
-       t->state = THREAD_STATE_RUNNABLE;
+       if (t->state != THREAD_STATE_TERMINATED)
+               t->state = THREAD_STATE_RUNNABLE;
 
        threads_list_unlock();
 }
@@ -646,15 +650,19 @@ void threads_thread_state_runnable(threadobject *t)
 
    Set the current state of the given thread to THREAD_STATE_WAITING.
 
+   NOTE: If the thread has already terminated, don't set the state.
+         This is important for threads_detach_thread.
+
 *******************************************************************************/
 
 void threads_thread_state_waiting(threadobject *t)
 {
-       /* set the state in the lock */
+       /* Set the state inside a lock. */
 
        threads_list_lock();
 
-       t->state = THREAD_STATE_WAITING;
+       if (t->state != THREAD_STATE_TERMINATED)
+               t->state = THREAD_STATE_WAITING;
 
        threads_list_unlock();
 }
@@ -665,15 +673,19 @@ void threads_thread_state_waiting(threadobject *t)
    Set the current state of the given thread to
    THREAD_STATE_TIMED_WAITING.
 
+   NOTE: If the thread has already terminated, don't set the state.
+         This is important for threads_detach_thread.
+
 *******************************************************************************/
 
 void threads_thread_state_timed_waiting(threadobject *t)
 {
-       /* set the state in the lock */
+       /* Set the state inside a lock. */
 
        threads_list_lock();
 
-       t->state = THREAD_STATE_TIMED_WAITING;
+       if (t->state != THREAD_STATE_TERMINATED)
+               t->state = THREAD_STATE_TIMED_WAITING;
 
        threads_list_unlock();
 }
@@ -745,32 +757,26 @@ utf *threads_thread_get_state(threadobject *t)
 
 *******************************************************************************/
 
-bool threads_thread_is_alive(threadobject *thread)
+bool threads_thread_is_alive(threadobject *t)
 {
-       bool result;
-
-       switch (thread->state) {
+       switch (t->state) {
        case THREAD_STATE_NEW:
        case THREAD_STATE_TERMINATED:
-               result = false;
-               break;
+               return false;
 
        case THREAD_STATE_RUNNABLE:
        case THREAD_STATE_BLOCKED:
        case THREAD_STATE_WAITING:
        case THREAD_STATE_TIMED_WAITING:
-               result = true;
-               break;
+               return true;
 
        default:
-               vm_abort("threads_is_alive: unknown thread state %d", thread->state);
-
-               /* keep compiler happy */
-
-               result = false;
+               vm_abort("threads_thread_is_alive: unknown thread state %d", t->state);
        }
 
-       return result;
+       /* keep compiler happy */
+
+       return false;
 }
 
 
index 60fd1155833fc0e19bac467dc2c3287d4c8d4cca..54b5e0d418c79db4877d48623af326c6c6c604da 100644 (file)
@@ -95,7 +95,7 @@ void          threads_thread_state_timed_waiting(threadobject *t);
 void          threads_thread_state_terminated(threadobject *t);
 utf          *threads_thread_get_state(threadobject *t);
 
-bool          threads_thread_is_alive(threadobject *thread);
+bool          threads_thread_is_alive(threadobject *t);
 
 void          threads_dump(void);
 void          threads_thread_print_stacktrace(threadobject *thread);