model: make comment more accurate
[c11tester.git] / libthreads.cc
1 #include "libthreads.h"
2 #include "common.h"
3 #include "threads.h"
4
5 /* global "model" object */
6 #include "model.h"
7
8 /*
9  * User program API functions
10  */
11 int thrd_create(thrd_t *t, thrd_start_t start_routine, void *arg)
12 {
13         Thread *thread;
14         int ret;
15         DBG();
16         thread = new Thread(t, start_routine, arg);
17         ret = model->add_thread(thread);
18         DEBUG("create thread %d\n", id_to_int(thrd_to_id(*t)));
19         /* seq_cst is just a 'don't care' parameter */
20         model->switch_to_master(new ModelAction(THREAD_CREATE, memory_order_seq_cst, thread, VALUE_NONE));
21         return ret;
22 }
23
24 int thrd_join(thrd_t t)
25 {
26         int ret = 0;
27         Thread *th = model->get_thread(thrd_to_id(t));
28         while (th->get_state() != THREAD_COMPLETED && !ret)
29                 ret = model->switch_to_master(NULL);
30         return ret;
31 }
32
33 int thrd_yield(void)
34 {
35         /* seq_cst is just a 'don't care' parameter */
36         return model->switch_to_master(new ModelAction(THREAD_YIELD, memory_order_seq_cst, NULL, VALUE_NONE));
37 }
38
39 thrd_t thrd_current(void)
40 {
41         return thread_current()->get_thrd_t();
42 }