.gitignore: add *~ files
[c11tester.git] / threads.h
index 7427eeb59747322195a05ad418adae4a788f2645..345f42077a2372510d5922cd31d26420ed274cd7 100644 (file)
--- a/threads.h
+++ b/threads.h
@@ -5,6 +5,10 @@
 
 #include "libthreads.h"
 
+typedef int thread_id_t;
+
+#define THREAD_ID_T_NONE       -1
+
 typedef enum thread_state {
        THREAD_CREATED,
        THREAD_RUNNING,
@@ -12,36 +16,50 @@ typedef enum thread_state {
        THREAD_COMPLETED
 } thread_state;
 
-class ModelAction;
-
 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; }
+       Thread * get_parent() { return parent; }
 private:
        int create_context();
+       Thread *parent;
 
        void (*start_routine)();
        void *arg;
        ucontext_t context;
        void *stack;
        thrd_t *user_thread;
+       thread_id_t id;
        thread_state state;
 };
 
-Thread *thread_current();
+Thread * thread_current();
 
 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__ */