From 333f433b6bc052819c91a73e390fb65b29161409 Mon Sep 17 00:00:00 2001 From: Drago Goricanec Date: Fri, 25 Sep 1998 07:01:09 +0900 Subject: [PATCH] lock sv_mutex in new_he() and del_he() for USE_THREADS Message-Id: <19980924220109J.drago@otsd.ts.fujitsu.co.jp> Subject: [PATCH 5.005_51] Re: Perl 5.005_51 not yet multi Thread safe p4raw-id: //depot/perl@1880 --- hv.c | 22 ++++++++++++---------- proto.h | 2 +- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/hv.c b/hv.c index 2416831..ddd989f 100644 --- a/hv.c +++ b/hv.c @@ -18,7 +18,7 @@ static void hv_magic_check _((HV *hv, bool *needs_copy, bool *needs_store)); #ifndef PERL_OBJECT static void hsplit _((HV *hv)); static void hfreeentries _((HV *hv)); -static HE* more_he _((void)); +static void more_he _((void)); #endif #if defined(STRANGE_MALLOC) || defined(MYMALLOC) @@ -32,22 +32,25 @@ STATIC HE* new_he(void) { HE* he; - if (PL_he_root) { - he = PL_he_root; - PL_he_root = HeNEXT(he); - return he; - } - return more_he(); + LOCK_SV_MUTEX; + if (!PL_he_root) + more_he(); + he = PL_he_root; + PL_he_root = HeNEXT(he); + UNLOCK_SV_MUTEX; + return he; } STATIC void del_he(HE *p) { + LOCK_SV_MUTEX; HeNEXT(p) = (HE*)PL_he_root; PL_he_root = p; + UNLOCK_SV_MUTEX; } -STATIC HE* +STATIC void more_he(void) { register HE* he; @@ -60,7 +63,6 @@ more_he(void) he++; } HeNEXT(he) = 0; - return new_he(); } STATIC HEK * @@ -1167,9 +1169,9 @@ unsharepvn(char *str, I32 len, U32 hash) del_he(entry); --xhv->xhv_keys; } - UNLOCK_STRTAB_MUTEX; break; } + UNLOCK_STRTAB_MUTEX; if (!found) warn("Attempt to free non-existent shared string"); diff --git a/proto.h b/proto.h index e1406f6..6e54567 100644 --- a/proto.h +++ b/proto.h @@ -695,7 +695,7 @@ VIRTUAL struct perl_vars *Perl_GetVars _((void)); protected: void hsplit _((HV *hv)); void hfreeentries _((HV *hv)); -HE* more_he _((void)); +void more_he _((void)); HE* new_he _((void)); void del_he _((HE *p)); HEK *save_hek _((char *str, I32 len, U32 hash)); -- 2.7.4