]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: threads: Handle nbthread == MAX_THREADS.
authorOlivier Houchard <ohouchard@haproxy.com>
Fri, 27 Jul 2018 15:06:59 +0000 (17:06 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 27 Jul 2018 15:18:22 +0000 (17:18 +0200)
If nbthread is MAX_THREADS, the shift operation needed to compute
all_threads_mask fails in thread_sync_init(). Instead pass a number
of threads to this function and let it compute the mask without
overflowing.

This should be backported to 1.8.

include/common/hathreads.h
src/hathreads.c

index 4aa6543fa4ecad79281d8edbf176fcb59db4c71b..35b6e6eac2fdc95b8db21c37d7cc3b68787c2926 100644 (file)
@@ -252,7 +252,7 @@ static inline void __ha_barrier_full(void)
 #define THREAD_NO_SYNC()      thread_no_sync()
 #define THREAD_NEED_SYNC()    thread_need_sync()
 
-int  thread_sync_init(unsigned long mask);
+int  thread_sync_init(int nbthread);
 void thread_sync_enable(void);
 void thread_want_sync(void);
 void thread_enter_sync(void);
index fa9993bd0c28424660e59334bf01457faf2a7620..c0c5956f504922efb93f2241089a827aa2130164 100644 (file)
@@ -37,11 +37,11 @@ volatile unsigned long all_threads_mask  = 0;
 struct lock_stat lock_stats[LOCK_LABELS];
 #endif
 
-/* Initializes the sync point. It creates a pipe used by threads to wakup all
- * others when a sync is requested. It also initialize the mask of all create
+/* Initializes the sync point. It creates a pipe used by threads to wakup all
+ * others when a sync is requested. It also initializes the mask of all created
  * threads. It returns 0 on success and -1 if an error occurred.
  */
-int thread_sync_init(unsigned long mask)
+int thread_sync_init(int nbthread)
 {
        int rfd;
 
@@ -52,7 +52,9 @@ int thread_sync_init(unsigned long mask)
        fcntl(rfd, F_SETFL, O_NONBLOCK);
        fd_insert(rfd, thread_sync_io_handler, thread_sync_io_handler, MAX_THREADS_MASK);
 
-       all_threads_mask = mask;
+       /* we proceed like this to be sure never to overflow the left shift */
+       all_threads_mask = 1UL << (nbthread - 1);
+       all_threads_mask |= all_threads_mask - 1;
        return 0;
 }