]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
REORG: thread: move ha_get_pthread_id() to thread.c
authorWilly Tarreau <w@1wt.eu>
Wed, 6 Oct 2021 20:44:28 +0000 (22:44 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 6 Oct 2021 23:41:14 +0000 (01:41 +0200)
It's the last function which directly accesses the pthread_t, let's move
it to thread.c and leave a static inline for non-thread.

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

index a8b04784b7bdddbeeeccf109e0d87804aa65c17e..1881fa98df16975b3987313a4e202038a5a0dfc3 100644 (file)
@@ -163,6 +163,11 @@ static inline void set_thread_cpu_affinity()
 {
 }
 
+static inline unsigned long long ha_get_pthread_id(unsigned int thr)
+{
+       return 0;
+}
+
 #else /* !USE_THREAD */
 
 /********************** THREADS ENABLED ************************/
@@ -181,6 +186,7 @@ void ha_rwlock_init(HA_RWLOCK_T *l);
 void setup_extra_threads(void *(*handler)(void *));
 void wait_for_threads_completion();
 void set_thread_cpu_affinity();
+unsigned long long ha_get_pthread_id(unsigned int thr);
 
 extern volatile unsigned long all_threads_mask;
 extern volatile unsigned long threads_harmless_mask;
index 40b64b0e83ce0685d87d475f3e63fbdbb6ad23c1..be6cddf171fb9dd04bfe050f110ce38bc9cd6898 100644 (file)
 extern struct thread_info ha_thread_info[MAX_THREADS];
 extern THREAD_LOCAL struct thread_info *ti; /* thread_info for the current thread */
 
-/* Retrieves the opaque pthread_t of thread <thr> cast to an unsigned long long
- * since POSIX took great care of not specifying its representation, making it
- * hard to export for post-mortem analysis. For this reason we copy it into a
- * union and will use the smallest scalar type at least as large as its size,
- * which will keep endianness and alignment for all regular sizes. As a last
- * resort we end up with a long long ligned to the first bytes in memory, which
- * will be endian-dependent if pthread_t is larger than a long long (not seen
- * yet).
- */
-static inline unsigned long long ha_get_pthread_id(unsigned int thr)
-{
-#ifdef USE_THREAD
-       union {
-               pthread_t t;
-               unsigned long long ll;
-               unsigned int i;
-               unsigned short s;
-               unsigned char c;
-       } u = { 0 };
-
-       u.t = ha_thread_info[thr].pthread;
-
-       if (sizeof(u.t) <= sizeof(u.c))
-               return u.c;
-       else if (sizeof(u.t) <= sizeof(u.s))
-               return u.s;
-       else if (sizeof(u.t) <= sizeof(u.i))
-               return u.i;
-       return u.ll;
-#else
-       return 0;
-#endif
-}
-
 #endif /* _HAPROXY_TINFO_H */
index 25ee3ab947cbde3b85ad6b46ff34ef6854d50c71..c0b7bdbad1c7c43521786cd64c21b46b6359bbf9 100644 (file)
@@ -254,6 +254,36 @@ void set_thread_cpu_affinity()
 #endif /* USE_CPU_AFFINITY */
 }
 
+/* Retrieves the opaque pthread_t of thread <thr> cast to an unsigned long long
+ * since POSIX took great care of not specifying its representation, making it
+ * hard to export for post-mortem analysis. For this reason we copy it into a
+ * union and will use the smallest scalar type at least as large as its size,
+ * which will keep endianness and alignment for all regular sizes. As a last
+ * resort we end up with a long long ligned to the first bytes in memory, which
+ * will be endian-dependent if pthread_t is larger than a long long (not seen
+ * yet).
+ */
+unsigned long long ha_get_pthread_id(unsigned int thr)
+{
+       union {
+               pthread_t t;
+               unsigned long long ll;
+               unsigned int i;
+               unsigned short s;
+               unsigned char c;
+       } u = { 0 };
+
+       u.t = ha_thread_info[thr].pthread;
+
+       if (sizeof(u.t) <= sizeof(u.c))
+               return u.c;
+       else if (sizeof(u.t) <= sizeof(u.s))
+               return u.s;
+       else if (sizeof(u.t) <= sizeof(u.i))
+               return u.i;
+       return u.ll;
+}
+
 /* send signal <sig> to thread <thr> */
 void ha_tkill(unsigned int thr, int sig)
 {