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"
44 # include "power-ucontext.h"
48 #if defined(__OpenBSD__)
49 # define mcontext libthread_mcontext
50 # define mcontext_t libthread_mcontext_t
51 # define ucontext libthread_ucontext
52 # define ucontext_t libthread_ucontext_t
54 # include "386-ucontext.h"
56 # include "power-ucontext.h"
58 extern pid_t rfork_thread(int, void*, int(*)(void*), void*);
61 /* THIS DOES NOT WORK! Don't do this!
62 (At least, not on Solaris. Maybe this is right for Linux,
63 in which case it should say if defined(__linux__) && defined(__sun__),
64 but surely the latter would be defined(__sparc__).
67 # define mcontext libthread_mcontext
68 # define mcontext_t libthread_mcontext_t
69 # define ucontext libthread_ucontext
70 # define ucontext_t libthread_ucontext_t
71 # include "sparc-ucontext.h"
76 int mygetmcontext(ulong*);
77 void mysetmcontext(const ulong*);
78 #define setcontext(u) mysetmcontext(&(u)->uc_mcontext.arm_r0)
79 #define getcontext(u) mygetmcontext(&(u)->uc_mcontext.arm_r0)
83 typedef struct Context Context;
84 typedef struct Execjob Execjob;
85 typedef struct Proc Proc;
86 typedef struct _Procrendez _Procrendez;
88 typedef struct Jmp Jmp;
123 void (*startfn)(void*);
136 #ifdef PLAN9PORT_USING_PTHREADS
143 extern void _procsleep(_Procrendez*);
144 extern void _procwakeup(_Procrendez*);
145 extern void _procwakeupandunlock(_Procrendez*);
152 #ifdef PLAN9PORT_USING_PTHREADS
161 _Threadlist runqueue;
162 _Threadlist idlequeue;
163 _Threadlist allthreads;
167 Context schedcontext;
173 #define proc() _threadproc()
174 #define setproc(p) _threadsetproc(p)
176 extern Proc *_threadprocs;
177 extern Lock _threadprocslock;
178 extern Proc *_threadexecproc;
179 extern Channel *_threadexecchan;
180 extern QLock _threadexeclock;
181 extern Channel *_dowaitchan;
183 extern void _procstart(Proc*, void (*fn)(Proc*));
184 extern _Thread *_threadcreate(Proc*, void(*fn)(void*), void*, uint);
185 extern void _threadexit(void);
186 extern Proc *_threadproc(void);
187 extern void _threadsetproc(Proc*);
188 extern int _threadlock(Lock*, int, ulong);
189 extern void _threadunlock(Lock*, ulong);
190 extern void _pthreadinit(void);
191 extern int _threadspawn(int*, char*, char**);
192 extern int _runthreadspawn(int*, char*, char**);
193 extern void _threadsetupdaemonize(void);
194 extern void _threaddodaemonize(char*);
195 extern void _threadpexit(void);
196 extern void _threaddaemonize(void);