]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: threads: make tg point to the current thread's group
authorWilly Tarreau <w@1wt.eu>
Tue, 28 Sep 2021 06:58:49 +0000 (08:58 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 8 Oct 2021 15:22:26 +0000 (17:22 +0200)
A the "tg" thread-local variable now always points to the current
thread group. It's pre-initializd to the first one during boot and is
set to point to the thread's one by ha_set_tid(). This last one takes
care of checking whether the thread group was assigned or not because
it may be called during boot before threads are initialized.

include/haproxy/thread.h

index 37808d9d78c17a1a8973d2d2c2c0fc55568780c2..14c88f0379a813fab4b20908a280f23edfd77f0f 100644 (file)
@@ -90,6 +90,7 @@ enum { tid = 0 };
 static inline void ha_set_tid(unsigned int tid)
 {
        ti = &ha_thread_info[tid];
+       tg = ti->tg ? ti->tg : &ha_tgroup_info[0];
        th_ctx = &ha_thread_ctx[tid];
 }
 
@@ -201,12 +202,17 @@ extern THREAD_LOCAL unsigned int tid;      /* The thread id */
 
 #define ha_sigmask(how, set, oldset)  pthread_sigmask(how, set, oldset)
 
-/* sets the thread ID and the TID bit for the current thread */
+/* sets the thread ID, TID bit and thread cfg/ctx pointers for the current
+ * thread. Since it may be called during early boot even before threads are
+ * initialized, we have to be extra careful about some fields which may still
+ * be null. For example tg may be null during a part of the boot.
+ */
 static inline void ha_set_tid(unsigned int data)
 {
        tid     = data;
        tid_bit = (1UL << tid);
        ti      = &ha_thread_info[tid];
+       tg      = ti->tg ? ti->tg : &ha_tgroup_info[0];
        th_ctx  = &ha_thread_ctx[tid];
 }