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? */
162 perl_mutex *Tthreadstart_mutexp;
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 3
180 #define THRf_NORMAL 0
181 #define THRf_DETACHED 1
182 #define THRf_JOINED 2
185 #define THRf_DIE_FATAL 4
187 #define ThrSTATE(t) (t->flags & THRf_STATE_MASK)
188 #define ThrSETSTATE(t, s) STMT_START { \
189 (t)->flags &= ~THRf_STATE_MASK; \
191 DEBUG_L(fprintf(stderr, "thread 0x%lx set to state %d\n", \
192 (unsigned long)(t), (s))); \
195 typedef struct condpair {
197 perl_cond owner_cond;
202 #define MgMUTEXP(mg) (&((condpair_t *)(mg->mg_ptr))->mutex)
203 #define MgOWNERCONDP(mg) (&((condpair_t *)(mg->mg_ptr))->owner_cond)
204 #define MgCONDP(mg) (&((condpair_t *)(mg->mg_ptr))->cond)
205 #define MgOWNER(mg) ((condpair_t *)(mg->mg_ptr))->owner
217 #undef scopestack_max
247 #define self (thr->Tself)
248 #define oursv (thr->Toursv)
249 #define stack_base (thr->Tstack_base)
250 #define stack_sp (thr->Tstack_sp)
251 #define stack_max (thr->Tstack_max)
252 #ifdef OP_IN_REGISTER
253 #define opsave (thr->Topsave)
256 #define op (thr->Top)
258 #define curcop (thr->Tcurcop)
259 #define stack (thr->Tstack)
260 #define curstack (thr->Tcurstack)
261 #define mainstack (thr->Tmainstack)
262 #define markstack (thr->Tmarkstack)
263 #define markstack_ptr (thr->Tmarkstack_ptr)
264 #define markstack_max (thr->Tmarkstack_max)
265 #define scopestack (thr->Tscopestack)
266 #define scopestack_ix (thr->Tscopestack_ix)
267 #define scopestack_max (thr->Tscopestack_max)
269 #define savestack (thr->Tsavestack)
270 #define savestack_ix (thr->Tsavestack_ix)
271 #define savestack_max (thr->Tsavestack_max)
273 #define retstack (thr->Tretstack)
274 #define retstack_ix (thr->Tretstack_ix)
275 #define retstack_max (thr->Tretstack_max)
277 #define cxstack (thr->Tcxstack)
278 #define cxstack_ix (thr->Tcxstack_ix)
279 #define cxstack_max (thr->Tcxstack_max)
281 #define curpad (thr->Tcurpad)
282 #define Sv (thr->TSv)
283 #define Xpv (thr->TXpv)
284 #define statbuf (thr->Tstatbuf)
285 #define timesbuf (thr->Ttimesbuf)
286 #define defstash (thr->Tdefstash)
287 #define curstash (thr->Tcurstash)
289 #define tmps_stack (thr->Ttmps_stack)
290 #define tmps_ix (thr->Ttmps_ix)
291 #define tmps_floor (thr->Ttmps_floor)
292 #define tmps_max (thr->Ttmps_max)
294 #define in_eval (thr->Tin_eval)
295 #define restartop (thr->Trestartop)
296 #define delaymagic (thr->Tdelaymagic)
297 #define dirty (thr->Tdirty)
298 #define localizing (thr->Tlocalizing)
300 #define top_env (thr->Ttop_env)
301 #define runlevel (thr->Trunlevel)
303 #define threadstart_mutexp (thr->Tthreadstart_mutexp)
304 #define cvcache (thr->Tcvcache)
305 #endif /* USE_THREADS */