threads/model: move switch_to_master from class Thread to class ModelChecker
[model-checker.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
24         thread_state get_state() { return state; }
25         void set_state(thread_state s) { state = s; }
26         thread_id_t get_id();
27         void set_id(thread_id_t i) { *user_thread = i; }
28         thrd_t get_thrd_t() { return *user_thread; }
29 private:
30         int create_context();
31
32         void (*start_routine)();
33         void *arg;
34         ucontext_t context;
35         void *stack;
36         thrd_t *user_thread;
37         thread_state state;
38 };
39
40 Thread *thread_current();
41
42 static inline thread_id_t thrd_to_id(thrd_t t)
43 {
44         return t;
45 }
46
47 #endif /* __THREADS_INTERNAL_H__ */