3 #define MUTEX_UNLOCK(m)
5 #define MUTEX_DESTROY(m)
8 #define COND_BROADCAST(c)
9 #define COND_WAIT(c, m)
10 #define COND_DESTROY(c)
13 /* Rats: if dTHR is just blank then the subsequent ";" throws an error */
14 #define dTHR extern int errno
18 typedef struct thread *perl_thread;
19 /* With fake threads, thr is global(ish) so we don't need dTHR */
20 #define dTHR extern int errno
23 * Note that SCHEDULE() is only callable from pp code (which
24 * must be expecting to be restarted). We'll have to do
25 * something a bit different for XS code.
27 #define SCHEDULE() return schedule(), op
30 #define MUTEX_UNLOCK(m)
32 #define MUTEX_DESTROY(m)
33 #define COND_INIT(c) perl_cond_init(c)
34 #define COND_SIGNAL(c) perl_cond_signal(c)
35 #define COND_BROADCAST(c) perl_cond_broadcast(c)
36 #define COND_WAIT(c, m) STMT_START { \
40 #define COND_DESTROY(c)
42 /* POSIXish threads */
43 typedef pthread_t perl_thread;
44 #ifdef OLD_PTHREADS_API
45 #define pthread_mutexattr_init(a) pthread_mutexattr_create(a)
46 #define pthread_mutexattr_settype(a,t) pthread_mutexattr_setkind_np(a,t)
47 #define pthread_key_create(k,d) pthread_keycreate(k,(pthread_destructor_t)(d))
49 #define pthread_mutexattr_default NULL
50 #endif /* OLD_PTHREADS_API */
52 #define MUTEX_INIT(m) \
53 if (pthread_mutex_init((m), pthread_mutexattr_default)) \
54 croak("panic: MUTEX_INIT"); \
56 #define MUTEX_LOCK(m) \
57 if (pthread_mutex_lock((m))) croak("panic: MUTEX_LOCK"); else 1
58 #define MUTEX_UNLOCK(m) \
59 if (pthread_mutex_unlock((m))) croak("panic: MUTEX_UNLOCK"); else 1
60 #define MUTEX_DESTROY(m) \
61 if (pthread_mutex_destroy((m))) croak("panic: MUTEX_DESTROY"); else 1
62 #define COND_INIT(c) \
63 if (pthread_cond_init((c), NULL)) croak("panic: COND_INIT"); else 1
64 #define COND_SIGNAL(c) \
65 if (pthread_cond_signal((c))) croak("panic: COND_SIGNAL"); else 1
66 #define COND_BROADCAST(c) \
67 if (pthread_cond_broadcast((c))) croak("panic: COND_BROADCAST"); else 1
68 #define COND_WAIT(c, m) \
69 if (pthread_cond_wait((c), (m))) croak("panic: COND_WAIT"); else 1
70 #define COND_DESTROY(c) \
71 if (pthread_cond_destroy((c))) croak("panic: COND_DESTROY"); else 1
74 if (pthread_detach((t)->Tself)) croak("panic: DETACH"); else 1
76 /* XXX Add "old" (?) POSIX draft interface too */
77 #ifdef OLD_PTHREADS_API
78 struct thread *getTHR _((void));
81 #define THR ((struct thread *) pthread_getspecific(thr_key))
82 #endif /* OLD_PTHREADS_API */
83 #define dTHR struct thread *thr = THR
84 #endif /* FAKE_THREADS */
87 # ifdef NEED_PTHREAD_INIT
88 # define INIT_THREADS pthread_init()
90 # define INIT_THREADS NOOP
95 /* The fields that used to be global */
96 /* Important ones in the first cache line (if alignment is done right) */
121 I32 * Tmarkstack_ptr;
122 I32 * Tmarkstack_max;
126 struct stat Tstatbuf;
127 struct tms Ttimesbuf;
129 /* XXX What about regexp stuff? */
131 /* Now the fields that used to be "per interpreter" (even when global) */
133 /* XXX What about magic variables such as $/, $? and so on? */
158 /* XXX Sort stuff, firstgv, secongv and so on? */
166 struct thread *next, *prev; /* Circular linked list of threads */
169 perl_thread next_run, prev_run; /* Linked list of runnable threads */
170 perl_cond wait_queue; /* Wait queue that we are waiting on */
171 IV private; /* Holds data across time slices */
172 I32 savemark; /* Holds MARK for thread join values */
173 #endif /* FAKE_THREADS */
176 typedef struct thread *Thread;
178 /* Values and macros for thr->flags */
179 #define THRf_STATE_MASK 7
180 #define THRf_R_JOINABLE 0
181 #define THRf_R_JOINED 1
182 #define THRf_R_DETACHED 2
183 #define THRf_ZOMBIE 3
186 #define THRf_DIE_FATAL 8
188 #define ThrSTATE(t) ((t)->flags)
189 #define ThrSETSTATE(t, s) STMT_START { \
190 MUTEX_LOCK(&(t)->mutex); \
191 (t)->flags &= ~THRf_STATE_MASK; \
193 MUTEX_UNLOCK(&(t)->mutex); \
194 DEBUG_L(PerlIO_printf(PerlIO_stderr(), \
195 "thread %p set to state %d\n", (t), (s))); \
198 typedef struct condpair {
200 perl_cond owner_cond;
205 #define MgMUTEXP(mg) (&((condpair_t *)(mg->mg_ptr))->mutex)
206 #define MgOWNERCONDP(mg) (&((condpair_t *)(mg->mg_ptr))->owner_cond)
207 #define MgCONDP(mg) (&((condpair_t *)(mg->mg_ptr))->cond)
208 #define MgOWNER(mg) ((condpair_t *)(mg->mg_ptr))->owner
220 #undef scopestack_max
250 #define self (thr->Tself)
251 #define oursv (thr->Toursv)
252 #define stack_base (thr->Tstack_base)
253 #define stack_sp (thr->Tstack_sp)
254 #define stack_max (thr->Tstack_max)
255 #ifdef OP_IN_REGISTER
256 #define opsave (thr->Topsave)
259 #define op (thr->Top)
261 #define curcop (thr->Tcurcop)
262 #define stack (thr->Tstack)
263 #define curstack (thr->Tcurstack)
264 #define mainstack (thr->Tmainstack)
265 #define markstack (thr->Tmarkstack)
266 #define markstack_ptr (thr->Tmarkstack_ptr)
267 #define markstack_max (thr->Tmarkstack_max)
268 #define scopestack (thr->Tscopestack)
269 #define scopestack_ix (thr->Tscopestack_ix)
270 #define scopestack_max (thr->Tscopestack_max)
272 #define savestack (thr->Tsavestack)
273 #define savestack_ix (thr->Tsavestack_ix)
274 #define savestack_max (thr->Tsavestack_max)
276 #define retstack (thr->Tretstack)
277 #define retstack_ix (thr->Tretstack_ix)
278 #define retstack_max (thr->Tretstack_max)
280 #define cxstack (thr->Tcxstack)
281 #define cxstack_ix (thr->Tcxstack_ix)
282 #define cxstack_max (thr->Tcxstack_max)
284 #define curpad (thr->Tcurpad)
285 #define Sv (thr->TSv)
286 #define Xpv (thr->TXpv)
287 #define statbuf (thr->Tstatbuf)
288 #define timesbuf (thr->Ttimesbuf)
289 #define defstash (thr->Tdefstash)
290 #define curstash (thr->Tcurstash)
292 #define tmps_stack (thr->Ttmps_stack)
293 #define tmps_ix (thr->Ttmps_ix)
294 #define tmps_floor (thr->Ttmps_floor)
295 #define tmps_max (thr->Ttmps_max)
297 #define in_eval (thr->Tin_eval)
298 #define restartop (thr->Trestartop)
299 #define delaymagic (thr->Tdelaymagic)
300 #define dirty (thr->Tdirty)
301 #define localizing (thr->Tlocalizing)
303 #define top_env (thr->Ttop_env)
304 #define runlevel (thr->Trunlevel)
306 #define cvcache (thr->Tcvcache)
307 #endif /* USE_THREADS */