threads: assert completion is only called once
authorBrian Norris <banorris@uci.edu>
Tue, 18 Dec 2012 22:08:19 +0000 (14:08 -0800)
committerBrian Norris <banorris@uci.edu>
Tue, 18 Dec 2012 22:58:32 +0000 (14:58 -0800)
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

index 87de32fb2452f0384016353306b0b0b43c3d4cea..d170b7ada3554da89213ab6219fff15c11ed0019 100644 (file)
@@ -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);
 }