summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/threads/shared/shared.xs17
-rw-r--r--sharedsv.c1
-rw-r--r--sharedsv.h1
3 files changed, 13 insertions, 6 deletions
diff --git a/ext/threads/shared/shared.xs b/ext/threads/shared/shared.xs
index 90049e2a8e..86ad419541 100644
--- a/ext/threads/shared/shared.xs
+++ b/ext/threads/shared/shared.xs
@@ -24,11 +24,14 @@ void shared_sv_attach_sv (SV* sv, shared_sv* shared) {
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 @@ int shared_sv_store_mg (pTHX_ SV* sv, MAGIC *mg) {
}
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 @@ new(class, value)
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:
diff --git a/sharedsv.c b/sharedsv.c
index 0deabb23ab..dde1153290 100644
--- a/sharedsv.c
+++ b/sharedsv.c
@@ -68,6 +68,7 @@ Perl_sharedsv_new(pTHX)
COND_INIT(&ssv->user_cond);
ssv->owner = 0;
ssv->locks = 0;
+ ssv->index = 0;
return ssv;
}
diff --git a/sharedsv.h b/sharedsv.h
index 5a55be632f..f82804dba4 100644
--- a/sharedsv.h
+++ b/sharedsv.h
@@ -7,6 +7,7 @@ typedef struct {
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)