X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=threads.h;h=7d2189b49d9f098a775b1cc158390cf76f49cbf4;hb=2866fe7049df652f89f3bfc1cc85ad65b3a150f8;hp=4a8025137013f3c4d9a20c8149cab709f2a1f108;hpb=c0eda11361a71ff8cef84164ddedab9dd875c20a;p=model-checker.git diff --git a/threads.h b/threads.h index 4a80251..7d2189b 100644 --- a/threads.h +++ b/threads.h @@ -2,9 +2,11 @@ #define __THREADS_H__ #include - +#include "mymemory.h" #include "libthreads.h" +typedef int thread_id_t; + #define THREAD_ID_T_NONE -1 typedef enum thread_state { @@ -14,22 +16,35 @@ typedef enum thread_state { THREAD_COMPLETED } thread_state; +class ModelAction; + class Thread { public: - Thread(thrd_t *t, void (*func)(), void *a); - Thread(thrd_t *t); + Thread(thrd_t *t, void (*func)(void *), void *a); ~Thread(); void complete(); - int swap(Thread *t); + + 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(); thrd_t get_thrd_t() { return *user_thread; } + Thread * get_parent() { return parent; } + + void set_creation(ModelAction *act) { creation = act; } + ModelAction * get_creation() { return creation; } + + friend void thread_startup(); + + SNAPSHOTALLOC private: int create_context(); + Thread *parent; + ModelAction *creation; - void (*start_routine)(); + void (*start_routine)(void *); void *arg; ucontext_t context; void *stack; @@ -45,4 +60,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__ */