Change pp_lock to take a reference instead of a
[p5sagit/p5-mst-13.2.git] / ext / threads / threads.xs
index 88aaf0e..5bcf4e4 100755 (executable)
@@ -91,6 +91,7 @@ perl_key self_key;
 void
 Perl_ithread_destruct (pTHX_ ithread* thread, const char *why)
 {
+        PerlInterpreter* destroyperl = NULL;        
        MUTEX_LOCK(&thread->mutex);
        if (!thread->next) {
            Perl_croak(aTHX_ "panic: destruct destroyed thread %p (%s)",thread, why);
@@ -127,14 +128,17 @@ Perl_ithread_destruct (pTHX_ ithread* thread, const char *why)
            PERL_SET_CONTEXT(thread->interp);
            SvREFCNT_dec(thread->params);
            thread->params = Nullsv;
-           perl_destruct(thread->interp);
-           perl_free(thread->interp);
+           destroyperl = thread->interp;
            thread->interp = NULL;
        }
-       PERL_SET_CONTEXT(aTHX);
        MUTEX_UNLOCK(&thread->mutex);
        MUTEX_DESTROY(&thread->mutex);
         PerlMemShared_free(thread);
+       if(destroyperl) {
+           perl_destruct(destroyperl);
+            perl_free(destroyperl);
+       }
+       PERL_SET_CONTEXT(aTHX);
 }
 
 int
@@ -382,7 +386,7 @@ Perl_ithread_create(pTHX_ SV *obj, char* classname, SV* init_function, SV* param
        thread->interp = perl_clone(aTHX, CLONEf_KEEP_PTR_TABLE);
 #endif
        /* perl_clone leaves us in new interpreter's context.
-          As it is tricky to spot implcit aTHX create a new scope
+          As it is tricky to spot an implicit aTHX, create a new scope
           with aTHX matching the context for the duration of
           our work for new interpreter.
         */