8 #if !defined(__OpenBSD__)
11 #include <sys/utsname.h>
15 #if defined(__FreeBSD__) && __FreeBSD__ < 5
16 extern int getmcontext(mcontext_t*);
17 extern void setmcontext(mcontext_t*);
18 #define setcontext(u) setmcontext(&(u)->uc_mcontext)
19 #define getcontext(u) getmcontext(&(u)->uc_mcontext)
20 extern int swapcontext(ucontext_t*, ucontext_t*);
21 extern void makecontext(ucontext_t*, void(*)(), int, ...);
24 #if defined(__APPLE__)
26 * OS X before 10.5 (Leopard) does not provide
27 * swapcontext nor makecontext, so we have to use our own.
28 * In theory, Leopard does provide them, but when we use
29 * them, they seg fault. Maybe we're using them wrong.
30 * So just use our own versions, even on Leopard.
32 # define mcontext libthread_mcontext
33 # define mcontext_t libthread_mcontext_t
34 # define ucontext libthread_ucontext
35 # define ucontext_t libthread_ucontext_t
36 # define swapcontext libthread_swapcontext
37 # define makecontext libthread_makecontext
38 # if defined(__i386__)
39 # include "386-ucontext.h"
41 # include "power-ucontext.h"
45 #if defined(__OpenBSD__)
46 # define mcontext libthread_mcontext
47 # define mcontext_t libthread_mcontext_t
48 # define ucontext libthread_ucontext
49 # define ucontext_t libthread_ucontext_t
51 # include "386-ucontext.h"
53 # include "power-ucontext.h"
55 extern pid_t rfork_thread(int, void*, int(*)(void*), void*);
58 /* THIS DOES NOT WORK! Don't do this!
59 (At least, not on Solaris. Maybe this is right for Linux,
60 in which case it should say if defined(__linux__) && defined(__sun__),
61 but surely the latter would be defined(__sparc__).
64 # define mcontext libthread_mcontext
65 # define mcontext_t libthread_mcontext_t
66 # define ucontext libthread_ucontext
67 # define ucontext_t libthread_ucontext_t
68 # include "sparc-ucontext.h"
73 int getmcontext(mcontext_t*);
74 void setmcontext(const mcontext_t*);
75 #define setcontext(u) setmcontext(&(u)->uc_mcontext)
76 #define getcontext(u) getmcontext(&(u)->uc_mcontext)
80 typedef struct Context Context;
81 typedef struct Execjob Execjob;
82 typedef struct Proc Proc;
83 typedef struct _Procrendez _Procrendez;
85 typedef struct Jmp Jmp;
120 void (*startfn)(void*);
133 #ifdef PLAN9PORT_USING_PTHREADS
140 extern void _procsleep(_Procrendez*);
141 extern void _procwakeup(_Procrendez*);
142 extern void _procwakeupandunlock(_Procrendez*);
149 #ifdef PLAN9PORT_USING_PTHREADS
158 _Threadlist runqueue;
159 _Threadlist idlequeue;
160 _Threadlist allthreads;
164 Context schedcontext;
170 #define proc() _threadproc()
171 #define setproc(p) _threadsetproc(p)
173 extern Proc *_threadprocs;
174 extern Lock _threadprocslock;
175 extern Proc *_threadexecproc;
176 extern Channel *_threadexecchan;
177 extern QLock _threadexeclock;
178 extern Channel *_dowaitchan;
180 extern void _procstart(Proc*, void (*fn)(Proc*));
181 extern _Thread *_threadcreate(Proc*, void(*fn)(void*), void*, uint);
182 extern void _threadexit(void);
183 extern Proc *_threadproc(void);
184 extern void _threadsetproc(Proc*);
185 extern int _threadlock(Lock*, int, ulong);
186 extern void _threadunlock(Lock*, ulong);
187 extern void _pthreadinit(void);
188 extern int _threadspawn(int*, char*, char**);
189 extern int _runthreadspawn(int*, char*, char**);
190 extern void _threadsetupdaemonize(void);
191 extern void _threaddodaemonize(char*);
192 extern void _threadpexit(void);
193 extern void _threaddaemonize(void);