diff --git a/embedvar.h b/embedvar.h index b70dd1745db1..df13032e0d12 100644 --- a/embedvar.h +++ b/embedvar.h @@ -106,6 +106,7 @@ # define PL_efloatsize (vTHX->Iefloatsize) # define PL_endav (vTHX->Iendav) # define PL_Env (vTHX->IEnv) +# define PL_env_mutex_depth (vTHX->Ienv_mutex_depth) # define PL_envgv (vTHX->Ienvgv) # define PL_errgv (vTHX->Ierrgv) # define PL_errors (vTHX->Ierrors) diff --git a/intrpvar.h b/intrpvar.h index e17ce3fb5c56..d939023705af 100644 --- a/intrpvar.h +++ b/intrpvar.h @@ -902,6 +902,7 @@ PERLVAR(I, regex_padav, AV *) /* All regex objects, indexed via the PERLVAR(I, stashpad, HV **) /* for CopSTASH */ PERLVARI(I, stashpadmax, PADOFFSET, 64) PERLVARI(I, stashpadix, PADOFFSET, 0) +PERLVARI(I, env_mutex_depth, int, 0) /* Emulate general semaphore */ #endif #ifdef USE_REENTRANT_API diff --git a/makedef.pl b/makedef.pl index ea46299104c3..6a461956acad 100644 --- a/makedef.pl +++ b/makedef.pl @@ -417,7 +417,8 @@ sub readvar { PL_regex_padav PL_dollarzero_mutex PL_env_mutex - PL_hints_mutex + PL_env_mutex_depth + PL_hints_mutex PL_locale_mutex PL_locale_mutex_depth PL_my_ctx_mutex diff --git a/perl.h b/perl.h index 64901c2eb550..7297fd86f88c 100644 --- a/perl.h +++ b/perl.h @@ -7065,8 +7065,13 @@ typedef struct am_table_short AMTS; #endif #ifdef USE_THREADS -# define ENV_LOCK PERL_WRITE_LOCK(&PL_env_mutex) -# define ENV_UNLOCK PERL_WRITE_UNLOCK(&PL_env_mutex) +# define ENV_LOCK PERL_REENTRANT_LOCK("env", \ + &PL_env_mutex, \ + PL_env_mutex_depth, \ + 1) +# define ENV_UNLOCK PERL_REENTRANT_UNLOCK("env", \ + &PL_env_mutex, \ + PL_env_mutex_depth) # define ENV_READ_LOCK PERL_READ_LOCK(&PL_env_mutex) # define ENV_READ_UNLOCK PERL_READ_UNLOCK(&PL_env_mutex) # define ENV_INIT PERL_RW_MUTEX_INIT(&PL_env_mutex) diff --git a/sv.c b/sv.c index b90721f810b0..d5ccc4e2381c 100644 --- a/sv.c +++ b/sv.c @@ -16240,6 +16240,10 @@ perl_clone_using(PerlInterpreter *proto_perl, UV flags, PL_less_dicey_locale_buf = NULL; PL_less_dicey_locale_bufsize = 0; #endif +#ifdef USE_THREADS + assert(PL_env_mutex_depth <= 0); + PL_env_mutex_depth = 0; +#endif /* Unicode inversion lists */