From: Vincent Pit Date: Sat, 28 Feb 2009 16:25:35 +0000 (+0100) Subject: Initialize the global op names cache in a critical section X-Git-Tag: v0.32~3 X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2FVariable-Magic.git;a=commitdiff_plain;h=da95f9db8211008bbb415d2de11e3616daf4017e Initialize the global op names cache in a critical section --- diff --git a/Magic.xs b/Magic.xs index 0915f4b..e9d9deb 100644 --- a/Magic.xs +++ b/Magic.xs @@ -623,6 +623,10 @@ STATIC UV vmg_dispell(pTHX_ SV *sv, U16 sig) { #define VMG_OP_INFO_NAME 1 #define VMG_OP_INFO_OBJECT 2 +#if VMG_THREADSAFE +STATIC perl_mutex vmg_op_name_init_mutex; +#endif + STATIC U32 vmg_op_name_init = 0; STATIC unsigned char vmg_op_name_len[MAXO] = { 0 }; @@ -630,12 +634,18 @@ STATIC void vmg_op_info_init(pTHX_ unsigned int opinfo) { #define vmg_op_info_init(W) vmg_op_info_init(aTHX_ (W)) switch (opinfo) { case VMG_OP_INFO_NAME: +#if VMG_THREADSAFE + MUTEX_LOCK(&vmg_op_name_init_mutex); +#endif if (!vmg_op_name_init) { OPCODE t; for (t = 0; t < OP_max; ++t) vmg_op_name_len[t] = strlen(PL_op_name[t]); vmg_op_name_init = 1; } +#if VMG_THREADSAFE + MUTEX_UNLOCK(&vmg_op_name_init_mutex); +#endif break; case VMG_OP_INFO_OBJECT: { dMY_CXT; @@ -1199,6 +1209,10 @@ BOOT: MY_CXT.wizards = newHV(); hv_iterinit(MY_CXT.wizards); /* Allocate iterator */ MY_CXT.b__op_stashes[0] = NULL; +#if VMG_THREADSAFE + MUTEX_INIT(&vmg_op_name_init_mutex); +#endif + stash = gv_stashpv(__PACKAGE__, 1); newCONSTSUB(stash, "SIG_MIN", newSVuv(SIG_MIN)); newCONSTSUB(stash, "SIG_MAX", newSVuv(SIG_MAX));