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 #define pthread_condattr_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), pthread_condattr_default)) \
65 croak("panic: COND_INIT"); \
67 #define COND_SIGNAL(c) \
68 if (pthread_cond_signal((c))) croak("panic: COND_SIGNAL"); else 1
69 #define COND_BROADCAST(c) \
70 if (pthread_cond_broadcast((c))) croak("panic: COND_BROADCAST"); else 1
71 #define COND_WAIT(c, m) \
72 if (pthread_cond_wait((c), (m))) croak("panic: COND_WAIT"); else 1
73 #define COND_DESTROY(c) \
74 if (pthread_cond_destroy((c))) croak("panic: COND_DESTROY"); else 1
76 /* DETACH(t) must only be called while holding t->mutex */
78 if (pthread_detach((t)->Tself)) { \
79 MUTEX_UNLOCK(&(t)->mutex); \
80 croak("panic: DETACH"); \
83 /* XXX Add "old" (?) POSIX draft interface too */
84 #ifdef OLD_PTHREADS_API
85 struct thread *getTHR _((void));
88 #define THR ((struct thread *) pthread_getspecific(thr_key))
89 #endif /* OLD_PTHREADS_API */
90 #define dTHR struct thread *thr = THR
91 #endif /* FAKE_THREADS */
94 # ifdef NEED_PTHREAD_INIT
95 # define INIT_THREADS pthread_init()
97 # define INIT_THREADS NOOP
102 /* The fields that used to be global */
103 /* Important ones in the first cache line (if alignment is done right) */
105 #ifdef OP_IN_REGISTER
128 I32 * Tmarkstack_ptr;
129 I32 * Tmarkstack_max;
133 struct stat Tstatbuf;
134 struct tms Ttimesbuf;
136 /* XXX What about regexp stuff? */
138 /* Now the fields that used to be "per interpreter" (even when global) */
140 /* XXX What about magic variables such as $/, $? and so on? */
165 /* XXX Sort stuff, firstgv, secongv and so on? */
171 perl_mutex mutex; /* For the fields others can change */
173 struct thread *next, *prev; /* Circular linked list of threads */
175 #ifdef ADD_THREAD_INTERN
176 struct thread_intern i; /* Platform-dependent internals */
178 char trailing_nul; /* For the sake of thrsv, t->Toursv */
181 typedef struct thread *Thread;
183 /* Values and macros for thr->flags */
184 #define THRf_STATE_MASK 7
185 #define THRf_R_JOINABLE 0
186 #define THRf_R_JOINED 1
187 #define THRf_R_DETACHED 2
188 #define THRf_ZOMBIE 3
191 #define THRf_DIE_FATAL 8
193 /* ThrSTATE(t) and ThrSETSTATE(t) must only be called while holding t->mutex */
194 #define ThrSTATE(t) ((t)->flags)
195 #define ThrSETSTATE(t, s) STMT_START { \
196 (t)->flags &= ~THRf_STATE_MASK; \
198 DEBUG_L(PerlIO_printf(PerlIO_stderr(), \
199 "thread %p set to state %d\n", (t), (s))); \
202 typedef struct condpair {
203 perl_mutex mutex; /* Protects all other fields */
204 perl_cond owner_cond; /* For when owner changes at all */
205 perl_cond cond; /* For cond_signal and cond_broadcast */
206 Thread owner; /* Currently owning thread */
209 #define MgMUTEXP(mg) (&((condpair_t *)(mg->mg_ptr))->mutex)
210 #define MgOWNERCONDP(mg) (&((condpair_t *)(mg->mg_ptr))->owner_cond)
211 #define MgCONDP(mg) (&((condpair_t *)(mg->mg_ptr))->cond)
212 #define MgOWNER(mg) ((condpair_t *)(mg->mg_ptr))->owner
224 #undef scopestack_max
254 #define self (thr->Tself)
255 #define oursv (thr->Toursv)
256 #define stack_base (thr->Tstack_base)
257 #define stack_sp (thr->Tstack_sp)
258 #define stack_max (thr->Tstack_max)
259 #ifdef OP_IN_REGISTER
260 #define opsave (thr->Topsave)
263 #define op (thr->Top)
265 #define curcop (thr->Tcurcop)
266 #define stack (thr->Tstack)
267 #define curstack (thr->Tcurstack)
268 #define mainstack (thr->Tmainstack)
269 #define markstack (thr->Tmarkstack)
270 #define markstack_ptr (thr->Tmarkstack_ptr)
271 #define markstack_max (thr->Tmarkstack_max)
272 #define scopestack (thr->Tscopestack)
273 #define scopestack_ix (thr->Tscopestack_ix)
274 #define scopestack_max (thr->Tscopestack_max)
276 #define savestack (thr->Tsavestack)
277 #define savestack_ix (thr->Tsavestack_ix)
278 #define savestack_max (thr->Tsavestack_max)
280 #define retstack (thr->Tretstack)
281 #define retstack_ix (thr->Tretstack_ix)
282 #define retstack_max (thr->Tretstack_max)
284 #define cxstack (thr->Tcxstack)
285 #define cxstack_ix (thr->Tcxstack_ix)
286 #define cxstack_max (thr->Tcxstack_max)
288 #define curpad (thr->Tcurpad)
289 #define Sv (thr->TSv)
290 #define Xpv (thr->TXpv)
291 #define statbuf (thr->Tstatbuf)
292 #define timesbuf (thr->Ttimesbuf)
293 #define defstash (thr->Tdefstash)
294 #define curstash (thr->Tcurstash)
296 #define tmps_stack (thr->Ttmps_stack)
297 #define tmps_ix (thr->Ttmps_ix)
298 #define tmps_floor (thr->Ttmps_floor)
299 #define tmps_max (thr->Ttmps_max)
301 #define in_eval (thr->Tin_eval)
302 #define restartop (thr->Trestartop)
303 #define delaymagic (thr->Tdelaymagic)
304 #define dirty (thr->Tdirty)
305 #define localizing (thr->Tlocalizing)
307 #define top_env (thr->Ttop_env)
308 #define runlevel (thr->Trunlevel)
310 #define cvcache (thr->Tcvcache)
311 #endif /* USE_THREADS */