]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: threads: add the current group ID in thread-local "tgid" variable
authorWilly Tarreau <w@1wt.eu>
Thu, 30 Sep 2021 06:00:11 +0000 (08:00 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 8 Oct 2021 15:22:26 +0000 (17:22 +0200)
This is the equivalent of "tid" for ease of access. In the future if we
make th_cfg a pure thread-local array (not a pointer), it may make sense
to move it there.

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

index d55c54e08be971ab5817180fbe63c597650db413..61bae9e9b4cb5aae673e77ae51e35080e0f4da3c 100644 (file)
@@ -61,6 +61,7 @@ enum { threads_sync_mask = 0 };
 enum { threads_want_rdv_mask = 0 };
 enum { tid_bit = 1UL };
 enum { tid = 0 };
+enum { tgid = 1 };
 
 #define HA_SPIN_INIT(l)               do { /* do nothing */ } while(0)
 #define HA_SPIN_DESTROY(l)            do { /* do nothing */ } while(0)
@@ -184,6 +185,7 @@ extern volatile unsigned long threads_sync_mask;
 extern volatile unsigned long threads_want_rdv_mask;
 extern THREAD_LOCAL unsigned long tid_bit; /* The bit corresponding to the thread id */
 extern THREAD_LOCAL unsigned int tid;      /* The thread id */
+extern THREAD_LOCAL unsigned int tgid;     /* The thread group id (starts at 1) */
 
 /* explanation for threads_want_rdv_mask, threads_harmless_mask, and
  * threads_sync_mask :
@@ -222,13 +224,16 @@ static inline void ha_set_thread(const struct thread_info *thr)
        if (thr) {
                BUG_ON(!thr->tid_bit);
                BUG_ON(!thr->tg);
+               BUG_ON(!thr->tg->tgid);
 
                ti      = thr;
                tg      = thr->tg;
                tid     = thr->tid;
                tid_bit = thr->tid_bit;
                th_ctx  = &ha_thread_ctx[tid];
+               tgid    = tg->tgid;
        } else {
+               tgid    = 1;
                tid     = 0;
                tid_bit = 1;
                ti      = &ha_thread_info[0];
index ce6a476598ded6321fb289cff8ef29b6bfdc95f0..750702d21052ed2c1dda0957abcaee0b7dec8c12 100644 (file)
@@ -66,6 +66,7 @@ volatile unsigned long threads_harmless_mask = 0;
 volatile unsigned long threads_idle_mask = 0;
 volatile unsigned long threads_sync_mask = 0;
 volatile unsigned long all_threads_mask __read_mostly  = 1; // nbthread 1 assumed by default
+THREAD_LOCAL unsigned int  tgid          = 1; // thread ID starts at 1
 THREAD_LOCAL unsigned int  tid           = 0;
 THREAD_LOCAL unsigned long tid_bit       = (1UL << 0);
 int thread_cpus_enabled_at_boot          = 1;