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