custom message type for VM_INFO
[minix3.git] / lib / libmthread / global.h
blob1554e893542aa72fc1c1f430e28880d80ddb86a0
1 /* EXTERN should be extern, except for the allocate file */
2 #ifdef ALLOCATE
3 #undef EXTERN
4 #define EXTERN
5 #endif
7 #include <assert.h>
8 #include <sys/types.h>
9 #include <sys/signal.h>
11 #define MTHREAD_RND_SCHED 0 /* Enable/disable random scheduling */
12 #define NO_THREADS 4
13 #define MAX_THREAD_POOL 1024
14 #define STACKSZ 4096
15 #define MAIN_THREAD (-1)
16 #define NO_THREAD (-2)
17 #define isokthreadid(i) (i == MAIN_THREAD || (i >= 0 && i < no_threads))
18 #define MTHREAD_INIT_MAGIC 0xca11ab1e
19 #define MTHREAD_NOT_INUSE 0xdefec7
21 typedef enum {
22 MS_CONDITION, MS_DEAD, MS_EXITING, MS_MUTEX, MS_RUNNABLE, MS_NEEDRESET
23 } mthread_state_t;
25 struct __mthread_tcb {
26 mthread_thread_t m_tid; /* My own ID */
27 mthread_state_t m_state; /* Thread state */
28 struct __mthread_attr m_attr; /* Thread attributes */
29 struct __mthread_cond *m_cond; /* Condition variable that this thread
30 * might be blocking on */
31 void *(*m_proc)(void *); /* Procedure to run */
32 void *m_arg; /* Argument passed to procedure */
33 void *m_result; /* Result after procedure returns */
34 mthread_cond_t m_exited; /* Condition variable signaling this
35 * thread has ended */
36 mthread_mutex_t m_exitm; /* Mutex to accompany exit condition */
37 ucontext_t m_context; /* Thread machine context */
38 struct __mthread_tcb *m_next; /* Next thread in linked list */
40 typedef struct __mthread_tcb mthread_tcb_t;
42 EXTERN mthread_thread_t current_thread;
43 EXTERN mthread_queue_t free_threads;
44 EXTERN mthread_queue_t run_queue; /* FIFO of runnable threads */
45 EXTERN mthread_tcb_t **threads;
46 EXTERN mthread_tcb_t mainthread;
47 EXTERN int no_threads;
48 EXTERN int used_threads;
49 EXTERN int need_reset;
50 EXTERN int running_main_thread;