vm: fix a null dereference on out-of-memory
[minix.git] / lib / libmthread / global.h
blob374fce17a2dd8451ba69dd228b95e8754889ffad
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>
9 #define NO_THREADS 4
10 #define MAX_THREAD_POOL 1024
11 #define STACKSZ 4096
12 #define MAIN_THREAD (-1)
13 #define NO_THREAD (-2)
14 #define isokthreadid(i) (i == MAIN_THREAD || (i >= 0 && i < no_threads))
15 #define MTHREAD_INIT_MAGIC 0xca11ab1e
16 #define MTHREAD_NOT_INUSE 0xdefec7
18 typedef enum {
19 MS_CONDITION, MS_DEAD, MS_EXITING, MS_MUTEX, MS_RUNNABLE, MS_NEEDRESET
20 } mthread_state_t;
22 struct __mthread_tcb {
23 mthread_thread_t m_tid; /* My own ID */
24 mthread_state_t m_state; /* Thread state */
25 struct __mthread_attr m_attr; /* Thread attributes */
26 struct __mthread_cond *m_cond; /* Condition variable that this thread
27 * might be blocking on */
28 void *(*m_proc)(void *); /* Procedure to run */
29 void *m_arg; /* Argument passed to procedure */
30 void *m_result; /* Result after procedure returns */
31 mthread_cond_t m_exited; /* Condition variable signaling this
32 * thread has ended */
33 mthread_mutex_t m_exitm; /* Mutex to accompany exit condition */
34 ucontext_t m_context; /* Thread machine context */
35 struct __mthread_tcb *m_next; /* Next thread in linked list */
37 typedef struct __mthread_tcb mthread_tcb_t;
39 EXTERN mthread_thread_t current_thread;
40 EXTERN mthread_queue_t free_threads;
41 EXTERN mthread_queue_t run_queue; /* FIFO of runnable threads */
42 EXTERN mthread_tcb_t **threads;
43 EXTERN mthread_tcb_t mainthread;
44 EXTERN int no_threads;
45 EXTERN int used_threads;
46 EXTERN int need_reset;
47 EXTERN int running_main_thread;