threads: add parent info + get_parent() method
[model-checker.git] / threads.cc
index dc7202e3aaa08e4e9dc00d8d6a40e6c04834180e..cc939318938170da4712191ab7ea7bd20e78140b 100644 (file)
@@ -33,10 +33,6 @@ int Thread::create_context()
        if (ret)
                return ret;
 
-       /* start_routine == NULL means this is our initial context */
-       if (!start_routine)
-               return 0;
-
        /* Initialize new managed context */
        stack = stack_allocate(STACK_SIZE);
        context.uc_stack.ss_sp = stack;
@@ -91,20 +87,7 @@ Thread::Thread(thrd_t *t, void (*func)(), void *a) {
        state = THREAD_CREATED;
        id = model->get_next_id();
        *user_thread = id;
-}
-
-Thread::Thread(thrd_t *t) {
-       /* system thread */
-       user_thread = t;
-       start_routine = NULL;
-       arg = NULL;
-
-       create_context();
-       stack = NULL;
-       state = THREAD_CREATED;
-       id = model->get_next_id();
-       *user_thread = id;
-       model->set_system_context(&context);
+       parent = thread_current();
 }
 
 Thread::~Thread()
@@ -134,7 +117,7 @@ static int thread_system_next(void)
                        /* Stopped while running; i.e., completed */
                        curr->complete();
                else
-                       DEBUG("ERROR: current thread in unexpected state??\n");
+                       ASSERT(false);
        }
        next = model->scheduler->next_thread();
        if (next)
@@ -170,7 +153,7 @@ int main()
 
        do {
                /* Start user program */
-               thrd_create(&user_thread, &user_main, NULL);
+               model->add_thread(new Thread(&user_thread, &user_main, NULL));
 
                /* Wait for all threads to complete */
                thread_wait_finish();