diff options
author | Karl Williamson <khw@cpan.org> | 2020-12-08 18:30:56 -0700 |
---|---|---|
committer | Karl Williamson <khw@cpan.org> | 2020-12-19 22:00:29 -0700 |
commit | 7510ca24a0ab79a6cf9eb76f13117b4e4d18051e (patch) | |
tree | e017ae2b953bec2c0d5e92ca455216752d52cc0a /thread.h | |
parent | fbd8d54d31dadf460479192f11f6569ab3d10dd3 (diff) | |
download | perl-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.h | 6 |
1 files changed, 5 insertions, 1 deletions
@@ -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); \ |