1 d54ead7f 2004-12-28 devnull #include "u.h"
2 d54ead7f 2004-12-28 devnull #include <errno.h>
3 d54ead7f 2004-12-28 devnull #include <sys/time.h>
4 d54ead7f 2004-12-28 devnull #include <sys/types.h>
5 d54ead7f 2004-12-28 devnull #include <sys/wait.h>
6 d54ead7f 2004-12-28 devnull #include <sched.h>
7 d54ead7f 2004-12-28 devnull #include <signal.h>
8 9d654ebc 2005-07-19 devnull #if !defined(__OpenBSD__)
9 cea10000 2005-05-01 devnull # include <ucontext.h>
11 7a2c8850 2005-01-17 devnull #include <sys/utsname.h>
12 d54ead7f 2004-12-28 devnull #include "libc.h"
13 d54ead7f 2004-12-28 devnull #include "thread.h"
15 48ca8d21 2005-11-01 devnull #if defined(__FreeBSD__) && __FreeBSD__ < 5
16 1e05fdf9 2005-11-04 devnull extern int getmcontext(mcontext_t*);
17 1e05fdf9 2005-11-04 devnull extern void setmcontext(mcontext_t*);
18 1e05fdf9 2005-11-04 devnull #define setcontext(u) setmcontext(&(u)->uc_mcontext)
19 1e05fdf9 2005-11-04 devnull #define getcontext(u) getmcontext(&(u)->uc_mcontext)
20 d54ead7f 2004-12-28 devnull extern int swapcontext(ucontext_t*, ucontext_t*);
21 d54ead7f 2004-12-28 devnull extern void makecontext(ucontext_t*, void(*)(), int, ...);
24 50f7ec33 2005-01-07 devnull #if defined(__APPLE__)
25 b8f742db 2005-01-11 devnull # define mcontext libthread_mcontext
26 b8f742db 2005-01-11 devnull # define mcontext_t libthread_mcontext_t
27 b8f742db 2005-01-11 devnull # define ucontext libthread_ucontext
28 b8f742db 2005-01-11 devnull # define ucontext_t libthread_ucontext_t
29 cea10000 2005-05-01 devnull # include "power-ucontext.h"
32 cea10000 2005-05-01 devnull #if defined(__OpenBSD__)
33 b4b68641 2005-07-20 devnull # define mcontext libthread_mcontext
34 b4b68641 2005-07-20 devnull # define mcontext_t libthread_mcontext_t
35 b4b68641 2005-07-20 devnull # define ucontext libthread_ucontext
36 b4b68641 2005-07-20 devnull # define ucontext_t libthread_ucontext_t
37 9d654ebc 2005-07-19 devnull # if defined __i386__
38 9d654ebc 2005-07-19 devnull # include "386-ucontext.h"
40 9d654ebc 2005-07-19 devnull # include "power-ucontext.h"
42 cea10000 2005-05-01 devnull extern pid_t rfork_thread(int, void*, int(*)(void*), void*);
45 33a102fc 2005-11-04 devnull #if defined(__arm__)
46 a81eb4ca 2005-11-04 devnull int getmcontext(mcontext_t*);
47 ac3d1298 2005-11-04 devnull void setmcontext(const mcontext_t*);
48 a81eb4ca 2005-11-04 devnull #define setcontext(u) setmcontext(&(u)->uc_mcontext)
49 a81eb4ca 2005-11-04 devnull #define getcontext(u) getmcontext(&(u)->uc_mcontext)
52 619085f0 2004-12-25 devnull typedef struct Context Context;
53 e127e40b 2004-12-27 devnull typedef struct Execjob Execjob;
54 619085f0 2004-12-25 devnull typedef struct Proc Proc;
55 619085f0 2004-12-25 devnull typedef struct _Procrendez _Procrendez;
57 e1dc7e45 2004-12-27 devnull typedef struct Jmp Jmp;
58 e1dc7e45 2004-12-27 devnull struct Jmp
60 e1dc7e45 2004-12-27 devnull p9jmp_buf b;
65 619085f0 2004-12-25 devnull STACK = 8192
68 619085f0 2004-12-25 devnull struct Context
70 619085f0 2004-12-25 devnull ucontext_t uc;
73 e127e40b 2004-12-27 devnull struct Execjob
76 e127e40b 2004-12-27 devnull char *cmd;
77 e127e40b 2004-12-27 devnull char **argv;
78 e127e40b 2004-12-27 devnull Channel *c;
81 619085f0 2004-12-25 devnull struct _Thread
83 619085f0 2004-12-25 devnull _Thread *next;
84 619085f0 2004-12-25 devnull _Thread *prev;
85 619085f0 2004-12-25 devnull _Thread *allnext;
86 619085f0 2004-12-25 devnull _Thread *allprev;
87 619085f0 2004-12-25 devnull Context context;
89 619085f0 2004-12-25 devnull uchar *stk;
90 619085f0 2004-12-25 devnull uint stksize;
91 619085f0 2004-12-25 devnull int exiting;
92 619085f0 2004-12-25 devnull void (*startfn)(void*);
93 619085f0 2004-12-25 devnull void *startarg;
94 619085f0 2004-12-25 devnull Proc *proc;
95 619085f0 2004-12-25 devnull char name[256];
96 619085f0 2004-12-25 devnull char state[256];
97 8dd8a81f 2005-03-18 devnull void *udata;
100 619085f0 2004-12-25 devnull struct _Procrendez
102 619085f0 2004-12-25 devnull Lock *l;
103 619085f0 2004-12-25 devnull int asleep;
104 4dbefdd4 2004-12-27 devnull #ifdef PLAN9PORT_USING_PTHREADS
105 619085f0 2004-12-25 devnull pthread_cond_t cond;
107 4dbefdd4 2004-12-27 devnull int pid;
111 619085f0 2004-12-25 devnull extern void _procsleep(_Procrendez*);
112 619085f0 2004-12-25 devnull extern void _procwakeup(_Procrendez*);
113 a0a331aa 2005-01-06 devnull extern void _procwakeupandunlock(_Procrendez*);
115 619085f0 2004-12-25 devnull struct Proc
117 4dbefdd4 2004-12-27 devnull Proc *next;
118 4dbefdd4 2004-12-27 devnull Proc *prev;
119 4dbefdd4 2004-12-27 devnull char msg[128];
120 4dbefdd4 2004-12-27 devnull #ifdef PLAN9PORT_USING_PTHREADS
121 4dbefdd4 2004-12-27 devnull pthread_t osprocid;
123 669a062b 2005-01-30 devnull int osprocid;
125 619085f0 2004-12-25 devnull Lock lock;
126 8cbd854a 2004-12-27 devnull int nswitch;
127 619085f0 2004-12-25 devnull _Thread *thread;
128 619085f0 2004-12-25 devnull _Threadlist runqueue;
129 619085f0 2004-12-25 devnull _Threadlist allthreads;
130 619085f0 2004-12-25 devnull uint nthread;
131 619085f0 2004-12-25 devnull uint sysproc;
132 619085f0 2004-12-25 devnull _Procrendez runrend;
133 619085f0 2004-12-25 devnull Context schedcontext;
134 619085f0 2004-12-25 devnull void *udata;
135 e1dc7e45 2004-12-27 devnull Jmp sigjmp;
136 8ee6ad4d 2005-02-14 devnull int mainproc;
139 619085f0 2004-12-25 devnull #define proc() _threadproc()
140 619085f0 2004-12-25 devnull #define setproc(p) _threadsetproc(p)
142 4dbefdd4 2004-12-27 devnull extern Proc *_threadprocs;
143 4dbefdd4 2004-12-27 devnull extern Lock _threadprocslock;
144 955a2ca7 2004-12-27 devnull extern Proc *_threadexecproc;
145 955a2ca7 2004-12-27 devnull extern Channel *_threadexecchan;
146 955a2ca7 2004-12-27 devnull extern QLock _threadexeclock;
147 955a2ca7 2004-12-27 devnull extern Channel *_dowaitchan;
149 73722a8b 2004-12-27 devnull extern void _procstart(Proc*, void (*fn)(Proc*));
150 619085f0 2004-12-25 devnull extern _Thread *_threadcreate(Proc*, void(*fn)(void*), void*, uint);
151 619085f0 2004-12-25 devnull extern void _threadexit(void);
152 619085f0 2004-12-25 devnull extern Proc *_threadproc(void);
153 619085f0 2004-12-25 devnull extern void _threadsetproc(Proc*);
154 619085f0 2004-12-25 devnull extern int _threadlock(Lock*, int, ulong);
155 619085f0 2004-12-25 devnull extern void _threadunlock(Lock*, ulong);
156 e1dc7e45 2004-12-27 devnull extern void _pthreadinit(void);
157 e127e40b 2004-12-27 devnull extern int _threadspawn(int*, char*, char**);
158 e127e40b 2004-12-27 devnull extern int _runthreadspawn(int*, char*, char**);
159 2c87dda8 2004-12-28 devnull extern void _threadsetupdaemonize(void);
160 2c87dda8 2004-12-28 devnull extern void _threaddodaemonize(char*);
161 1d2533d0 2004-12-28 devnull extern void _threadpexit(void);
162 c7acb53e 2005-01-04 devnull extern void _threaddaemonize(void);