From b35a82ba015aa347209a0285320608fcc71a9690 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Fri, 12 Jun 2020 11:42:25 +0200 Subject: [PATCH] BUILD: thread: add parenthesis around values of locking macros clang just failed on fd.c with this error: src/fd.c:491:9: error: logical not is only applied to the left hand side of this comparison [-Werror,-Wlogical-not-parentheses] while (HA_SPIN_TRYLOCK(OTHER_LOCK, &log_lock) != 0) { ^ ~~ That's because this expands to this: while (!pl_try_s(&log_lock) != 0) { Let's just add parenthesis in the TRYLOCK macros to avoid this. This may need to be backported if commit df187875d ("BUG/MEDIUM: log: don't hold the log lock during writev() on a file descriptor") is backported as well as it seems to be the first one to trigger it. (cherry picked from commit db57a142c31016ff3e0dd533cb2b4de14445781e) [wt: applied by hand to common/hathread.h since context significantly differed] Signed-off-by: Willy Tarreau --- include/common/hathreads.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/include/common/hathreads.h b/include/common/hathreads.h index 61a1aa4..72573d6 100644 --- a/include/common/hathreads.h +++ b/include/common/hathreads.h @@ -628,7 +628,7 @@ extern struct lock_stat lock_stats[LOCK_LABELS]; #define __SPIN_INIT(l) ({ (*l) = 0; }) #define __SPIN_DESTROY(l) ({ (*l) = 0; }) #define __SPIN_LOCK(l) pl_take_s(l) -#define __SPIN_TRYLOCK(l) !pl_try_s(l) +#define __SPIN_TRYLOCK(l) (!pl_try_s(l)) #define __SPIN_UNLOCK(l) pl_drop_s(l) #define __HA_RWLOCK_T unsigned long @@ -636,10 +636,10 @@ extern struct lock_stat lock_stats[LOCK_LABELS]; #define __RWLOCK_INIT(l) ({ (*l) = 0; }) #define __RWLOCK_DESTROY(l) ({ (*l) = 0; }) #define __RWLOCK_WRLOCK(l) pl_take_w(l) -#define __RWLOCK_TRYWRLOCK(l) !pl_try_w(l) +#define __RWLOCK_TRYWRLOCK(l) (!pl_try_w(l)) #define __RWLOCK_WRUNLOCK(l) pl_drop_w(l) #define __RWLOCK_RDLOCK(l) pl_take_r(l) -#define __RWLOCK_TRYRDLOCK(l) !pl_try_r(l) +#define __RWLOCK_TRYRDLOCK(l) (!pl_try_r(l)) #define __RWLOCK_RDUNLOCK(l) pl_drop_r(l) #define HA_SPINLOCK_T struct ha_spinlock @@ -1027,7 +1027,7 @@ static inline void __spin_unlock(enum lock_label lbl, struct ha_spinlock *l, #define HA_SPIN_INIT(l) ({ (*l) = 0; }) #define HA_SPIN_DESTROY(l) ({ (*l) = 0; }) #define HA_SPIN_LOCK(lbl, l) pl_take_s(l) -#define HA_SPIN_TRYLOCK(lbl, l) !pl_try_s(l) +#define HA_SPIN_TRYLOCK(lbl, l) (!pl_try_s(l)) #define HA_SPIN_UNLOCK(lbl, l) pl_drop_s(l) #define HA_RWLOCK_T unsigned long @@ -1035,10 +1035,10 @@ static inline void __spin_unlock(enum lock_label lbl, struct ha_spinlock *l, #define HA_RWLOCK_INIT(l) ({ (*l) = 0; }) #define HA_RWLOCK_DESTROY(l) ({ (*l) = 0; }) #define HA_RWLOCK_WRLOCK(lbl,l) pl_take_w(l) -#define HA_RWLOCK_TRYWRLOCK(lbl,l) !pl_try_w(l) +#define HA_RWLOCK_TRYWRLOCK(lbl,l) (!pl_try_w(l)) #define HA_RWLOCK_WRUNLOCK(lbl,l) pl_drop_w(l) #define HA_RWLOCK_RDLOCK(lbl,l) pl_take_r(l) -#define HA_RWLOCK_TRYRDLOCK(lbl,l) !pl_try_r(l) +#define HA_RWLOCK_TRYRDLOCK(lbl,l) (!pl_try_r(l)) #define HA_RWLOCK_RDUNLOCK(lbl,l) pl_drop_r(l) #endif /* DEBUG_THREAD */ -- 1.7.10.4