random memory leak fixes and memory access fixes
[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         DBG();
15         thread = new Thread(t, start_routine, arg);
16         model->add_thread(thread);
17         DEBUG("create thread %d\n", id_to_int(thrd_to_id(*t)));
18         /* seq_cst is just a 'don't care' parameter */
19         model->switch_to_master(new ModelAction(THREAD_CREATE, std::memory_order_seq_cst, thread, VALUE_NONE));
20         return 0;
21 }
22
23 int thrd_join(thrd_t t)
24 {
25         Thread *th = model->get_thread(thrd_to_id(t));
26         model->switch_to_master(new ModelAction(THREAD_JOIN, std::memory_order_seq_cst, th, thrd_to_id(t)));
27         return 0;
28 }
29
30 int thrd_yield(void)
31 {
32         /* seq_cst is just a 'don't care' parameter */
33         return model->switch_to_master(new ModelAction(THREAD_YIELD, std::memory_order_seq_cst, NULL, VALUE_NONE));
34 }
35
36 thrd_t thrd_current(void)
37 {
38         return thread_current()->get_thrd_t();
39 }