]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: fd/threads: silence a build warning with threads disabled
authorWilly Tarreau <w@1wt.eu>
Thu, 26 Nov 2020 21:25:10 +0000 (22:25 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 26 Nov 2020 21:28:41 +0000 (22:28 +0100)
Building with gcc-9.3.0 without threads may result in this warning:

In file included from include/haproxy/api-t.h:36,
                 from include/haproxy/api.h:33,
                 from src/fd.c:90:
src/fd.c: In function 'updt_fd_polling':
include/haproxy/fd.h:507:11: warning: array subscript 63 is above array bounds of 'int[1]' [-Warray-bounds]
  507 |  DISGUISE(write(poller_wr_pipe[tid], &c, 1));
include/haproxy/compiler.h:92:41: note: in definition of macro 'DISGUISE'
   92 | #define DISGUISE(v) ({ typeof(v) __v = (v); ALREADY_CHECKED(__v); __v; })
      |                                         ^
src/fd.c:113:5: note: while referencing 'poller_wr_pipe'
  113 | int poller_wr_pipe[MAX_THREADS]; // Pipe to wake the threads
      |     ^~~~~~~~~~~~~~

gcc is wrong but this time it cannot be blamed because it doesn't know
that the FD's thread_mask always has at least one bit set. Let's add
the test for all_threads_mask there. It will also remove that test and
drop the else block.

src/fd.c

index 79a9ec861ae71fce282eb6c2ce205032498f00d5..7cb864ec9183c0b96545f5d10b8943d2259748ae 100644 (file)
--- a/src/fd.c
+++ b/src/fd.c
@@ -394,10 +394,7 @@ int fd_takeover(int fd, void *expected_owner)
 
 void updt_fd_polling(const int fd)
 {
-       if ((fdtab[fd].thread_mask & all_threads_mask) == tid_bit) {
-
-               /* note: we don't have a test-and-set yet in hathreads */
-
+       if (all_threads_mask == 1UL || (fdtab[fd].thread_mask & all_threads_mask) == tid_bit) {
                if (HA_ATOMIC_BTS(&fdtab[fd].update_mask, tid))
                        return;