Merged.
[cacao.git] / src / threads / thread.cpp
index 8804f6eb55f06e37d07a6925c0c23545b1beb187..57f8b5c0b1c862b3c8b342d0d74c4eb8d1f5991c 100644 (file)
@@ -948,6 +948,12 @@ void thread_print_info(threadobject *t)
        case THREAD_STATE_TIMED_WAITING:
                printf(" waiting on condition");
                break;
+       case THREAD_STATE_PARKED:
+               printf(" parked");
+               break;
+       case THREAD_STATE_TIMED_PARKED:
+               printf(" timed parked");
+               break;
        case THREAD_STATE_TERMINATED:
                printf(" terminated");
                break;
@@ -1057,6 +1063,56 @@ void thread_set_state_timed_waiting(threadobject *t)
 }
 
 
+/* thread_set_state_parked *****************************************************
+
+   Set the current state of the given thread to THREAD_STATE_PARKED.
+
+   NOTE: If the thread has already terminated, don't set the state.
+         This is important for threads_detach_thread.
+
+*******************************************************************************/
+
+void thread_set_state_parked(threadobject *t)
+{
+       /* Set the state inside a lock. */
+
+       ThreadList::lock();
+
+       if (t->state != THREAD_STATE_TERMINATED) {
+               t->state = THREAD_STATE_PARKED;
+
+               DEBUGTHREADS("is PARKED", t);
+       }
+
+       ThreadList::unlock();
+}
+
+
+/* thread_set_state_timed_parked ***********************************************
+
+   Set the current state of the given thread to THREAD_STATE_TIMED_PARKED.
+
+   NOTE: If the thread has already terminated, don't set the state.
+         This is important for threads_detach_thread.
+
+*******************************************************************************/
+
+void thread_set_state_timed_parked(threadobject *t)
+{
+       /* Set the state inside a lock. */
+
+       ThreadList::lock();
+
+       if (t->state != THREAD_STATE_TERMINATED) {
+               t->state = THREAD_STATE_TIMED_PARKED;
+
+               DEBUGTHREADS("is TIMED_PARKED", t);
+       }
+
+       ThreadList::unlock();
+}
+
+
 /* thread_set_state_terminated *************************************************
 
    Set the current state of the given thread to