z/OS: More threaded build tweaks from Brian De Pradine--
[p5sagit/p5-mst-13.2.git] / ext / threads / threads.xs
index 0110724..83f9e89 100755 (executable)
@@ -350,13 +350,21 @@ ithread *
 SV_to_ithread(pTHX_ SV *sv)
 {
     ithread *thread;
+#ifdef OEMVS
+    void *ptr;
+#endif
     if (SvROK(sv))
      {
       thread = INT2PTR(ithread*, SvIV(SvRV(sv)));
      }
     else
      {
+#ifdef OEMVS
+      PERL_THREAD_GETSPECIFIC(self_key,ptr);
+      thread = (ithread *) ptr;
+#else
       PERL_THREAD_GETSPECIFIC(self_key,thread);
+#endif
      }
     return thread;
 }
@@ -399,7 +407,10 @@ Perl_ithread_create(pTHX_ SV *obj, char* classname, SV* init_function, SV* param
        PerlIO_flush((PerlIO*)NULL);
        PERL_THREAD_SETSPECIFIC(self_key,thread);
 
-
+       SAVEBOOL(PL_srand_called); /* Save this so it becomes the correct
+                                     value */
+       PL_srand_called = FALSE; /* Set it to false so we can detect
+                                   if it gets set during the clone */
 
 #ifdef WIN32
        thread->interp = perl_clone(aTHX, CLONEf_KEEP_PTR_TABLE | CLONEf_CLONE_HOST);
@@ -413,6 +424,7 @@ Perl_ithread_create(pTHX_ SV *obj, char* classname, SV* init_function, SV* param
         */
        {
            dTHXa(thread->interp);
+
             /* Here we remove END blocks since they should only run
               in the thread they are created
             */
@@ -494,6 +506,7 @@ Perl_ithread_create(pTHX_ SV *obj, char* classname, SV* init_function, SV* param
 #ifdef OLD_PTHREADS_API
          pthread_create( &thread->thr, attr, Perl_ithread_run, (void *)thread);
 #else
+         pthread_attr_setscope( &attr, PTHREAD_SCOPE_SYSTEM );
          pthread_create( &thread->thr, &attr, Perl_ithread_run, (void *)thread);
 #endif
        }
@@ -510,7 +523,13 @@ SV*
 Perl_ithread_self (pTHX_ SV *obj, char* Class)
 {
     ithread *thread;
+#ifdef OEMVS
+    void *ptr;
+    PERL_THREAD_GETSPECIFIC(self_key,ptr);
+    thread = (ithread *) ptr;
+#else
     PERL_THREAD_GETSPECIFIC(self_key,thread);
+#endif
     return ithread_to_SV(aTHX_ obj, thread, Class, TRUE);
 }
 
@@ -600,7 +619,7 @@ Perl_ithread_join(pTHX_ SV *obj)
        /* We have finished with it */
        thread->state |= PERL_ITHR_JOINED;
        MUTEX_UNLOCK(&thread->mutex);
-       sv_unmagic(SvRV(obj),PERL_MAGIC_shared_scalar);
+       
        return retparam;
     }
     return (AV*)NULL;