From: Willy Tarreau Date: Fri, 12 Jun 2020 09:42:25 +0000 (+0200) Subject: BUILD: thread: add parenthesis around values of locking macros X-Git-Tag: v2.2-dev10~56 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=db57a142c31016ff3e0dd533cb2b4de14445781e;p=thirdparty%2Fhaproxy.git 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. --- diff --git a/include/haproxy/thread.h b/include/haproxy/thread.h index 6520b77888..cf9ed12a47 100644 --- a/include/haproxy/thread.h +++ b/include/haproxy/thread.h @@ -277,16 +277,16 @@ static inline unsigned long thread_isolated() #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_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) #else /* !defined(DEBUG_THREAD) && !defined(DEBUG_FULL) */ @@ -296,16 +296,16 @@ static inline unsigned long thread_isolated() #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 __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_SPIN_INIT(l) __spin_init(l)