diff --git a/include/haproxy/thread.h b/include/haproxy/thread.h index a06b93d5b..b9625354d 100644 --- a/include/haproxy/thread.h +++ b/include/haproxy/thread.h @@ -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 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 diff --git a/include/haproxy/tinfo.h b/include/haproxy/tinfo.h index be6cddf17..40b64b0e8 100644 --- a/include/haproxy/tinfo.h +++ b/include/haproxy/tinfo.h @@ -29,4 +29,38 @@ 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 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 */