From: Artur Bergman Date: Wed, 24 Oct 2001 11:06:35 +0000 (+0000) Subject: We only need to fetch the SV from the backend if the index X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=55fc11ad574fdface3f93a0c10965511fdcfd69b;p=p5sagit%2Fp5-mst-13.2.git 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. p4raw-id: //depot/perl@12616 --- diff --git a/ext/threads/shared/shared.xs b/ext/threads/shared/shared.xs index 90049e2..86ad419 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 0deabb2..dde1153 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 5a55be6..f82804d 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)