libthreads: split into libthreads and threads
[c11tester.git] / threads_internal.h
1 #ifndef __THREADS_INTERNAL_H__
2 #define __THREADS_INTERNAL_H__
3
4 #include <ucontext.h>
5
6 #include "libthreads.h"
7
8 typedef enum thread_state {
9         THREAD_CREATED,
10         THREAD_RUNNING,
11         THREAD_READY,
12         THREAD_COMPLETED
13 } thread_state;
14
15 class ModelAction;
16
17 class Thread {
18 public:
19         Thread(thrd_t *t, void (*func)(), void *a);
20         Thread(thrd_t *t);
21         int swap(Thread *t);
22         void dispose();
23         int switch_to_master(ModelAction *act);
24
25         thread_state get_state() { return state; }
26         void set_state(thread_state s) { state = s; }
27         thread_id_t get_id();
28         void set_id(thread_id_t i) { *user_thread = i; }
29         thrd_t get_thrd_t() { return *user_thread; }
30 private:
31         int create_context();
32
33         void (*start_routine)();
34         void *arg;
35         ucontext_t context;
36         void *stack;
37         thrd_t *user_thread;
38         thread_state state;
39 };
40
41 Thread *thread_current();
42
43 static inline thread_id_t thrd_to_id(thrd_t t)
44 {
45         return t;
46 }
47
48 #endif /* __THREADS_INTERNAL_H__ */