threads: remove leftover class 'prototype'
[model-checker.git] / threads.h
1 #ifndef __THREADS_H__
2 #define __THREADS_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 Thread {
16 public:
17         Thread(thrd_t *t, void (*func)(), void *a);
18         Thread(thrd_t *t);
19         int swap(Thread *t);
20         void dispose();
21
22         thread_state get_state() { return state; }
23         void set_state(thread_state s) { state = s; }
24         thread_id_t get_id();
25         void set_id(thread_id_t i) { *user_thread = i; }
26         thrd_t get_thrd_t() { return *user_thread; }
27 private:
28         int create_context();
29
30         void (*start_routine)();
31         void *arg;
32         ucontext_t context;
33         void *stack;
34         thrd_t *user_thread;
35         thread_state state;
36 };
37
38 Thread *thread_current();
39
40 static inline thread_id_t thrd_to_id(thrd_t t)
41 {
42         return t;
43 }
44
45 #endif /* __THREADS_H__ */