MINOR: threads: add the current group ID in thread-local "tgid" variable
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.
diff --git a/include/haproxy/thread.h b/include/haproxy/thread.h
index d55c54e..61bae9e 100644
--- a/include/haproxy/thread.h
+++ b/include/haproxy/thread.h
@@ -61,6 +61,7 @@
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_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 @@
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];
diff --git a/src/thread.c b/src/thread.c
index ce6a476..750702d 100644
--- a/src/thread.c
+++ b/src/thread.c
@@ -66,6 +66,7 @@
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;