From 09b2cb3cabe0d96f62383a8fdd040e7605a1ffc6 Mon Sep 17 00:00:00 2001 From: Brian Norris Date: Tue, 18 Dec 2012 14:08:19 -0800 Subject: [PATCH] threads: assert completion is only called once We don't need to support the case that Thread::complete() is called multiple times. We should instead ensure (ASSERT()) that it is only called when the Thread is not already completed (and cleaned up). --- threads.cc | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/threads.cc b/threads.cc index 87de32fb..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); } -- 2.34.1