]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: thread: make wake_thread() take care of the sleeping threads mask
authorWilly Tarreau <w@1wt.eu>
Mon, 20 Jun 2022 07:14:40 +0000 (09:14 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 1 Jul 2022 17:15:14 +0000 (19:15 +0200)
Almost every call place of wake_thread() checks for sleeping threads and
clears the sleeping mask itself, while the function is solely used for
there. Let's move the check and the clearing of the bit inside the function
itself. Note that updt_fd_polling() still performs the check because its
rules are a bit different.

include/haproxy/fd.h
src/fd.c
src/task.c

index cf2d02b781f9a494c228a1d019611017a1790337..010fdacf8e05634cb5a6e11aeaa2aae4105d575c 100644 (file)
@@ -369,11 +369,13 @@ static inline unsigned int hap_fd_isset(int fd, unsigned int *evts)
        return evts[fd / (8*sizeof(*evts))] & (1U << (fd & (8*sizeof(*evts) - 1)));
 }
 
-static inline void wake_thread(int tid)
+static inline void wake_thread(int thr)
 {
-       char c = 'c';
-
-       DISGUISE(write(poller_wr_pipe[tid], &c, 1));
+       if (sleeping_thread_mask & (1UL << thr)) {
+               char c = 'c';
+               _HA_ATOMIC_AND(&sleeping_thread_mask, ~(1UL << thr));
+               DISGUISE(write(poller_wr_pipe[thr], &c, 1));
+       }
 }
 
 
index 079df15af0519e1d16ca40047566df33ffdc558c..96d77bd55fb2ea1ea0c92f025b123a3e99b23508 100644 (file)
--- a/src/fd.c
+++ b/src/fd.c
@@ -454,7 +454,6 @@ void updt_fd_polling(const int fd)
                        /* we need to wake up one thread to handle it immediately */
                        int thr = my_ffsl(fdtab[fd].thread_mask & ~tid_bit & all_threads_mask) - 1;
 
-                       _HA_ATOMIC_AND(&sleeping_thread_mask, ~(1UL << thr));
                        wake_thread(thr);
                }
        }
index fc698d52bfff86edd4a9222147d4d74f97ca56de..76a7432737fcd0754477c1089a109de92de4639d 100644 (file)
@@ -86,10 +86,7 @@ void task_kill(struct task *t)
                                       list_to_mt_list(&((struct tasklet *)t)->list));
                        _HA_ATOMIC_INC(&ha_thread_ctx[thr].rq_total);
                        _HA_ATOMIC_INC(&ha_thread_ctx[thr].tasks_in_list);
-                       if (sleeping_thread_mask & (1UL << thr)) {
-                               _HA_ATOMIC_AND(&sleeping_thread_mask, ~(1UL << thr));
-                               wake_thread(thr);
-                       }
+                       wake_thread(thr);
                        return;
                }
        }
@@ -124,10 +121,7 @@ void tasklet_kill(struct tasklet *t)
                        MT_LIST_APPEND(&ha_thread_ctx[thr].shared_tasklet_list,
                                       list_to_mt_list(&t->list));
                        _HA_ATOMIC_INC(&ha_thread_ctx[thr].rq_total);
-                       if (sleeping_thread_mask & (1UL << thr)) {
-                               _HA_ATOMIC_AND(&sleeping_thread_mask, ~(1UL << thr));
-                               wake_thread(thr);
-                       }
+                       wake_thread(thr);
                        return;
                }
        }
@@ -168,10 +162,7 @@ void __tasklet_wakeup_on(struct tasklet *tl, int thr)
                /* this tasklet runs on a specific thread. */
                MT_LIST_APPEND(&ha_thread_ctx[thr].shared_tasklet_list, list_to_mt_list(&tl->list));
                _HA_ATOMIC_INC(&ha_thread_ctx[thr].rq_total);
-               if (sleeping_thread_mask & (1UL << thr)) {
-                       _HA_ATOMIC_AND(&sleeping_thread_mask, ~(1UL << thr));
-                       wake_thread(thr);
-               }
+               wake_thread(thr);
        }
 }
 
@@ -262,12 +253,7 @@ void __task_wakeup(struct task *t)
                /* If all threads that are supposed to handle this task are sleeping,
                 * wake one.
                 */
-               if (sleeping_thread_mask & (1UL << thr)) {
-                       unsigned long m = 1UL << thr;
-
-                       _HA_ATOMIC_AND(&sleeping_thread_mask, ~m);
-                       wake_thread(thr);
-               }
+               wake_thread(thr);
        }
 #endif
        return;