]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUILD: thread: add parenthesis around values of locking macros
authorWilly Tarreau <w@1wt.eu>
Fri, 12 Jun 2020 09:42:25 +0000 (11:42 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 12 Jun 2020 09:46:44 +0000 (11:46 +0200)
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.

include/haproxy/thread.h

index 6520b7788809e3e7e314fa763fedebbe5a61ebf4..cf9ed12a474373f85dc7d948f8cf05e6454d155e 100644 (file)
@@ -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)