From 9d5424201af87d2824eb9411f1afa42e82e2f602 Mon Sep 17 00:00:00 2001 From: Brian Norris Date: Mon, 12 Mar 2012 20:38:18 -0700 Subject: [PATCH] libthreads: add THREAD_* states --- libthreads.c | 6 ++++-- libthreads.h | 9 ++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/libthreads.c b/libthreads.c index 8d76bf1..892d784 100644 --- a/libthreads.c +++ b/libthreads.c @@ -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(); } diff --git a/libthreads.h b/libthreads.h index c0eb7d7..bf7acae 100644 --- a/libthreads.h +++ b/libthreads.h @@ -3,13 +3,20 @@ #include +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); -- 2.34.1