From 317eb84550f521767cc9b0507d7a0f760531e920 Mon Sep 17 00:00:00 2001 From: Karl Williamson Date: Wed, 28 Feb 2024 15:01:01 -0700 Subject: [PATCH] Make ENV_LOCK reentrant This is in preparation for future commits --- embedvar.h | 2 ++ intrpvar.h | 2 ++ makedef.pl | 4 +++- perl.h | 9 +++++++-- sv.c | 5 +++++ 5 files changed, 19 insertions(+), 3 deletions(-) diff --git a/embedvar.h b/embedvar.h index b70dd1745db11..0cdfb76e65fdf 100644 --- a/embedvar.h +++ b/embedvar.h @@ -106,6 +106,8 @@ # 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_env_mutex_readers (vTHX->Ienv_mutex_readers) # define PL_envgv (vTHX->Ienvgv) # define PL_errgv (vTHX->Ierrgv) # define PL_errors (vTHX->Ierrors) diff --git a/intrpvar.h b/intrpvar.h index e17ce3fb5c563..e9aac8f3fce91 100644 --- a/intrpvar.h +++ b/intrpvar.h @@ -902,6 +902,8 @@ 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 */ +PERLVARI(I, env_mutex_readers, int, 0) #endif #ifdef USE_REENTRANT_API diff --git a/makedef.pl b/makedef.pl index ea46299104c34..8d90fc37513e7 100644 --- a/makedef.pl +++ b/makedef.pl @@ -417,7 +417,9 @@ sub readvar { PL_regex_padav PL_dollarzero_mutex PL_env_mutex - PL_hints_mutex + PL_env_mutex_depth + PL_env_mutex_readers + PL_hints_mutex PL_locale_mutex PL_locale_mutex_depth PL_my_ctx_mutex diff --git a/perl.h b/perl.h index e208b0923083d..b91d2f8c6c984 100644 --- a/perl.h +++ b/perl.h @@ -7068,8 +7068,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 ede9cbcfcd70f..cb9b9431292a3 100644 --- a/sv.c +++ b/sv.c @@ -16193,6 +16193,11 @@ 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; + PL_env_mutex_readers = 0; +#endif /* Unicode inversion lists */