libthreads: add THREAD_* states
authorBrian Norris <banorris@uci.edu>
Tue, 13 Mar 2012 03:38:18 +0000 (20:38 -0700)
committerBrian Norris <banorris@uci.edu>
Tue, 13 Mar 2012 03:38:18 +0000 (20:38 -0700)
libthreads.c
libthreads.h

index 8d76bf12dbf7459cd83d97c18948fa08a39725fd..892d784587b7c00fa22083bde526567729326170 100644 (file)
@@ -70,7 +70,7 @@ int thread_yield(void)
 static void thread_dispose(struct thread *t)
 {
        DEBUG("completed thread %d\n", thread_current()->index);
-       t->completed = 1;
+       t->state = THREAD_COMPLETED;
        stack_free(t->stack);
 }
 
@@ -106,13 +106,15 @@ int thread_create(struct thread *t, void (*start_routine), void *arg)
        if (ret)
                return ret;
 
+       t->state = THREAD_CREATED;
+
        model->scheduler->add_thread(t);
        return 0;
 }
 
 void thread_join(struct thread *t)
 {
-       while (!t->completed)
+       while (t->state != THREAD_COMPLETED)
                thread_yield();
 }
 
index c0eb7d75c658e2e5d3de1842cefa75b67ec0b383..bf7acae804bc58a99d85cf883f9cf3d14e8b1bac 100644 (file)
@@ -3,13 +3,20 @@
 
 #include <ucontext.h>
 
+typedef enum thread_state {
+       THREAD_CREATED,
+       THREAD_RUNNING,
+       THREAD_READY,
+       THREAD_COMPLETED
+} thread_state;
+
 struct thread {
        void (*start_routine);
        void *arg;
        ucontext_t context;
        void *stack;
        int index;
-       int completed;
+       thread_state state;
 };
 
 int thread_create(struct thread *t, void (*start_routine), void *arg);