From 91d37a4ab73d59d295cbd36220f5e1a2cf07aa63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonin=20D=C3=A9cimo?= Date: Thu, 14 Dec 2023 11:03:43 +0100 Subject: [PATCH] winpthreads: Inline INIT_RWLOCK into its only callsite MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Prevents a warning of `r` being shadowed, and makes the code clearer. Signed-off-by: Antonin Décimo Signed-off-by: Martin Storsjö --- mingw-w64-libraries/winpthreads/src/rwlock.c | 6 +++++- mingw-w64-libraries/winpthreads/src/rwlock.h | 3 --- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/mingw-w64-libraries/winpthreads/src/rwlock.c b/mingw-w64-libraries/winpthreads/src/rwlock.c index 933d43885..f2496f3db 100644 --- a/mingw-w64-libraries/winpthreads/src/rwlock.c +++ b/mingw-w64-libraries/winpthreads/src/rwlock.c @@ -47,7 +47,11 @@ static WINPTHREADS_ATTRIBUTE((noinline)) int rwl_unref(volatile pthread_rwlock_t static WINPTHREADS_ATTRIBUTE((noinline)) int rwl_ref(pthread_rwlock_t *rwl, int f ) { int r = 0; - INIT_RWLOCK(rwl); + if (STATIC_RWL_INITIALIZER(*rwl)) { + r = rwlock_static_init(rwl); + if (r != 0 && r != EBUSY) + return r; + } pthread_spin_lock(&rwl_global); if (!rwl || !*rwl || ((rwlock_t *)*rwl)->valid != LIFE_RWLOCK) r = EINVAL; diff --git a/mingw-w64-libraries/winpthreads/src/rwlock.h b/mingw-w64-libraries/winpthreads/src/rwlock.h index f08b0d37b..2d640faa9 100644 --- a/mingw-w64-libraries/winpthreads/src/rwlock.h +++ b/mingw-w64-libraries/winpthreads/src/rwlock.h @@ -26,9 +26,6 @@ #define LIFE_RWLOCK 0xBAB1F0ED #define DEAD_RWLOCK 0xDEADB0EF -#define INIT_RWLOCK(rwl) { int r; \ - if (STATIC_RWL_INITIALIZER(*rwl)) { if ((r = rwlock_static_init(rwl))) { if (r != EBUSY) return r; }}} - #define STATIC_RWL_INITIALIZER(x) ((pthread_rwlock_t)(x) == ((pthread_rwlock_t)PTHREAD_RWLOCK_INITIALIZER)) typedef struct rwlock_t rwlock_t;