X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=threads.cc;h=d170b7ada3554da89213ab6219fff15c11ed0019;hb=f19a959f1a76e35316df4b8dce39d17640305417;hp=6b4e2c740ab50b7b55f624b7bda05a4c9ad72678;hpb=84d0cd2f078f4cb15c318a0fef2515feab570375;p=c11tester.git diff --git a/threads.cc b/threads.cc index 6b4e2c74..d170b7ad 100644 --- a/threads.cc +++ b/threads.cc @@ -104,12 +104,11 @@ int Thread::swap(ucontext_t *ctxt, Thread *t) /** Terminate a thread and free its stack. */ void Thread::complete() { - if (!is_complete()) { - DEBUG("completed thread %d\n", id_to_int(get_id())); - state = THREAD_COMPLETED; - if (stack) - stack_free(stack); - } + ASSERT(!is_complete()); + DEBUG("completed thread %d\n", id_to_int(get_id())); + state = THREAD_COMPLETED; + if (stack) + stack_free(stack); } /** @@ -169,7 +168,8 @@ Thread::Thread(thrd_t *t, void (*func)(void *), void *a) : /** Destructor */ Thread::~Thread() { - complete(); + if (!is_complete()) + complete(); model->remove_thread(this); } @@ -178,3 +178,13 @@ thread_id_t Thread::get_id() const { return id; } + +/** + * Set a thread's THREAD_* state (@see thread_state) + * @param s The state to enter + */ +void Thread::set_state(thread_state s) +{ + ASSERT(s == THREAD_COMPLETED || state != THREAD_COMPLETED); + state = s; +}