/** 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);
}
/**
model_print("Error in create_context\n");
id = model->get_next_id();
- *user_thread = id;
+ user_thread->priv = this;
parent = thread_current();
}
/** Destructor */
Thread::~Thread()
{
- complete();
+ if (!is_complete())
+ complete();
model->remove_thread(this);
}
{
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;
+}