#define __THREADS_H__
#include <ucontext.h>
-
+#include "mymemory.h"
#include "libthreads.h"
+typedef int thread_id_t;
+
#define THREAD_ID_T_NONE -1
typedef enum thread_state {
class Thread {
public:
- Thread(thrd_t *t, void (*func)(), void *a);
- Thread(thrd_t *t);
- int swap(Thread *t);
- void dispose();
+ Thread(thrd_t *t, void (*func)(void *), void *a);
+ ~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();
thrd_t get_thrd_t() { return *user_thread; }
+ Thread * get_parent() { return parent; }
+
+ friend void thread_startup();
+
+ SNAPSHOTALLOC
private:
int create_context();
+ Thread *parent;
- void (*start_routine)();
+ void (*start_routine)(void *);
void *arg;
ucontext_t context;
void *stack;
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__ */