winpthreads: Inline INIT_RWLOCK into its only callsite

Prevents a warning of `r` being shadowed, and makes the code clearer.

Signed-off-by: Antonin Décimo <antonin@tarides.com>
Signed-off-by: Martin Storsjö <martin@martin.st>
This commit is contained in:
Antonin Décimo 2023-12-14 11:03:43 +01:00 committed by Martin Storsjö
parent d64ea219aa
commit 91d37a4ab7
2 changed files with 5 additions and 4 deletions

View File

@ -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 ) static WINPTHREADS_ATTRIBUTE((noinline)) int rwl_ref(pthread_rwlock_t *rwl, int f )
{ {
int r = 0; 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); pthread_spin_lock(&rwl_global);
if (!rwl || !*rwl || ((rwlock_t *)*rwl)->valid != LIFE_RWLOCK) r = EINVAL; if (!rwl || !*rwl || ((rwlock_t *)*rwl)->valid != LIFE_RWLOCK) r = EINVAL;

View File

@ -26,9 +26,6 @@
#define LIFE_RWLOCK 0xBAB1F0ED #define LIFE_RWLOCK 0xBAB1F0ED
#define DEAD_RWLOCK 0xDEADB0EF #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)) #define STATIC_RWL_INITIALIZER(x) ((pthread_rwlock_t)(x) == ((pthread_rwlock_t)PTHREAD_RWLOCK_INITIALIZER))
typedef struct rwlock_t rwlock_t; typedef struct rwlock_t rwlock_t;