Merge branch 'brian'
[c11tester.git] / libthreads.cc
index fd6259ad64d62474e0f7b7565cc72685e56288ad..a414686dccb713116bad22a1e6126f590b72cc7b 100644 (file)
@@ -1,6 +1,6 @@
 #include "libthreads.h"
 #include "common.h"
-#include "threads_internal.h"
+#include "threads.h"
 
 /* global "model" object */
 #include "model.h"
@@ -8,12 +8,16 @@
 /*
  * User program API functions
  */
-int thrd_create(thrd_t *t, void (*start_routine)(), void *arg)
+int thrd_create(thrd_t *t, thrd_start_t start_routine, void *arg)
 {
+       Thread *thread;
        int ret;
        DBG();
-       ret = model->add_thread(new Thread(t, start_routine, arg));
-       DEBUG("create thread %d\n", thrd_to_id(*t));
+       thread = new Thread(t, start_routine, arg);
+       ret = model->add_thread(thread);
+       DEBUG("create thread %d\n", id_to_int(thrd_to_id(*t)));
+       /* seq_cst is just a 'don't care' parameter */
+       model->switch_to_master(new ModelAction(THREAD_CREATE, memory_order_seq_cst, thread, VALUE_NONE));
        return ret;
 }
 
@@ -22,15 +26,14 @@ int thrd_join(thrd_t t)
        int ret = 0;
        Thread *th = model->get_thread(thrd_to_id(t));
        while (th->get_state() != THREAD_COMPLETED && !ret)
-               /* seq_cst is just a 'don't care' parameter */
-               ret = thread_current()->switch_to_master(new ModelAction(THREAD_JOIN, memory_order_seq_cst, NULL, VALUE_NONE));
+               ret = model->switch_to_master(NULL);
        return ret;
 }
 
 int thrd_yield(void)
 {
        /* seq_cst is just a 'don't care' parameter */
-       return thread_current()->switch_to_master(new ModelAction(THREAD_YIELD, memory_order_seq_cst, NULL, VALUE_NONE));
+       return model->switch_to_master(new ModelAction(THREAD_YIELD, memory_order_seq_cst, NULL, VALUE_NONE));
 }
 
 thrd_t thrd_current(void)