X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=threads.h;h=7a21a30d8d93f49e4e0c13d37dfeb18f21260b47;hb=3cade2fadc95d3dcbc37f5e6c4da4b8e9b559c23;hp=8e0c3b054dfe7c84a92f60f0cc44ee700db00518;hpb=d279e84ed265af079ea035d5dff49183def2c144;p=model-checker.git diff --git a/threads.h b/threads.h index 8e0c3b0..7a21a30 100644 --- a/threads.h +++ b/threads.h @@ -16,15 +16,18 @@ typedef enum thread_state { class Thread { public: + void * operator new(size_t size); + void operator delete(void *ptr); Thread(thrd_t *t, void (*func)(), void *a); - Thread(thrd_t *t); - int swap(Thread *t); - void dispose(); + ~Thread(); + void complete(); + + static int swap(ucontext_t *ctxt, Thread *t); + static int swap(Thread *t, ucontext_t *ctxt); thread_state get_state() { return state; } void set_state(thread_state s) { state = s; } thread_id_t get_id(); - void set_id(thread_id_t i) { *user_thread = i; } thrd_t get_thrd_t() { return *user_thread; } private: int create_context(); @@ -34,6 +37,7 @@ private: ucontext_t context; void *stack; thrd_t *user_thread; + thread_id_t id; thread_state state; }; @@ -44,4 +48,14 @@ static inline thread_id_t thrd_to_id(thrd_t t) return t; } +static inline thread_id_t int_to_id(int i) +{ + return i; +} + +static inline int id_to_int(thread_id_t id) +{ + return id; +} + #endif /* __THREADS_H__ */