Change 12616 by sky@sky-borderline on 2001/10/24 11:06:35

        We only need to fetch the SV from the backend if the index is not the same as 
mg_private
               in theory this could be a problem if there are an exact multiple of U16 
changes of a shared
               variable between two access in a given thread, we choose to avoid 
theory for now.

Affected files ...

... //depot/perl/ext/threads/shared/shared.xs#2 edit
... //depot/perl/sharedsv.c#10 edit
... //depot/perl/sharedsv.h#6 edit

Differences ...

==== //depot/perl/ext/threads/shared/shared.xs#2 (text) ====
Index: perl/ext/threads/shared/shared.xs
--- perl/ext/threads/shared/shared.xs.~1~       Wed Oct 24 05:15:05 2001
+++ perl/ext/threads/shared/shared.xs   Wed Oct 24 05:15:05 2001
@@ -24,11 +24,14 @@
 int shared_sv_fetch_mg (pTHX_ SV* sv, MAGIC *mg) {
     shared_sv* shared = (shared_sv*) SvIV(mg->mg_obj);
     SHAREDSvLOCK(shared);
-    if(SvROK(SHAREDSvGET(shared))) {
-        shared_sv* target = (shared_sv*) SvIV(SvRV(SHAREDSvGET(shared)));
-       shared_sv_attach_sv(sv, target);
-    } else {
-        sv_setsv(sv, SHAREDSvGET(shared));
+    if(mg->mg_private != shared->index) {
+        if(SvROK(SHAREDSvGET(shared))) {
+            shared_sv* target = (shared_sv*) SvIV(SvRV(SHAREDSvGET(shared)));
+           shared_sv_attach_sv(sv, target);
+        } else {
+            sv_setsv(sv, SHAREDSvGET(shared));
+        }
+        mg->mg_private = shared->index;
     }
     SHAREDSvUNLOCK(shared);
 
@@ -51,10 +54,11 @@
         }
         Perl_sv_free(PL_sharedsv_space,SHAREDSvGET(shared));
         SHAREDSvGET(shared) = newRV_noinc(newSViv((IV)target));
-        SvROK_off(sv);
     } else {
         sv_setsv(SHAREDSvGET(shared), sv);
     }
+    shared->index++;
+    mg->mg_private = shared->index;
     SHAREDSvRELEASE(shared);
     if(SvROK(SHAREDSvGET(shared)))
        Perl_sharedsv_thrcnt_inc(aTHX_ (shared_sv*) SvIV(SvRV(SHAREDSvGET(shared))));  
     
@@ -136,6 +140,7 @@
         shared_magic->mg_virtual = &svtable;
         shared_magic->mg_obj = newSViv((IV)shared);
         shared_magic->mg_flags |= MGf_REFCOUNTED;
+        shared_magic->mg_private = 0;
         SvMAGICAL_on(value);
         RETVAL = obj;
         OUTPUT:                

==== //depot/perl/sharedsv.c#10 (text) ====
Index: perl/sharedsv.c
--- perl/sharedsv.c.~1~ Wed Oct 24 05:15:05 2001
+++ perl/sharedsv.c     Wed Oct 24 05:15:05 2001
@@ -68,6 +68,7 @@
     COND_INIT(&ssv->user_cond);
     ssv->owner = 0;
     ssv->locks = 0;
+    ssv->index = 0;
     return ssv;
 }
 

==== //depot/perl/sharedsv.h#6 (text) ====
Index: perl/sharedsv.h
--- perl/sharedsv.h.~1~ Wed Oct 24 05:15:05 2001
+++ perl/sharedsv.h     Wed Oct 24 05:15:05 2001
@@ -7,6 +7,7 @@
     perl_cond           user_cond;      /* For user-level conditions */
     IV                  locks;          /* Number of locks held */
     PerlInterpreter    *owner;          /* Who owns the lock? */
+    U16                 index;          /* Update index */
 } shared_sv;
 
 #define SHAREDSvGET(a)      (a->sv)
End of Patch.

Reply via email to