libthreads: add thread_current() function
[c11tester.git] / libthreads.h
1 #ifndef __LIBTHREADS_H__
2 #define __LIBTHREADS_H__
3
4 #include <stdio.h>
5 #include <ucontext.h>
6
7 //#define CONFIG_DEBUG
8
9 #ifdef CONFIG_DEBUG
10 #define DEBUG(fmt, ...) do { printf("*** %25s(): line %-4d *** " fmt, __func__, __LINE__, ##__VA_ARGS__); } while (0)
11 #define DBG() DEBUG("\n");
12 #else
13 #define DEBUG(fmt, ...)
14 #define DBG()
15 #endif
16
17 struct thread {
18         void (*start_routine);
19         void *arg;
20         ucontext_t context;
21         void *stack;
22         int index;
23         int completed;
24 };
25
26 int thread_create(struct thread *t, void (*start_routine), void *arg);
27 void thread_join(struct thread *t);
28 struct thread *thread_current(void);
29
30 #endif /* __LIBTHREADS_H__ */