This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Rename perl_thread to perl_os_thread.
[perl5.git] / ext / Thread / Thread.xs
CommitLineData
d9bb3666
MB
1#include "EXTERN.h"
2#include "perl.h"
3#include "XSUB.h"
4
7d901afa
MB
5/* Magic signature for Thread's mg_private is "Th" */
6#define Thread_MAGIC_SIGNATURE 0x5468
7
f0f333f4
NIS
8#ifdef __cplusplus
9#ifdef I_UNISTD
10#include <unistd.h>
11#endif
12#endif
13#include <fcntl.h>
14
7d901afa 15static U32 threadnum = 0;
85ced67f 16static int sig_pipe[2];
f0f333f4
NIS
17
18#ifndef THREAD_RET_TYPE
19typedef struct thread *Thread;
20#define THREAD_RET_TYPE void *
21#define THREAD_RET_CAST(x) ((THREAD_RET_TYPE) x)
458fb581 22#endif
683929b4 23
7d901afa 24static void
f0f333f4 25remove_thread(struct thread *t)
7d901afa 26{
f0f333f4 27#ifdef USE_THREADS
7d901afa
MB
28 DEBUG_L(WITH_THR(PerlIO_printf(PerlIO_stderr(),
29 "%p: remove_thread %p\n", thr, t)));
30 MUTEX_LOCK(&threads_mutex);
0a00ffdb 31 MUTEX_DESTROY(&t->mutex);
7d901afa
MB
32 nthreads--;
33 t->prev->next = t->next;
34 t->next->prev = t->prev;
35 COND_BROADCAST(&nthreads_cond);
36 MUTEX_UNLOCK(&threads_mutex);
f0f333f4 37#endif
7d901afa
MB
38}
39
ea0efc06 40static THREAD_RET_TYPE
f0f333f4 41threadstart(void *arg)
d9bb3666 42{
f0f333f4 43#ifdef USE_THREADS
783070da
MB
44#ifdef FAKE_THREADS
45 Thread savethread = thr;
46 LOGOP myop;
47 dSP;
48 I32 oldscope = scopestack_ix;
49 I32 retval;
458fb581 50 AV *av;
783070da
MB
51 int i;
52
683929b4
MB
53 DEBUG_L(PerlIO_printf(PerlIO_stderr(), "new thread %p starting at %s\n",
54 thr, SvPEEK(TOPs)));
783070da
MB
55 thr = (Thread) arg;
56 savemark = TOPMARK;
57 thr->prev = thr->prev_run = savethread;
58 thr->next = savethread->next;
59 thr->next_run = savethread->next_run;
60 savethread->next = savethread->next_run = thr;
61 thr->wait_queue = 0;
62 thr->private = 0;
63
64 /* Now duplicate most of perl_call_sv but with a few twists */
65 op = (OP*)&myop;
66 Zero(op, 1, LOGOP);
67 myop.op_flags = OPf_STACKED;
68 myop.op_next = Nullop;
69 myop.op_flags |= OPf_KNOW;
70 myop.op_flags |= OPf_WANT_LIST;
71 op = pp_entersub(ARGS);
72 DEBUG_L(if (!op)
73 PerlIO_printf(PerlIO_stderr(), "thread starts at Nullop\n"));
74 /*
75 * When this thread is next scheduled, we start in the right
76 * place. When the thread runs off the end of the sub, perl.c
77 * handles things, using savemark to figure out how much of the
78 * stack is the return value for any join.
79 */
80 thr = savethread; /* back to the old thread */
81 return 0;
82#else
d9bb3666
MB
83 Thread thr = (Thread) arg;
84 LOGOP myop;
4e35701f 85 djSP;
d9bb3666
MB
86 I32 oldmark = TOPMARK;
87 I32 oldscope = scopestack_ix;
88 I32 retval;
458fb581
MB
89 SV *sv;
90 AV *av = newAV();
14fcddff 91 int i, ret;
783070da 92 dJMPENV;
0b9678a8
NIS
93 DEBUG_L(PerlIO_printf(PerlIO_stderr(), "new thread %p waiting to start\n",
94 thr));
783070da 95
0b9678a8 96 /* Don't call *anything* requiring dTHR until after SET_THR() */
d9bb3666
MB
97 /*
98 * Wait until our creator releases us. If we didn't do this, then
99 * it would be potentially possible for out thread to carry on and
100 * do stuff before our creator fills in our "self" field. For example,
ea0efc06
MB
101 * if we went and created another thread which tried to JOIN with us,
102 * then we'd be in a mess.
d9bb3666 103 */
50112d62
MB
104 MUTEX_LOCK(&thr->mutex);
105 MUTEX_UNLOCK(&thr->mutex);
d9bb3666 106
d9bb3666
MB
107 /*
108 * It's safe to wait until now to set the thread-specific pointer
109 * from our pthread_t structure to our struct thread, since we're
110 * the only thread who can get at it anyway.
111 */
ea0efc06 112 SET_THR(thr);
d9bb3666 113
783070da 114 /* Only now can we use SvPEEK (which calls sv_newmortal which does dTHR) */
683929b4
MB
115 DEBUG_L(PerlIO_printf(PerlIO_stderr(), "new thread %p starting at %s\n",
116 thr, SvPEEK(TOPs)));
783070da 117
458fb581
MB
118 sv = POPs;
119 PUTBACK;
120 perl_call_sv(sv, G_ARRAY|G_EVAL);
734689b1
MB
121 SPAGAIN;
122 retval = sp - (stack_base + oldmark);
123 sp = stack_base + oldmark + 1;
458fb581
MB
124 if (SvCUR(thr->errsv)) {
125 MUTEX_LOCK(&thr->mutex);
126 thr->flags |= THRf_DID_DIE;
127 MUTEX_UNLOCK(&thr->mutex);
128 av_store(av, 0, &sv_no);
129 av_store(av, 1, newSVsv(thr->errsv));
130 DEBUG_L(PerlIO_printf(PerlIO_stderr(), "%p died: %s\n",
131 SvPV(thr->errsv, na));
132 } else {
133 DEBUG_L(STMT_START {
134 for (i = 1; i <= retval; i++) {
135 PerlIO_printf(PerlIO_stderr(), "%p return[%d] = %s\n",
136 thr, i, SvPEEK(sp[i - 1]));)
137 }
138 } STMT_END);
139 av_store(av, 0, &sv_yes);
140 for (i = 1; i <= retval; i++, sp++)
141 sv_setsv(*av_fetch(av, i, TRUE), SvREFCNT_inc(*sp));
142 }
143
d9bb3666 144 finishoff:
783070da
MB
145#if 0
146 /* removed for debug */
147 SvREFCNT_dec(curstack);
148#endif
199100c8 149 SvREFCNT_dec(thr->cvcache);
54b9620d 150 SvREFCNT_dec(thr->threadsv);
554b3eca 151 SvREFCNT_dec(thr->specific);
38a03e6e
MB
152 SvREFCNT_dec(thr->errsv);
153 SvREFCNT_dec(thr->errhv);
d9bb3666
MB
154 Safefree(markstack);
155 Safefree(scopestack);
156 Safefree(savestack);
157 Safefree(retstack);
158 Safefree(cxstack);
159 Safefree(tmps_stack);
199100c8 160 Safefree(ofs);
d9bb3666 161
14fcddff 162 MUTEX_LOCK(&thr->mutex);
50112d62
MB
163 DEBUG_L(PerlIO_printf(PerlIO_stderr(),
164 "%p: threadstart finishing: state is %u\n",
165 thr, ThrSTATE(thr)));
14fcddff
MB
166 switch (ThrSTATE(thr)) {
167 case THRf_R_JOINABLE:
168 ThrSETSTATE(thr, THRf_ZOMBIE);
169 MUTEX_UNLOCK(&thr->mutex);
783070da 170 DEBUG_L(PerlIO_printf(PerlIO_stderr(),
14fcddff
MB
171 "%p: R_JOINABLE thread finished\n", thr));
172 break;
173 case THRf_R_JOINED:
174 ThrSETSTATE(thr, THRf_DEAD);
175 MUTEX_UNLOCK(&thr->mutex);
50112d62 176 remove_thread(thr);
14fcddff
MB
177 DEBUG_L(PerlIO_printf(PerlIO_stderr(),
178 "%p: R_JOINED thread finished\n", thr));
179 break;
50112d62 180 case THRf_R_DETACHED:
683929b4 181 ThrSETSTATE(thr, THRf_DEAD);
14fcddff 182 MUTEX_UNLOCK(&thr->mutex);
458fb581 183 SvREFCNT_dec(av);
14fcddff
MB
184 DEBUG_L(PerlIO_printf(PerlIO_stderr(),
185 "%p: DETACHED thread finished\n", thr));
50112d62 186 remove_thread(thr); /* This might trigger main thread to finish */
14fcddff
MB
187 break;
188 default:
189 MUTEX_UNLOCK(&thr->mutex);
190 croak("panic: illegal state %u at end of threadstart", ThrSTATE(thr));
191 /* NOTREACHED */
734689b1 192 }
458fb581 193 return THREAD_RET_CAST(av); /* Available for anyone to join with */
ea0efc06
MB
194 /* us unless we're detached, in which */
195 /* case noone sees the value anyway. */
783070da 196#endif
f0f333f4
NIS
197#else
198 return THREAD_RET_CAST(NULL);
199#endif
d9bb3666
MB
200}
201
683929b4 202static SV *
458fb581 203newthread (SV *startsv, AV *initargs, char *classname)
d9bb3666 204{
f0f333f4 205#ifdef USE_THREADS
d9bb3666
MB
206 dSP;
207 Thread savethread;
208 int i;
683929b4 209 SV *sv;
ea0efc06
MB
210 int err;
211#ifndef THREAD_CREATE
f152979c 212 sigset_t fullmask, oldmask;
ea0efc06 213#endif
d9bb3666
MB
214
215 savethread = thr;
a863c7d1 216 thr = new_struct_thread(thr);
d9bb3666 217 SPAGAIN;
50112d62 218 DEBUG_L(PerlIO_printf(PerlIO_stderr(),
0b9678a8
NIS
219 "%p: newthread (%p), tid is %u, preparing stack\n",
220 savethread, thr, thr->tid));
d9bb3666
MB
221 /* The following pushes the arg list and startsv onto the *new* stack */
222 PUSHMARK(sp);
223 /* Could easily speed up the following greatly */
734689b1 224 for (i = 0; i <= AvFILL(initargs); i++)
d9bb3666
MB
225 XPUSHs(SvREFCNT_inc(*av_fetch(initargs, i, FALSE)));
226 XPUSHs(SvREFCNT_inc(startsv));
227 PUTBACK;
ea0efc06 228#ifdef THREAD_CREATE
f0f333f4 229 err = THREAD_CREATE(thr, threadstart);
783070da 230#else
d9bb3666 231 /* On your marks... */
14fcddff 232 MUTEX_LOCK(&thr->mutex);
ea0efc06 233 /* Get set... */
f152979c
MB
234 sigfillset(&fullmask);
235 if (sigprocmask(SIG_SETMASK, &fullmask, &oldmask) == -1)
236 croak("panic: sigprocmask");
46930d8f
MB
237 err = pthread_create(&thr->self, pthread_attr_default,
238 threadstart, (void*) thr);
d9bb3666 239 /* Go */
14fcddff 240 MUTEX_UNLOCK(&thr->mutex);
ea0efc06
MB
241#endif
242 if (err) {
0b9678a8
NIS
243 DEBUG_L(PerlIO_printf(PerlIO_stderr(),
244 "%p: create of %p failed %d\n", savethread, thr, err));
ea0efc06 245 /* Thread creation failed--clean up */
199100c8 246 SvREFCNT_dec(thr->cvcache);
ea0efc06
MB
247 remove_thread(thr);
248 MUTEX_DESTROY(&thr->mutex);
249 for (i = 0; i <= AvFILL(initargs); i++)
250 SvREFCNT_dec(*av_fetch(initargs, i, FALSE));
251 SvREFCNT_dec(startsv);
252 return NULL;
253 }
254#ifdef THREAD_POST_CREATE
255 THREAD_POST_CREATE(thr);
256#else
f152979c
MB
257 if (sigprocmask(SIG_SETMASK, &oldmask, 0))
258 croak("panic: sigprocmask");
783070da 259#endif
7d901afa 260 sv = newSViv(thr->tid);
199100c8 261 sv_magic(sv, thr->oursv, '~', 0, 0);
7d901afa 262 SvMAGIC(sv)->mg_private = Thread_MAGIC_SIGNATURE;
458fb581 263 return sv_bless(newRV_noinc(sv), gv_stashpv(classname, TRUE));
f0f333f4
NIS
264#else
265 croak("No threads in this perl");
266 return &sv_undef;
267#endif
d9bb3666
MB
268}
269
f0f333f4
NIS
270static Signal_t handle_thread_signal _((int sig));
271
f152979c 272static Signal_t
f0f333f4 273handle_thread_signal(int sig)
f152979c
MB
274{
275 char c = (char) sig;
276 write(sig_pipe[0], &c, 1);
277}
278
d9bb3666 279MODULE = Thread PACKAGE = Thread
0b9678a8 280PROTOTYPES: DISABLE
d9bb3666 281
683929b4 282void
458fb581
MB
283new(classname, startsv, ...)
284 char * classname
d9bb3666 285 SV * startsv
734689b1 286 AV * av = av_make(items - 2, &ST(2));
683929b4 287 PPCODE:
458fb581 288 XPUSHs(sv_2mortal(newthread(startsv, av, classname)));
d9bb3666
MB
289
290void
d9bb3666
MB
291join(t)
292 Thread t
293 AV * av = NO_INIT
294 int i = NO_INIT
295 PPCODE:
f0f333f4 296#ifdef USE_THREADS
7d901afa
MB
297 DEBUG_L(PerlIO_printf(PerlIO_stderr(), "%p: joining %p (state %u)\n",
298 thr, t, ThrSTATE(t)););
50112d62
MB
299 MUTEX_LOCK(&t->mutex);
300 switch (ThrSTATE(t)) {
14fcddff
MB
301 case THRf_R_JOINABLE:
302 case THRf_R_JOINED:
50112d62
MB
303 ThrSETSTATE(t, THRf_R_JOINED);
304 MUTEX_UNLOCK(&t->mutex);
14fcddff
MB
305 break;
306 case THRf_ZOMBIE:
50112d62
MB
307 ThrSETSTATE(t, THRf_DEAD);
308 MUTEX_UNLOCK(&t->mutex);
309 remove_thread(t);
14fcddff
MB
310 break;
311 default:
50112d62 312 MUTEX_UNLOCK(&t->mutex);
14fcddff
MB
313 croak("can't join with thread");
314 /* NOTREACHED */
315 }
ea0efc06 316 JOIN(t, &av);
7d901afa 317
458fb581
MB
318 if (SvTRUE(*av_fetch(av, 0, FALSE))) {
319 /* Could easily speed up the following if necessary */
320 for (i = 1; i <= AvFILL(av); i++)
321 XPUSHs(sv_2mortal(*av_fetch(av, i, FALSE)));
322 } else {
323 char *mess = SvPV(*av_fetch(av, 1, FALSE), na);
324 DEBUG_L(PerlIO_printf(PerlIO_stderr(),
325 "%p: join propagating die message: %s\n",
326 thr, mess));
327 croak(mess);
328 }
f0f333f4 329#endif
d9bb3666
MB
330
331void
734689b1 332detach(t)
d9bb3666
MB
333 Thread t
334 CODE:
f0f333f4 335#ifdef USE_THREADS
7d901afa
MB
336 DEBUG_L(PerlIO_printf(PerlIO_stderr(), "%p: detaching %p (state %u)\n",
337 thr, t, ThrSTATE(t)););
50112d62
MB
338 MUTEX_LOCK(&t->mutex);
339 switch (ThrSTATE(t)) {
14fcddff 340 case THRf_R_JOINABLE:
50112d62 341 ThrSETSTATE(t, THRf_R_DETACHED);
14fcddff 342 /* fall through */
50112d62 343 case THRf_R_DETACHED:
14fcddff 344 DETACH(t);
50112d62 345 MUTEX_UNLOCK(&t->mutex);
14fcddff
MB
346 break;
347 case THRf_ZOMBIE:
50112d62 348 ThrSETSTATE(t, THRf_DEAD);
7d901afa 349 DETACH(t);
50112d62
MB
350 MUTEX_UNLOCK(&t->mutex);
351 remove_thread(t);
14fcddff
MB
352 break;
353 default:
50112d62 354 MUTEX_UNLOCK(&t->mutex);
14fcddff
MB
355 croak("can't detach thread");
356 /* NOTREACHED */
734689b1 357 }
f0f333f4 358#endif
d9bb3666
MB
359
360void
7d901afa
MB
361equal(t1, t2)
362 Thread t1
363 Thread t2
364 PPCODE:
365 PUSHs((t1 == t2) ? &sv_yes : &sv_no);
366
367void
368flags(t)
369 Thread t
370 PPCODE:
f0f333f4 371#ifdef USE_THREADS
7d901afa 372 PUSHs(sv_2mortal(newSViv(t->flags)));
f0f333f4 373#endif
7d901afa
MB
374
375void
458fb581
MB
376self(classname)
377 char * classname
7d901afa
MB
378 PREINIT:
379 SV *sv;
f0f333f4
NIS
380 PPCODE:
381#ifdef USE_THREADS
7d901afa 382 sv = newSViv(thr->tid);
199100c8 383 sv_magic(sv, thr->oursv, '~', 0, 0);
7d901afa 384 SvMAGIC(sv)->mg_private = Thread_MAGIC_SIGNATURE;
458fb581
MB
385 PUSHs(sv_2mortal(sv_bless(newRV_noinc(sv),
386 gv_stashpv(classname, TRUE))));
f0f333f4 387#endif
7d901afa 388
50112d62
MB
389U32
390tid(t)
391 Thread t
392 CODE:
f0f333f4 393#ifdef USE_THREADS
50112d62
MB
394 MUTEX_LOCK(&t->mutex);
395 RETVAL = t->tid;
396 MUTEX_UNLOCK(&t->mutex);
f0f333f4
NIS
397#else
398 RETVAL = 0;
399#endif
50112d62
MB
400 OUTPUT:
401 RETVAL
402
403void
404DESTROY(t)
405 SV * t
406 PPCODE:
407 PUSHs(&sv_yes);
408
7d901afa 409void
734689b1 410yield()
d9bb3666 411 CODE:
f0f333f4
NIS
412{
413#ifdef USE_THREADS
ea0efc06 414 YIELD;
f0f333f4
NIS
415#endif
416}
d9bb3666
MB
417
418void
734689b1
MB
419cond_wait(sv)
420 SV * sv
421 MAGIC * mg = NO_INIT
f0f333f4
NIS
422CODE:
423#ifdef USE_THREADS
2c127b02 424 if (SvROK(sv))
734689b1 425 sv = SvRV(sv);
2c127b02 426
734689b1 427 mg = condpair_magic(sv);
683929b4 428 DEBUG_L(PerlIO_printf(PerlIO_stderr(), "%p: cond_wait %p\n", thr, sv));
734689b1
MB
429 MUTEX_LOCK(MgMUTEXP(mg));
430 if (MgOWNER(mg) != thr) {
431 MUTEX_UNLOCK(MgMUTEXP(mg));
432 croak("cond_wait for lock that we don't own\n");
433 }
434 MgOWNER(mg) = 0;
435 COND_WAIT(MgCONDP(mg), MgMUTEXP(mg));
50112d62
MB
436 while (MgOWNER(mg))
437 COND_WAIT(MgOWNERCONDP(mg), MgMUTEXP(mg));
734689b1
MB
438 MgOWNER(mg) = thr;
439 MUTEX_UNLOCK(MgMUTEXP(mg));
f0f333f4
NIS
440#endif
441
734689b1
MB
442void
443cond_signal(sv)
444 SV * sv
445 MAGIC * mg = NO_INIT
446CODE:
f0f333f4 447#ifdef USE_THREADS
50112d62 448 if (SvROK(sv))
734689b1 449 sv = SvRV(sv);
50112d62 450
734689b1 451 mg = condpair_magic(sv);
683929b4 452 DEBUG_L(PerlIO_printf(PerlIO_stderr(), "%p: cond_signal %p\n",thr,sv));
734689b1
MB
453 MUTEX_LOCK(MgMUTEXP(mg));
454 if (MgOWNER(mg) != thr) {
455 MUTEX_UNLOCK(MgMUTEXP(mg));
456 croak("cond_signal for lock that we don't own\n");
457 }
458 COND_SIGNAL(MgCONDP(mg));
459 MUTEX_UNLOCK(MgMUTEXP(mg));
f0f333f4 460#endif
d9bb3666 461
734689b1
MB
462void
463cond_broadcast(sv)
464 SV * sv
465 MAGIC * mg = NO_INIT
f0f333f4
NIS
466CODE:
467#ifdef USE_THREADS
783070da 468 if (SvROK(sv))
734689b1 469 sv = SvRV(sv);
783070da 470
734689b1 471 mg = condpair_magic(sv);
683929b4
MB
472 DEBUG_L(PerlIO_printf(PerlIO_stderr(), "%p: cond_broadcast %p\n",
473 thr, sv));
734689b1
MB
474 MUTEX_LOCK(MgMUTEXP(mg));
475 if (MgOWNER(mg) != thr) {
476 MUTEX_UNLOCK(MgMUTEXP(mg));
477 croak("cond_broadcast for lock that we don't own\n");
478 }
479 COND_BROADCAST(MgCONDP(mg));
480 MUTEX_UNLOCK(MgMUTEXP(mg));
f0f333f4 481#endif
f152979c 482
7d901afa 483void
458fb581
MB
484list(classname)
485 char * classname
7d901afa
MB
486 PREINIT:
487 Thread t;
488 AV * av;
489 SV ** svp;
490 int n = 0;
491 PPCODE:
f0f333f4 492#ifdef USE_THREADS
7d901afa
MB
493 av = newAV();
494 /*
495 * Iterate until we have enough dynamic storage for all threads.
496 * We mustn't do any allocation while holding threads_mutex though.
497 */
498 MUTEX_LOCK(&threads_mutex);
499 do {
500 n = nthreads;
501 MUTEX_UNLOCK(&threads_mutex);
502 if (AvFILL(av) < n - 1) {
503 int i = AvFILL(av);
504 for (i = AvFILL(av); i < n - 1; i++) {
505 SV *sv = newSViv(0); /* fill in tid later */
506 sv_magic(sv, 0, '~', 0, 0); /* fill in other magic later */
507 av_push(av, sv_bless(newRV_noinc(sv),
458fb581 508 gv_stashpv(classname, TRUE)));
50112d62 509
7d901afa
MB
510 }
511 }
512 MUTEX_LOCK(&threads_mutex);
513 } while (n < nthreads);
50112d62 514 n = nthreads; /* Get the final correct value */
7d901afa
MB
515
516 /*
517 * At this point, there's enough room to fill in av.
518 * Note that we are holding threads_mutex so the list
519 * won't change out from under us but all the remaining
520 * processing is "fast" (no blocking, malloc etc.)
521 */
522 t = thr;
523 svp = AvARRAY(av);
524 do {
0a00ffdb 525 SV *sv = (SV*)SvRV(*svp);
7d901afa 526 sv_setiv(sv, t->tid);
199100c8 527 SvMAGIC(sv)->mg_obj = SvREFCNT_inc(t->oursv);
7d901afa
MB
528 SvMAGIC(sv)->mg_flags |= MGf_REFCOUNTED;
529 SvMAGIC(sv)->mg_private = Thread_MAGIC_SIGNATURE;
530 t = t->next;
0a00ffdb 531 svp++;
7d901afa 532 } while (t != thr);
50112d62 533 /* */
7d901afa
MB
534 MUTEX_UNLOCK(&threads_mutex);
535 /* Truncate any unneeded slots in av */
50112d62 536 av_fill(av, n - 1);
7d901afa
MB
537 /* Finally, push all the new objects onto the stack and drop av */
538 EXTEND(sp, n);
539 for (svp = AvARRAY(av); n > 0; n--, svp++)
540 PUSHs(*svp);
541 (void)sv_2mortal((SV*)av);
f0f333f4 542#endif
7d901afa
MB
543
544
f152979c
MB
545MODULE = Thread PACKAGE = Thread::Signal
546
547void
548kill_sighandler_thread()
549 PPCODE:
550 write(sig_pipe[0], "\0", 1);
551 PUSHs(&sv_yes);
552
553void
554init_thread_signals()
555 PPCODE:
556 sighandlerp = handle_thread_signal;
557 if (pipe(sig_pipe) == -1)
558 XSRETURN_UNDEF;
559 PUSHs(&sv_yes);
560
561SV *
562await_signal()
563 PREINIT:
564 char c;
ea0efc06 565 SSize_t ret;
f152979c
MB
566 CODE:
567 do {
568 ret = read(sig_pipe[1], &c, 1);
569 } while (ret == -1 && errno == EINTR);
570 if (ret == -1)
571 croak("panic: await_signal");
572 if (ret == 0)
573 XSRETURN_UNDEF;
574 RETVAL = c ? psig_ptr[c] : &sv_no;
575 OUTPUT:
576 RETVAL
4e35701f 577
458fb581
MB
578MODULE = Thread PACKAGE = Thread::Specific
579
580void
581data(classname = "Thread::Specific")
582 char * classname
583 PPCODE:
fb223100 584#ifdef USE_THREADS
458fb581
MB
585 if (AvFILL(thr->specific) == -1) {
586 GV *gv = gv_fetchpv("Thread::Specific::FIELDS", TRUE, SVt_PVHV);
587 av_store(thr->specific, 0, newRV((SV*)GvHV(gv)));
588 }
589 XPUSHs(sv_bless(newRV((SV*)thr->specific),gv_stashpv(classname,TRUE)));
fb223100 590#endif