#endif
static void
-remove_thread(pTHX_ struct perl_thread *t)
+remove_thread(pTHX_ Thread t)
{
#ifdef USE_THREADS
DEBUG_S(WITH_THR(PerlIO_printf(Perl_debug_log,
PL_nthreads--;
t->prev->next = t->next;
t->next->prev = t->prev;
+ SvREFCNT_dec(t->oursv);
COND_BROADCAST(&PL_nthreads_cond);
MUTEX_UNLOCK(&PL_threads_mutex);
#endif
#else
Thread thr = (Thread) arg;
LOGOP myop;
- djSP;
+ dSP;
I32 oldmark = TOPMARK;
I32 oldscope = PL_scopestack_ix;
I32 retval;
DEBUG_S(PerlIO_printf(Perl_debug_log, "new thread %p waiting to start\n",
thr));
- /* Don't call *anything* requiring dTHR until after SET_THR() */
/*
* Wait until our creator releases us. If we didn't do this, then
* it would be potentially possible for out thread to carry on and
* from our pthread_t structure to our struct perl_thread, since
* we're the only thread who can get at it anyway.
*/
- SET_THR(thr);
+ PERL_SET_THX(thr);
- /* Only now can we use SvPEEK (which calls sv_newmortal which does dTHR) */
DEBUG_S(PerlIO_printf(Perl_debug_log, "new thread %p starting at %s\n",
thr, SvPEEK(TOPs)));
av_store(av, 1, newSVsv(thr->errsv));
DEBUG_S(PerlIO_printf(Perl_debug_log, "%p died: %s\n",
thr, SvPV(thr->errsv, PL_na)));
- } else {
+ }
+ else {
DEBUG_S(STMT_START {
for (i = 1; i <= retval; i++) {
PerlIO_printf(Perl_debug_log, "%p return[%d] = %s\n",
SvREFCNT_dec(thr->threadsv);
SvREFCNT_dec(thr->specific);
SvREFCNT_dec(thr->errsv);
- SvREFCNT_dec(thr->errhv);
/*Safefree(cxstack);*/
while (PL_curstackinfo->si_next)
Safefree(PL_savestack);
Safefree(PL_retstack);
Safefree(PL_tmps_stack);
- Safefree(PL_ofs);
+ SvREFCNT_dec(PL_ofs_sv);
SvREFCNT_dec(PL_rs);
SvREFCNT_dec(PL_nrs);
Safefree(PL_reg_poscache);
MUTEX_LOCK(&thr->mutex);
+ thr->thr_done = 1;
DEBUG_S(PerlIO_printf(Perl_debug_log,
"%p: threadstart finishing: state is %u\n",
thr, ThrSTATE(thr)));
* XPUSHs() below want to grow the child's stack. This is
* safe, since the other thread is not yet created, and we
* are the only ones who know about it */
- SET_THR(thr);
+ PERL_SET_THX(thr);
SPAGAIN;
DEBUG_S(PerlIO_printf(Perl_debug_log,
"%p: newthread (%p), tid is %u, preparing stack\n",
PUTBACK;
/* On your marks... */
- SET_THR(savethread);
+ PERL_SET_THX(savethread);
MUTEX_LOCK(&thr->mutex);
#ifdef THREAD_CREATE
if (!attr_inited) {
attr_inited = 1;
err = pthread_attr_init(&attr);
+# ifdef THREAD_CREATE_NEEDS_STACK
+ if (err == 0)
+ err = pthread_attr_setstacksize(&attr, THREAD_CREATE_NEEDS_STACK);
+ if (err)
+ croak("panic: pthread_attr_setstacksize failed");
+#else
+ croak("panic: can't pthread_attr_setstacksize");
+# endif
# ifdef PTHREAD_ATTR_SETDETACHSTATE
if (err == 0)
err = PTHREAD_ATTR_SETDETACHSTATE(&attr, attr_joinable);
-
+ if (err)
+ croak("panic: pthread_attr_setdetachstate failed");
# else
croak("panic: can't pthread_attr_setdetachstate");
# endif
/* Thread creation failed--clean up */
SvREFCNT_dec(thr->cvcache);
remove_thread(aTHX_ thr);
- MUTEX_DESTROY(&thr->mutex);
for (i = 0; i <= AvFILL(initargs); i++)
SvREFCNT_dec(*av_fetch(initargs, i, FALSE));
SvREFCNT_dec(startsv);
return sv;
#else
- croak("No threads in this perl");
+# ifdef USE_ITHREADS
+ croak("This perl was built for \"ithreads\", which currently does not support Thread.pm.\n"
+ "Run \"perldoc Thread\" for more information");
+# else
+ croak("This perl was not built with support for 5.005-style threads.\n"
+ "Run \"perldoc Thread\" for more information");
+# endif
return &PL_sv_undef;
#endif
}
}
JOIN(t, &av);
+ sv_2mortal((SV*)av);
+
if (SvTRUE(*av_fetch(av, 0, FALSE))) {
/* Could easily speed up the following if necessary */
for (i = 1; i <= AvFILL(av); i++)
- XPUSHs(sv_2mortal(*av_fetch(av, i, FALSE)));
- } else {
+ XPUSHs(*av_fetch(av, i, FALSE));
+ }
+ else {
STRLEN n_a;
char *mess = SvPV(*av_fetch(av, 1, FALSE), n_a);
DEBUG_S(PerlIO_printf(Perl_debug_log,
#endif
void
+done(t)
+ Thread t
+ PPCODE:
+#ifdef USE_THREADS
+ PUSHs(t->thr_done ? &PL_sv_yes : &PL_sv_no);
+#endif
+
+void
self(classname)
char * classname
PREINIT: