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"
60 # include "power-ucontext.h"
62 extern pid_t rfork_thread(int, void*, int(*)(void*), void*);
65 /* THIS DOES NOT WORK! Don't do this!
66 (At least, not on Solaris. Maybe this is right for Linux,
67 in which case it should say if defined(__linux__) && defined(__sun__),
68 but surely the latter would be defined(__sparc__).
71 # define mcontext libthread_mcontext
72 # define mcontext_t libthread_mcontext_t
73 # define ucontext libthread_ucontext
74 # define ucontext_t libthread_ucontext_t
75 # include "sparc-ucontext.h"
80 int mygetmcontext(ulong*);
81 void mysetmcontext(const ulong*);
82 #define setcontext(u) mysetmcontext(&(u)->uc_mcontext.arm_r0)
83 #define getcontext(u) mygetmcontext(&(u)->uc_mcontext.arm_r0)
87 typedef struct Context Context;
88 typedef struct Execjob Execjob;
89 typedef struct Proc Proc;
90 typedef struct _Procrendez _Procrendez;
92 typedef struct Jmp Jmp;
108 * On Snow Leopard, etc., the context routines exist,
109 * so we use them, but apparently they write past the
110 * end of the ucontext_t. Sigh. We put some extra
111 * scratch space here for them.
132 void (*startfn)(void*);
149 #ifdef PLAN9PORT_USING_PTHREADS
156 extern void _procsleep(_Procrendez*);
157 extern void _procwakeup(_Procrendez*);
158 extern void _procwakeupandunlock(_Procrendez*);
165 #ifdef PLAN9PORT_USING_PTHREADS
174 _Threadlist runqueue;
175 _Threadlist idlequeue;
176 _Threadlist allthreads;
180 Context schedcontext;
186 #define proc() _threadproc()
187 #define setproc(p) _threadsetproc(p)
189 extern Proc *_threadprocs;
190 extern Lock _threadprocslock;
191 extern Proc *_threadexecproc;
192 extern Channel *_threadexecchan;
193 extern QLock _threadexeclock;
194 extern Channel *_dowaitchan;
196 extern void _procstart(Proc*, void (*fn)(Proc*));
197 extern _Thread *_threadcreate(Proc*, void(*fn)(void*), void*, uint);
198 extern void _threadexit(void);
199 extern Proc *_threadproc(void);
200 extern void _threadsetproc(Proc*);
201 extern int _threadlock(Lock*, int, ulong);
202 extern void _threadunlock(Lock*, ulong);
203 extern void _pthreadinit(void);
204 extern int _threadspawn(int*, char*, char**);
205 extern int _runthreadspawn(int*, char*, char**);
206 extern void _threadsetupdaemonize(void);
207 extern void _threaddodaemonize(char*);
208 extern void _threadpexit(void);
209 extern void _threaddaemonize(void);