integrate cfgperl contents into mainline
[p5sagit/p5-mst-13.2.git] / ext / Thread / Thread.xs
index 09d063a..4b5e6db 100644 (file)
@@ -31,6 +31,7 @@ remove_thread(pTHX_ struct perl_thread *t)
     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
@@ -97,7 +98,7 @@ threadstart(void *arg)
     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() */
+    /* Don't call *anything* requiring dTHR until after PERL_SET_THX() */
     /*
      * 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
@@ -113,7 +114,7 @@ threadstart(void *arg)
      * 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",
@@ -136,7 +137,8 @@ threadstart(void *arg)
        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",
@@ -159,7 +161,6 @@ threadstart(void *arg)
     SvREFCNT_dec(thr->threadsv);
     SvREFCNT_dec(thr->specific);
     SvREFCNT_dec(thr->errsv);
-    SvREFCNT_dec(thr->errhv);
 
     /*Safefree(cxstack);*/
     while (PL_curstackinfo->si_next)
@@ -251,7 +252,7 @@ newthread (pTHX_ SV *startsv, AV *initargs, char *classname)
      * 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",
@@ -265,7 +266,7 @@ newthread (pTHX_ SV *startsv, AV *initargs, char *classname)
     PUTBACK;
 
     /* On your marks... */
-    SET_THR(savethread);
+    PERL_SET_THX(savethread);
     MUTEX_LOCK(&thr->mutex);
 
 #ifdef THREAD_CREATE
@@ -299,7 +300,6 @@ newthread (pTHX_ SV *startsv, AV *initargs, char *classname)
        /* 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);
@@ -386,11 +386,14 @@ join(t)
        }
        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,