summaryrefslogtreecommitdiff
path: root/thread.h
diff options
context:
space:
mode:
authorKarl Williamson <khw@cpan.org>2020-12-08 18:30:56 -0700
committerKarl Williamson <khw@cpan.org>2020-12-19 22:00:29 -0700
commit7510ca24a0ab79a6cf9eb76f13117b4e4d18051e (patch)
treee017ae2b953bec2c0d5e92ca455216752d52cc0a /thread.h
parentfbd8d54d31dadf460479192f11f6569ab3d10dd3 (diff)
downloadperl-7510ca24a0ab79a6cf9eb76f13117b4e4d18051e.tar.gz
Make many-reader mutexes more resilient
These mutexes rely on a counter being accurate to work. If for some reason that I can't imagine happening, the count goes below 0, this commit resets it to zero, which may be enough to cause the program to continue.
Diffstat (limited to 'thread.h')
-rw-r--r--thread.h6
1 files changed, 5 insertions, 1 deletions
diff --git a/thread.h b/thread.h
index 4c4966f79d..99679b22f5 100644
--- a/thread.h
+++ b/thread.h
@@ -298,6 +298,7 @@
MUTEX_LOCK(&(mutex)->lock); \
(mutex)->readers_count--; \
if ((mutex)->readers_count <= 0) { \
+ assert((mutex)->readers_count == 0); \
COND_SIGNAL(&(mutex)->wakeup); \
(mutex)->readers_count = 0; \
} \
@@ -308,8 +309,11 @@
STMT_START { \
MUTEX_LOCK(&(mutex)->lock); \
do { \
- if ((mutex)->readers_count == 0) \
+ if ((mutex)->readers_count <= 0) { \
+ assert((mutex)->readers_count == 0); \
+ (mutex)->readers_count = 0; \
break; \
+ } \
COND_WAIT(&(mutex)->wakeup, &(mutex)->lock); \
} \
while (1); \