csu: restore crt1.o symlink
[minix.git] / include / minix / mthread.h
blob1ac6b0c707e944a7d80630ccff2bce1d1d3da65d
1 #ifndef _MTHREAD_H
2 #define _MTHREAD_H
4 #include <minix/config.h> /* MUST be first */
5 #include <minix/const.h>
6 #include <sys/types.h>
7 #include <stdio.h>
8 #include <ucontext.h>
9 #include <errno.h>
10 #include <stdlib.h>
11 #include <limits.h>
12 #ifdef __NBSD_LIBC
13 #include <sys/signal.h>
14 #endif
16 typedef int mthread_thread_t;
17 typedef int mthread_once_t;
18 typedef int mthread_key_t;
19 typedef void * mthread_condattr_t;
20 typedef void * mthread_mutexattr_t;
22 struct __mthread_tcb;
23 typedef struct {
24 struct __mthread_tcb *mq_head;
25 struct __mthread_tcb *mq_tail;
26 } mthread_queue_t;
28 struct __mthread_mutex {
29 mthread_queue_t mm_queue; /* Queue of threads blocked on this mutex */
30 mthread_thread_t mm_owner; /* Thread ID that currently owns mutex */
31 #ifdef MTHREAD_STRICT
32 struct __mthread_mutex *mm_prev;
33 struct __mthread_mutex *mm_next;
34 #endif
35 unsigned int mm_magic;
37 typedef struct __mthread_mutex *mthread_mutex_t;
39 struct __mthread_cond {
40 struct __mthread_mutex *mc_mutex; /* Associate mutex with condition */
41 #ifdef MTHREAD_STRICT
42 struct __mthread_cond *mc_prev;
43 struct __mthread_cond *mc_next;
44 #endif
45 unsigned int mc_magic;
47 typedef struct __mthread_cond *mthread_cond_t;
49 struct __mthread_attr {
50 size_t ma_stacksize;
51 char *ma_stackaddr;
52 int ma_detachstate;
53 struct __mthread_attr *ma_prev;
54 struct __mthread_attr *ma_next;
55 };
56 typedef struct __mthread_attr *mthread_attr_t;
58 typedef struct {
59 mthread_mutex_t mutex;
60 mthread_cond_t cond;
61 } mthread_event_t;
63 typedef struct {
64 unsigned int readers;
65 mthread_thread_t writer;
66 mthread_mutex_t queue;
67 mthread_event_t drain;
68 } mthread_rwlock_t;
70 #define MTHREAD_CREATE_JOINABLE 001
71 #define MTHREAD_CREATE_DETACHED 002
72 #define MTHREAD_ONCE_INIT 0
73 #define MTHREAD_STACK_MIN MINSIGSTKSZ
74 #define MTHREAD_KEYS_MAX 128
76 /* allocate.c */
77 int mthread_create(mthread_thread_t *thread, mthread_attr_t *tattr, void
78 *(*proc)(void *), void *arg);
79 int mthread_detach(mthread_thread_t thread);
80 int mthread_equal(mthread_thread_t l, mthread_thread_t r);
81 void mthread_exit(void *value);
82 int mthread_join(mthread_thread_t thread, void **value);
83 int mthread_once(mthread_once_t *once, void (*proc)(void));
84 mthread_thread_t mthread_self(void);
86 /* attribute.c */
87 int mthread_attr_destroy(mthread_attr_t *tattr);
88 int mthread_attr_getdetachstate(mthread_attr_t *tattr, int
89 *detachstate);
90 int mthread_attr_getstack(mthread_attr_t *tattr, void **stackaddr,
91 size_t *stacksize);
92 int mthread_attr_getstacksize(mthread_attr_t *tattr, size_t *stacksize);
93 int mthread_attr_init(mthread_attr_t *tattr);
94 int mthread_attr_setdetachstate(mthread_attr_t *tattr, int detachstate);
95 int mthread_attr_setstack(mthread_attr_t *tattr, void *stackaddr, size_t
96 stacksize);
97 int mthread_attr_setstacksize(mthread_attr_t *tattr, size_t stacksize);
100 /* condition.c */
101 int mthread_cond_broadcast(mthread_cond_t *cond);
102 int mthread_cond_destroy(mthread_cond_t *cond);
103 int mthread_cond_init(mthread_cond_t *cond, mthread_condattr_t *cattr);
104 int mthread_cond_signal(mthread_cond_t *cond);
105 int mthread_cond_wait(mthread_cond_t *cond, mthread_mutex_t *mutex);
107 /* key.c */
108 int mthread_key_create(mthread_key_t *key, void (*destructor)(void *));
109 int mthread_key_delete(mthread_key_t key);
110 void *mthread_getspecific(mthread_key_t key);
111 int mthread_setspecific(mthread_key_t key, void *value);
113 /* misc.c */
114 void mthread_stats(void);
115 void mthread_verify_f(char *f, int l);
116 #define mthread_verify() mthread_verify_f(__FILE__, __LINE__)
117 void mthread_stacktrace(mthread_thread_t t);
118 void mthread_stacktraces(void);
120 /* mutex.c */
121 int mthread_mutex_destroy(mthread_mutex_t *mutex);
122 int mthread_mutex_init(mthread_mutex_t *mutex, mthread_mutexattr_t
123 *mattr);
124 int mthread_mutex_lock(mthread_mutex_t *mutex);
125 int mthread_mutex_trylock(mthread_mutex_t *mutex);
126 int mthread_mutex_unlock(mthread_mutex_t *mutex);
128 /* event.c */
129 int mthread_event_destroy(mthread_event_t *event);
130 int mthread_event_init(mthread_event_t *event);
131 int mthread_event_wait(mthread_event_t *event);
132 int mthread_event_fire(mthread_event_t *event);
133 int mthread_event_fire_all(mthread_event_t *event);
135 /* rwlock.c */
136 int mthread_rwlock_destroy(mthread_rwlock_t *rwlock);
137 int mthread_rwlock_init(mthread_rwlock_t *rwlock);
138 int mthread_rwlock_rdlock(mthread_rwlock_t *rwlock);
139 int mthread_rwlock_wrlock(mthread_rwlock_t *rwlock);
140 int mthread_rwlock_unlock(mthread_rwlock_t *rwlock);
142 /* schedule.c */
143 void mthread_init(void);
144 int mthread_yield(void);
145 void mthread_yield_all(void);
147 #endif