Update readme
[c11tester.git] / libthreads.cc
1 #include "threads.h"
2 #include "common.h"
3 #include "threads-model.h"
4 #include "action.h"
5
6
7 /* global "model" object */
8 #include "model.h"
9
10 /*
11  * User program API functions
12  */
13 int thrd_create(thrd_t *t, thrd_start_t start_routine, void *arg)
14 {
15         createModelIfNotExist();
16         struct thread_params params = { start_routine, arg };
17         /* seq_cst is just a 'don't care' parameter */
18         model->switch_thread(new ModelAction(THREAD_CREATE, std::memory_order_seq_cst, t, (uint64_t)&params));
19         return 0;
20 }
21
22 int thrd_join(thrd_t t)
23 {
24         createModelIfNotExist();
25         Thread *th = t.priv;
26         model->switch_thread(new ModelAction(THREAD_JOIN, std::memory_order_seq_cst, th, id_to_int(thrd_to_id(t))));
27         return 0;
28 }
29
30 /** A no-op, for now */
31 void thrd_yield(void)
32 {
33         createModelIfNotExist();
34         model->switch_thread(new ModelAction(THREAD_YIELD, std::memory_order_seq_cst, thread_current(), VALUE_NONE));
35 }
36
37 thrd_t thrd_current(void)
38 {
39         createModelIfNotExist();
40         return thread_current()->get_thrd_t();
41 }