]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: tinfo: make thread_set functions return nth group/mask instead of first
authorWilly Tarreau <w@1wt.eu>
Mon, 27 Feb 2023 10:27:38 +0000 (11:27 +0100)
committerWilly Tarreau <w@1wt.eu>
Tue, 28 Feb 2023 09:28:47 +0000 (10:28 +0100)
thread_set_first_group() and thread_set_first_tmask() were modified
and renamed to instead return the number and mask of the nth group.
Passing zero continues to return the first one, but it will be more
convenient to use this way when building shards.

include/haproxy/tinfo.h
src/cfgparse.c
src/thread.c

index 4bae4f2b3abf5c2cffeffaded7e92cf3206b0d4d..3d10560f906982524a7488d6cf59e0162b899c47 100644 (file)
@@ -68,33 +68,36 @@ static inline int thread_set_is_empty(const struct thread_set *ts)
        return 1;
 }
 
-/* returns the number starting at 1 of the first thread-group set in thread set
+/* returns the number starting at 1 of the <n>th thread-group set in thread set
  * <ts>, or zero if the set is empty or if thread numbers are only absolute.
+ * <n> starts at zero and corresponds to the number of non-empty groups to be
+ * skipped (i.e. 0 returns the first one).
  */
-static inline int thread_set_first_group(const struct thread_set *ts)
+static inline int thread_set_nth_group(const struct thread_set *ts, int n)
 {
        int i;
 
        if (ts->nbgrp) {
                for (i = 0; i < MAX_TGROUPS; i++)
-                       if (ts->rel[i])
+                       if (ts->rel[i] && !n--)
                                return i + 1;
        }
        return 0;
 }
 
-/* returns the thread mask of the first assigned thread-group in the thread
+/* returns the thread mask of the <n>th assigned thread-group in the thread
  * set <ts> for relative sets, the first thread mask at all in case of absolute
  * sets, or zero if the set is empty. This is only used temporarily to ease the
- * transition.
+ * transition. <n> starts at zero and corresponds to the number of non-empty
+ * groups to be skipped (i.e. 0 returns the first one).
  */
-static inline ulong thread_set_first_tmask(const struct thread_set *ts)
+static inline ulong thread_set_nth_tmask(const struct thread_set *ts, int n)
 {
        int i;
 
        if (ts->nbgrp) {
                for (i = 0; i < MAX_TGROUPS; i++)
-                       if (ts->rel[i])
+                       if (ts->rel[i] && !n--)
                                return ts->rel[i];
        }
        return ts->abs[0];
index 06ee980972eb54747b8418b31415062b57892ee8..52f40d633de331903ac1217f62950b7d44e3a964 100644 (file)
@@ -3016,8 +3016,8 @@ init_proxies_list_stage1:
                                        }
 
                                        /* assign the first (and only) thread and group */
-                                       new_li->rx.bind_thread = thread_set_first_tmask(&new_ts);
-                                       new_li->rx.bind_tgroup = thread_set_first_group(&new_ts);
+                                       new_li->rx.bind_thread = thread_set_nth_tmask(&new_ts, 0);
+                                       new_li->rx.bind_tgroup = thread_set_nth_group(&new_ts, 0);
                                        done -= todo;
 
                                        shard++;
@@ -4458,8 +4458,8 @@ init_proxies_list_stage2:
 
                                        /* apply thread masks and groups to all receivers */
                                        list_for_each_entry(li, &bind_conf->listeners, by_bind) {
-                                               li->rx.bind_thread = thread_set_first_tmask(&bind_conf->thread_set);
-                                               li->rx.bind_tgroup = thread_set_first_group(&bind_conf->thread_set);
+                                               li->rx.bind_thread = thread_set_nth_tmask(&bind_conf->thread_set, 0);
+                                               li->rx.bind_tgroup = thread_set_nth_group(&bind_conf->thread_set, 0);
                                        }
 
                                        if (bind_conf->xprt->prepare_bind_conf &&
index 0deb9202b30841955ade9a34d32ee5ba2dedee3f..af27bbb603e0f07c41d49e723484464281bf107a 100644 (file)
@@ -1311,7 +1311,7 @@ int thread_resolve_group_mask(struct thread_set *ts, int defgrp, char **err)
        }
 
        /* update the thread_set */
-       if (!thread_set_first_group(&new_ts)) {
+       if (!thread_set_nth_group(&new_ts, 0)) {
                memprintf(err, "'thread' directive only references non-existing threads");
                return -1;
        }