libthreads: only record 'final' even for thrd_join
[model-checker.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, void (*start_routine)(), void *arg)
12 {
13         int ret;
14         DBG();
15         ret = model->add_thread(new Thread(t, start_routine, arg));
16         DEBUG("create thread %d\n", thrd_to_id(*t));
17         return ret;
18 }
19
20 int thrd_join(thrd_t t)
21 {
22         int ret = 0;
23         Thread *th = model->get_thread(thrd_to_id(t));
24         while (th->get_state() != THREAD_COMPLETED && !ret)
25                 ret = model->switch_to_master(NULL);
26         /* seq_cst is just a 'don't care' parameter */
27         ret = model->switch_to_master(new ModelAction(THREAD_JOIN, memory_order_seq_cst, NULL, VALUE_NONE));
28         return ret;
29 }
30
31 int thrd_yield(void)
32 {
33         /* seq_cst is just a 'don't care' parameter */
34         return model->switch_to_master(new ModelAction(THREAD_YIELD, memory_order_seq_cst, NULL, VALUE_NONE));
35 }
36
37 thrd_t thrd_current(void)
38 {
39         return thread_current()->get_thrd_t();
40 }