This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Add the shared sv space to the global vars.
authorArtur Bergman <sky@nanisky.com>
Fri, 21 Sep 2001 07:35:30 +0000 (07:35 +0000)
committerArtur Bergman <sky@nanisky.com>
Fri, 21 Sep 2001 07:35:30 +0000 (07:35 +0000)
Fix problems compiling on win32.

p4raw-id: //depot/perl@12102

embedvar.h
ext/threads/threads.xs
perlapi.h
perlvars.h
sharedsv.c
sharedsv.h

index 21a11f5..d2e15a0 100644 (file)
 #define PL_malloc_mutex                (PL_Vars.Gmalloc_mutex)
 #define PL_op_mutex            (PL_Vars.Gop_mutex)
 #define PL_patleave            (PL_Vars.Gpatleave)
+#define PL_sharedsv_space      (PL_Vars.Gsharedsv_space)
+#define PL_sharedsv_space_mutex        (PL_Vars.Gsharedsv_space_mutex)
 #define PL_thr_key             (PL_Vars.Gthr_key)
 
 #else /* !PERL_GLOBAL_STRUCT */
 #define PL_Gmalloc_mutex       PL_malloc_mutex
 #define PL_Gop_mutex           PL_op_mutex
 #define PL_Gpatleave           PL_patleave
+#define PL_Gsharedsv_space     PL_sharedsv_space
+#define PL_Gsharedsv_space_mutex       PL_sharedsv_space_mutex
 #define PL_Gthr_key            PL_thr_key
 
 #endif /* PERL_GLOBAL_STRUCT */
index 9d63932..b295672 100755 (executable)
@@ -19,8 +19,6 @@ void thread_run(ithread* thread) {
        SV* thread_tid_ptr;
        SV* thread_ptr;
        dTHXa(thread->interp);
-
-
        PERL_SET_CONTEXT(thread->interp);
 
 #ifdef WIN32
@@ -29,15 +27,16 @@ void thread_run(ithread* thread) {
        thread->thr = pthread_self();
 #endif
 
+       SHAREDSvLOCK(threads);
        SHAREDSvEDIT(threads);
-       thread_tid_ptr = Perl_newSViv(sharedsv_space, (IV) thread->thr);
-       thread_ptr = Perl_newSViv(sharedsv_space, (IV) thread); 
+       thread_tid_ptr = Perl_newSViv(PL_sharedsv_space, (IV) thread->thr);
+       thread_ptr = Perl_newSViv(PL_sharedsv_space, (IV) thread);      
        hv_store_ent((HV*)SHAREDSvGET(threads), thread_tid_ptr, thread_ptr,0);
        SvREFCNT_dec(thread_tid_ptr);
        SHAREDSvRELEASE(threads);
-
-
+       SHAREDSvUNLOCK(threads);
        PL_perl_destruct_level = 2;
+
        {
 
                AV* params;
@@ -55,7 +54,7 @@ void thread_run(ithread* thread) {
                        }       
                }
                PUTBACK;
-               call_sv(thread->init_function, G_DISCARD);
+               call_sv(thread->init_function, G_DISCARD);
                FREETMPS;
                LEAVE;
 
@@ -106,10 +105,7 @@ SV* thread_create(char* class, SV* init_function, SV* params) {
                here we put the values of params and function to call onto namespace, this is so perl will properly             clone them when we call perl_clone.
        */
        
-       /*if(SvTYPE(SvRV(init_function)) == SVt_PVCV) {
-               CvCLONED_on(SvRV(init_function));
-       }
-       */
+
 
        temp_store = Perl_get_sv(current_perl, "threads::paramtempstore", TRUE | GV_ADDMULTI);
        Perl_sv_setsv(current_perl, temp_store,params);
@@ -118,7 +114,8 @@ SV* thread_create(char* class, SV* init_function, SV* params) {
 
        temp_store = Perl_get_sv(current_perl, "threads::calltempstore", TRUE | GV_ADDMULTI);
        Perl_sv_setsv(current_perl,temp_store, init_function);
-
+       init_function = NULL;
+       temp_store = NULL;
        
 
 #ifdef WIN32
@@ -126,19 +123,12 @@ SV* thread_create(char* class, SV* init_function, SV* params) {
 #else
        thread->interp = perl_clone(current_perl,0);
 #endif
-       
-       PL_perl_destruct_level = 2;
-
-#if 0
-       sv_dump(SvRV(Perl_get_sv(current_perl, "threads::calltempstore",FALSE)));       
-       sv_dump(SvRV(Perl_get_sv(thread->interp, "threads::calltempstore",FALSE)));     
-#endif
 
        thread->init_function = newSVsv(Perl_get_sv(thread->interp, "threads::calltempstore",FALSE));
        thread->params = newSVsv(Perl_get_sv(thread->interp, "threads::paramtempstore",FALSE));
 
-       init_function = NULL;
-       temp_store = NULL;
+
+
 
 
        /*
@@ -164,7 +154,7 @@ SV* thread_create(char* class, SV* init_function, SV* params) {
        /* lets init the thread */
 
 
-
+//     thread->mutex = (perl_mutex) malloc(sizeof(perl_mutex));
 
 
        MUTEX_INIT(&thread->mutex);
@@ -183,7 +173,7 @@ SV* thread_create(char* class, SV* init_function, SV* params) {
        MUTEX_UNLOCK(&create_mutex);    
 
 
-       if(!SvRV(obj_ref)) printf("FUCK\n");
+
   return obj_ref;
 }
 
@@ -209,29 +199,28 @@ SV* thread_self (char* class) {
        SV*             thread_tid_ptr;
        SV*             thread_ptr;
        HE*             thread_entry;
-       IV      pointer;
        PerlInterpreter *old_context = PERL_GET_CONTEXT;
 
 
        
+       SHAREDSvLOCK(threads);
        SHAREDSvEDIT(threads);
 #ifdef WIN32
-       thread_tid_ptr = Perl_newSViv(sharedsv_space, (IV) GetCurrentThreadId());
+       thread_tid_ptr = Perl_newSViv(PL_sharedsv_space, (IV) GetCurrentThreadId());
 #else
-       thread_tid_ptr = Perl_newSViv(sharedsv_space, (IV) pthread_self());
+       thread_tid_ptr = Perl_newSViv(PL_sharedsv_space, (IV) pthread_self());
 #endif
-       thread_entry = Perl_hv_fetch_ent(sharedsv_space,(HV*) SHAREDSvGET(threads), thread_tid_ptr, 0,0);
+       thread_entry = Perl_hv_fetch_ent(PL_sharedsv_space,(HV*) SHAREDSvGET(threads), thread_tid_ptr, 0,0);
        thread_ptr = HeVAL(thread_entry);
        SvREFCNT_dec(thread_tid_ptr);   
-       pointer = SvIV(thread_ptr);
        SHAREDSvRELEASE(threads);
-
+       SHAREDSvUNLOCK(threads);
        
 
 
        obj_ref = newSViv(0);
        obj = newSVrv(obj_ref, class);
-       sv_setiv(obj, pointer);
+       sv_setsv(obj, thread_ptr);
        SvREADONLY_on(obj);
        return obj_ref;
 }
@@ -299,13 +288,13 @@ BOOT:
        PL_perl_destruct_level = 2;
        threads = Perl_sharedsv_new(aTHX);
        SHAREDSvEDIT(threads);
-       SHAREDSvGET(threads) = (SV *)newHV();
+       ((HV*) SHAREDSvGET(threads)) = newHV();
        SHAREDSvRELEASE(threads);
        {
            
        
            SV* temp = get_sv("threads::sharedsv_space", TRUE | GV_ADDMULTI);
-           SV* temp2 = newSViv((IV)sharedsv_space );
+           SV* temp2 = newSViv((IV)PL_sharedsv_space );
            sv_setsv( temp , temp2 );
        }
        {
@@ -319,13 +308,12 @@ BOOT:
 #else
                thread->thr = pthread_self();
 #endif
+               thread_tid_ptr = Perl_newSViv(PL_sharedsv_space, (IV) thread->thr);
+               thread_ptr = Perl_newSViv(PL_sharedsv_space, (IV) thread);      
                SHAREDSvEDIT(threads);
-               thread_tid_ptr = Perl_newSViv(sharedsv_space, (IV) thread->thr);
-               thread_ptr = Perl_newSViv(sharedsv_space, (IV) thread); 
                hv_store_ent((HV*) SHAREDSvGET(threads), thread_tid_ptr, thread_ptr,0);
-               SvREFCNT_dec(thread_tid_ptr);
                SHAREDSvRELEASE(threads);
-
+               SvREFCNT_dec(thread_tid_ptr);
        }
        MUTEX_INIT(&create_mutex);
 
index 738d069..325b360 100644 (file)
--- a/perlapi.h
+++ b/perlapi.h
@@ -927,6 +927,10 @@ END_EXTERN_C
 #define PL_op_mutex            (*Perl_Gop_mutex_ptr(NULL))
 #undef  PL_patleave
 #define PL_patleave            (*Perl_Gpatleave_ptr(NULL))
+#undef  PL_sharedsv_space
+#define PL_sharedsv_space      (*Perl_Gsharedsv_space_ptr(NULL))
+#undef  PL_sharedsv_space_mutex
+#define PL_sharedsv_space_mutex        (*Perl_Gsharedsv_space_mutex_ptr(NULL))
 #undef  PL_thr_key
 #define PL_thr_key             (*Perl_Gthr_key_ptr(NULL))
 
index ff56195..7041924 100644 (file)
@@ -37,4 +37,6 @@ PERLVAR(Gmalloc_mutex,        perl_mutex)     /* Mutex for malloc */
 
 #if defined(USE_ITHREADS)
 PERLVAR(Gop_mutex,     perl_mutex)     /* Mutex for op refcounting */
+PERLVAR(Gsharedsv_space, PerlInterpreter*) /* The shared sv space */
+PERLVAR(Gsharedsv_space_mutex, perl_mutex) /* Mutex protecting the shared sv space */
 #endif
index 070a956..d03443c 100644 (file)
@@ -22,8 +22,7 @@
 
 #ifdef USE_ITHREADS
 
-PerlInterpreter* sharedsv_space;
-perl_mutex sharedsv_space_mutex;
+
 
 /*
   Shared SV
@@ -45,8 +44,8 @@ currently only stores a pointer to the first interpreter.
 void
 Perl_sharedsv_init(pTHX)
 {
-    sharedsv_space = PERL_GET_CONTEXT;
-    MUTEX_INIT(&sharedsv_space_mutex);
+    PL_sharedsv_space = PERL_GET_CONTEXT;
+    MUTEX_INIT(&PL_sharedsv_space_mutex);
 }
 
 /*
index f92a94a..bba2210 100644 (file)
@@ -10,8 +10,7 @@ typedef struct {
     PerlInterpreter* owner; /* who owns the lock */
 } shared_sv;
 
-extern PerlInterpreter* sharedsv_space;
-extern perl_mutex  sharedsv_space_mutex;
+
 
 void Perl_sharedsv_unlock_scope(pTHX_ shared_sv* ssv);
 void Perl_sharedsv_unlock(pTHX_ shared_sv* ssv);
@@ -24,13 +23,13 @@ void Perl_sharedsv_thrcnt_dec(pTHX_ shared_sv* ssv);
 
 
 #define SHAREDSvGET(a)     (a->sv)
-#define SHAREDSvEDIT(a)    { MUTEX_LOCK(&sharedsv_space_mutex);\
+#define SHAREDSvEDIT(a)    { MUTEX_LOCK(&PL_sharedsv_space_mutex);\
 SHAREDSvLOCK((a));\
-PERL_SET_CONTEXT(sharedsv_space);\
+PERL_SET_CONTEXT(PL_sharedsv_space);\
 }
 #define SHAREDSvRELEASE(a) { PERL_SET_CONTEXT((a)->owner);\
 SHAREDSvUNLOCK((a));\
-MUTEX_UNLOCK(&sharedsv_space_mutex);\
+MUTEX_UNLOCK(&PL_sharedsv_space_mutex);\
 }
 #define SHAREDSvLOCK(a)    Perl_sharedsv_lock(aTHX_ a)
 #define SHAREDSvUNLOCK(a)  Perl_sharedsv_unlock(aTHX_ a)