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)
43 /* POSIXish threads */
44 typedef pthread_t perl_thread;
45 #ifdef OLD_PTHREADS_API
46 #define pthread_mutexattr_init(a) pthread_mutexattr_create(a)
47 #define pthread_mutexattr_settype(a,t) pthread_mutexattr_setkind_np(a,t)
48 #define pthread_key_create(k,d) pthread_keycreate(k,(pthread_destructor_t)(d))
50 #define pthread_mutexattr_default NULL
51 #endif /* OLD_PTHREADS_API */
53 #define MUTEX_INIT(m) \
54 if (pthread_mutex_init((m), pthread_mutexattr_default)) \
55 croak("panic: MUTEX_INIT"); \
57 #define MUTEX_LOCK(m) \
58 if (pthread_mutex_lock((m))) croak("panic: MUTEX_LOCK"); else 1
59 #define MUTEX_UNLOCK(m) \
60 if (pthread_mutex_unlock((m))) croak("panic: MUTEX_UNLOCK"); else 1
61 #define MUTEX_DESTROY(m) \
62 if (pthread_mutex_destroy((m))) croak("panic: MUTEX_DESTROY"); else 1
63 #define COND_INIT(c) \
64 if (pthread_cond_init((c), NULL)) croak("panic: COND_INIT"); else 1
65 #define COND_SIGNAL(c) \
66 if (pthread_cond_signal((c))) croak("panic: COND_SIGNAL"); else 1
67 #define COND_BROADCAST(c) \
68 if (pthread_cond_broadcast((c))) croak("panic: COND_BROADCAST"); else 1
69 #define COND_WAIT(c, m) \
70 if (pthread_cond_wait((c), (m))) croak("panic: COND_WAIT"); else 1
71 #define COND_DESTROY(c) \
72 if (pthread_cond_destroy((c))) croak("panic: COND_DESTROY"); else 1
73 /* XXX Add "old" (?) POSIX draft interface too */
74 #ifdef OLD_PTHREADS_API
75 struct thread *getTHR _((void));
78 #define THR ((struct thread *) pthread_getspecific(thr_key))
79 #endif /* OLD_PTHREADS_API */
80 #define dTHR struct thread *thr = THR
81 #endif /* FAKE_THREADS */
87 /* The fields that used to be global */
111 I32 * Tmarkstack_ptr;
112 I32 * Tmarkstack_max;
118 char Tbuf[2048]; /* should be a global locked by a mutex */
119 char Ttokenbuf[256]; /* should be a global locked by a mutex */
120 struct stat Tstatbuf;
121 struct tms Ttimesbuf;
123 /* XXX What about regexp stuff? */
125 /* Now the fields that used to be "per interpreter" (even when global) */
127 /* XXX What about magic variables such as $/, $? and so on? */
152 /* XXX Sort stuff, firstgv, secongv and so on? */
154 perl_mutex *Tthreadstart_mutexp;
159 perl_thread next, prev; /* Linked list of all threads */
160 perl_thread next_run, prev_run; /* Linked list of runnable threads */
161 perl_cond wait_queue; /* Wait queue that we are waiting on */
162 IV private; /* Holds data across time slices */
163 I32 savemark; /* Holds MARK for thread join values */
164 #endif /* FAKE_THREADS */
167 typedef struct thread *Thread;
169 /* Values and macros for thrflags */
170 #define THRf_STATE_MASK 3
171 #define THRf_NORMAL 0
172 #define THRf_DETACHED 1
173 #define THRf_JOINED 2
176 #define THRf_DIE_FATAL 4
178 #define ThrSTATE(t) (t->Tthrflags & THRf_STATE_MASK)
179 #define ThrSETSTATE(t, s) STMT_START { \
180 (t)->Tthrflags &= ~THRf_STATE_MASK; \
181 (t)->Tthrflags |= (s); \
182 DEBUG_L(fprintf(stderr, "thread 0x%lx set to state %d\n", \
183 (unsigned long)(t), (s))); \
186 typedef struct condpair {
188 perl_cond owner_cond;
193 #define MgMUTEXP(mg) (&((condpair_t *)(mg->mg_ptr))->mutex)
194 #define MgOWNERCONDP(mg) (&((condpair_t *)(mg->mg_ptr))->owner_cond)
195 #define MgCONDP(mg) (&((condpair_t *)(mg->mg_ptr))->cond)
196 #define MgOWNER(mg) ((condpair_t *)(mg->mg_ptr))->owner
208 #undef scopestack_max
236 #define self (thr->Tself)
237 #define oursv (thr->Toursv)
238 #define stack_base (thr->Tstack_base)
239 #define stack_sp (thr->Tstack_sp)
240 #define stack_max (thr->Tstack_max)
241 #ifdef OP_IN_REGISTER
242 #define opsave (thr->Topsave)
245 #define op (thr->Top)
247 #define curcop (thr->Tcurcop)
248 #define stack (thr->Tstack)
249 #define curstack (thr->Tcurstack)
250 #define mainstack (thr->Tmainstack)
251 #define markstack (thr->Tmarkstack)
252 #define markstack_ptr (thr->Tmarkstack_ptr)
253 #define markstack_max (thr->Tmarkstack_max)
254 #define scopestack (thr->Tscopestack)
255 #define scopestack_ix (thr->Tscopestack_ix)
256 #define scopestack_max (thr->Tscopestack_max)
258 #define savestack (thr->Tsavestack)
259 #define savestack_ix (thr->Tsavestack_ix)
260 #define savestack_max (thr->Tsavestack_max)
262 #define retstack (thr->Tretstack)
263 #define retstack_ix (thr->Tretstack_ix)
264 #define retstack_max (thr->Tretstack_max)
266 #define cxstack (thr->Tcxstack)
267 #define cxstack_ix (thr->Tcxstack_ix)
268 #define cxstack_max (thr->Tcxstack_max)
270 #define curpad (thr->Tcurpad)
271 #define Sv (thr->TSv)
272 #define Xpv (thr->TXpv)
273 #define defstash (thr->Tdefstash)
274 #define curstash (thr->Tcurstash)
276 #define tmps_stack (thr->Ttmps_stack)
277 #define tmps_ix (thr->Ttmps_ix)
278 #define tmps_floor (thr->Ttmps_floor)
279 #define tmps_max (thr->Ttmps_max)
281 #define in_eval (thr->Tin_eval)
282 #define restartop (thr->Trestartop)
283 #define delaymagic (thr->Tdelaymagic)
284 #define dirty (thr->Tdirty)
285 #define localizing (thr->Tlocalizing)
287 #define top_env (thr->Ttop_env)
288 #define runlevel (thr->Trunlevel)
290 #define threadstart_mutexp (thr->Tthreadstart_mutexp)
291 #define cvcache (thr->Tcvcache)
292 #define thrflags (thr->Tthrflags)
293 #endif /* USE_THREADS */