summaryrefslogtreecommitdiff
path: root/thread.h
diff options
context:
space:
mode:
authorTony Cook <tony@develop-help.com>2020-12-14 15:54:25 +1100
committerKarl Williamson <khw@cpan.org>2020-12-14 13:25:17 -0700
commit385ff59891f97046e99af32c3718c9d5cea167e6 (patch)
treea3656b72c9a05484a3b93e2bcd74d0f61bb596d1 /thread.h
parent13d2ab8bbbcb68824b0e53e403df7b9dd3ec55d5 (diff)
downloadperl-385ff59891f97046e99af32c3718c9d5cea167e6.tar.gz
consistently parenthesise the RW lock macro arguments
and fix the mixed up pointer vs non-pointer use of the mutex argument. Without the parentheses (or without the new tests in the previous commit) for code like; PERL_WRITE_LOCK(&PL_some_mutex); the MUTEX_LOCK(mutex.lock) in that code would expand to: MUTEX_LOCK(&PL_some_mutex.lock); and happen to work, even though the next line has: if ((mutex)->readers_count) treating the mutex parameter as a pointer. With the parentheses the MUTEX_LOCK(mutex.lock) becomes: MUTEX_LOCK((&PL_some_mutex).lock); which as expected fails to compile in a similar way to the pointer test code in the previous commit.
Diffstat (limited to 'thread.h')
-rw-r--r--thread.h26
1 files changed, 13 insertions, 13 deletions
diff --git a/thread.h b/thread.h
index 38020715ee..4c4966f79d 100644
--- a/thread.h
+++ b/thread.h
@@ -288,29 +288,29 @@
# define PERL_READ_LOCK(mutex) \
STMT_START { \
- MUTEX_LOCK(mutex.lock); \
+ MUTEX_LOCK(&(mutex)->lock); \
(mutex)->readers_count++; \
- MUTEX_UNLOCK(mutex.lock); \
+ MUTEX_UNLOCK(&(mutex)->lock); \
} STMT_END
# define PERL_READ_UNLOCK(mutex) \
STMT_START { \
- MUTEX_LOCK(mutex.lock); \
+ MUTEX_LOCK(&(mutex)->lock); \
(mutex)->readers_count--; \
if ((mutex)->readers_count <= 0) { \
- COND_SIGNAL(mutex.wakeup); \
+ COND_SIGNAL(&(mutex)->wakeup); \
(mutex)->readers_count = 0; \
} \
- MUTEX_UNLOCK(mutex.lock); \
+ MUTEX_UNLOCK(&(mutex)->lock); \
} STMT_END
# define PERL_WRITE_LOCK(mutex) \
STMT_START { \
- MUTEX_LOCK(mutex.lock); \
+ MUTEX_LOCK(&(mutex)->lock); \
do { \
if ((mutex)->readers_count == 0) \
break; \
- COND_WAIT(mutex.wakeup, mutex.lock); \
+ COND_WAIT(&(mutex)->wakeup, &(mutex)->lock); \
} \
while (1); \
\
@@ -319,21 +319,21 @@
# define PERL_WRITE_UNLOCK(mutex) \
STMT_START { \
- COND_SIGNAL(mutex.wakeup); \
- MUTEX_UNLOCK(mutex.lock); \
+ COND_SIGNAL(&(mutex)->wakeup); \
+ MUTEX_UNLOCK(&(mutex)->lock); \
} STMT_END
# define PERL_RW_MUTEX_INIT(mutex) \
STMT_START { \
- MUTEX_INIT(mutex.lock); \
- COND_INIT(mutex.wakeup); \
+ MUTEX_INIT(&(mutex)->lock); \
+ COND_INIT(&(mutex)->wakeup); \
(mutex)->readers_count = 0; \
} STMT_END
# define PERL_RW_MUTEX_DESTROY(mutex) \
STMT_START { \
- COND_DESTROY(mutex.wakeup); \
- MUTEX_DESTROY(mutex.lock); \
+ COND_DESTROY(&(mutex)->wakeup); \
+ MUTEX_DESTROY(&(mutex)->lock); \
} STMT_END
#endif