]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
REORG: threads: move ha_get_pthread_id() to tinfo.h
authorWilly Tarreau <w@1wt.eu>
Mon, 13 Sep 2021 16:42:07 +0000 (18:42 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 17 Sep 2021 14:08:34 +0000 (16:08 +0200)
This solely manipulates the thread_info struct, it ought to be in
tinfo.h, not in thread.h.

include/haproxy/thread.h
include/haproxy/tinfo.h

index a06b93d5bc08d8517c24925440b2d5ac400631f4..b9625354dd152696c6e6b78d91459422e2514216 100644 (file)
@@ -95,11 +95,6 @@ static inline void ha_set_tid(unsigned int tid)
        ti = &ha_thread_info[tid];
 }
 
-static inline unsigned long long ha_get_pthread_id(unsigned int thr)
-{
-       return 0;
-}
-
 static inline void ha_thread_relax(void)
 {
 #ifdef _POSIX_PRIORITY_SCHEDULING
@@ -219,37 +214,6 @@ static inline void ha_set_tid(unsigned int data)
        ti      = &ha_thread_info[tid];
 }
 
-/* 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)
-{
-       union {
-               pthread_t t;
-               unsigned long long ll;
-               unsigned int i;
-               unsigned short s;
-               unsigned char c;
-       } u;
-
-       memset(&u, 0, sizeof(u));
-       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;
-}
-
 static inline void ha_thread_relax(void)
 {
 #ifdef _POSIX_PRIORITY_SCHEDULING
index be6cddf171fb9dd04bfe050f110ce38bc9cd6898..40b64b0e83ce0685d87d475f3e63fbdbb6ad23c1 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 */