major rewrite - 'struct thread' replaced with internal 'class Thread'
[model-checker.git] / threads_internal.h
index 0fde64b768bb2cb7f37efc943fca5c4a42b8e3ca..2f17f57f2091d0870eeafd40a71bcdc5344036ea 100644 (file)
@@ -1,9 +1,43 @@
 #ifndef __THREADS_INTERNAL_H__
 #define __THREADS_INTERNAL_H__
 
-#include "model.h"
+#include <ucontext.h>
+
 #include "libthreads.h"
 
-int thread_switch_to_master(ModelAction *act);
+typedef enum thread_state {
+       THREAD_CREATED,
+       THREAD_RUNNING,
+       THREAD_READY,
+       THREAD_COMPLETED
+} thread_state;
+
+class ModelAction;
+
+class Thread {
+public:
+       Thread(thrd_t *t, void (*func)(), void *a);
+       Thread(thrd_t *t);
+       int swap(Thread *t);
+       void dispose();
+       int switch_to_master(ModelAction *act);
+
+       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();
+
+       void (*start_routine)();
+       void *arg;
+       ucontext_t context;
+       void *stack;
+       thrd_t *user_thread;
+       thread_state state;
+};
+
+Thread *thread_current();
 
 #endif /* __THREADS_INTERNAL_H__ */