8 #if !defined(__OpenBSD__)
9 # if defined(__APPLE__)
10 # define _XOPEN_SOURCE /* for Snow Leopard */
12 # include <ucontext.h>
14 #include <sys/utsname.h>
18 #if defined(__FreeBSD__) && __FreeBSD__ < 5
19 extern int getmcontext(mcontext_t*);
20 extern void setmcontext(mcontext_t*);
21 #define setcontext(u) setmcontext(&(u)->uc_mcontext)
22 #define getcontext(u) getmcontext(&(u)->uc_mcontext)
23 extern int swapcontext(ucontext_t*, ucontext_t*);
24 extern void makecontext(ucontext_t*, void(*)(), int, ...);
27 #if defined(__APPLE__)
29 * OS X before 10.5 (Leopard) does not provide
30 * swapcontext nor makecontext, so we have to use our own.
31 * In theory, Leopard does provide them, but when we use
32 * them, they seg fault. Maybe we're using them wrong.
33 * So just use our own versions, even on Leopard.
35 # define mcontext libthread_mcontext
36 # define mcontext_t libthread_mcontext_t
37 # define ucontext libthread_ucontext
38 # define ucontext_t libthread_ucontext_t
39 # define swapcontext libthread_swapcontext
40 # define makecontext libthread_makecontext
41 # if defined(__i386__)
42 # include "386-ucontext.h"
43 # elif defined(__x86_64__)
44 # include "x86_64-ucontext.h"
45 # elif defined(__ppc__) || defined(__power__)
46 # include "power-ucontext.h"
48 # error "unknown architecture"
52 #if defined(__OpenBSD__)
53 # define mcontext libthread_mcontext
54 # define mcontext_t libthread_mcontext_t
55 # define ucontext libthread_ucontext
56 # define ucontext_t libthread_ucontext_t
58 # include "386-ucontext.h"
59 # elif defined __amd64__
60 # include "x86_64-ucontext.h"
62 # include "power-ucontext.h"
64 extern pid_t rfork_thread(int, void*, int(*)(void*), void*);
67 /* THIS DOES NOT WORK! Don't do this!
68 (At least, not on Solaris. Maybe this is right for Linux,
69 in which case it should say if defined(__linux__) && defined(__sun__),
70 but surely the latter would be defined(__sparc__).
73 # define mcontext libthread_mcontext
74 # define mcontext_t libthread_mcontext_t
75 # define ucontext libthread_ucontext
76 # define ucontext_t libthread_ucontext_t
77 # include "sparc-ucontext.h"
82 int mygetmcontext(ulong*);
83 void mysetmcontext(const ulong*);
84 #define setcontext(u) mysetmcontext(&(u)->uc_mcontext.arm_r0)
85 #define getcontext(u) mygetmcontext(&(u)->uc_mcontext.arm_r0)
89 typedef struct Context Context;
90 typedef struct Execjob Execjob;
91 typedef struct Proc Proc;
92 typedef struct _Procrendez _Procrendez;
94 typedef struct Jmp Jmp;
110 * On Snow Leopard, etc., the context routines exist,
111 * so we use them, but apparently they write past the
112 * end of the ucontext_t. Sigh. We put some extra
113 * scratch space here for them.
135 void (*startfn)(void*);
152 #ifdef PLAN9PORT_USING_PTHREADS
159 extern void _procsleep(_Procrendez*);
160 extern void _procwakeup(_Procrendez*);
161 extern void _procwakeupandunlock(_Procrendez*);
168 #ifdef PLAN9PORT_USING_PTHREADS
177 _Threadlist runqueue;
178 _Threadlist idlequeue;
179 _Threadlist allthreads;
183 Context schedcontext;
189 #define proc() _threadproc()
190 #define setproc(p) _threadsetproc(p)
192 extern Proc *_threadprocs;
193 extern Lock _threadprocslock;
194 extern Proc *_threadexecproc;
195 extern Channel *_threadexecchan;
196 extern QLock _threadexeclock;
197 extern Channel *_dowaitchan;
199 extern void _procstart(Proc*, void (*fn)(Proc*));
200 extern _Thread *_threadcreate(Proc*, void(*fn)(void*), void*, uint);
201 extern void _threadexit(void);
202 extern Proc *_threadproc(void);
203 extern void _threadsetproc(Proc*);
204 extern int _threadlock(Lock*, int, ulong);
205 extern void _threadunlock(Lock*, ulong);
206 extern void _pthreadinit(void);
207 extern int _threadspawn(int*, char*, char**, char*);
208 extern int _runthreadspawn(int*, char*, char**, char*);
209 extern void _threadsetupdaemonize(void);
210 extern void _threaddodaemonize(char*);
211 extern void _threadpexit(void);
212 extern void _threaddaemonize(void);