Skip to content

Commit

Permalink
Make ENV_LOCK reentrant
Browse files Browse the repository at this point in the history
This is in preparation for future commits
  • Loading branch information
khwilliamson committed Jun 24, 2024
1 parent 262c141 commit 317eb84
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 3 deletions.
2 changes: 2 additions & 0 deletions embedvar.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions intrpvar.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion makedef.pl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions perl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions sv.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down

0 comments on commit 317eb84

Please sign in to comment.