mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-11-29 06:40:59 +01:00
REORG: thread: move ha_get_pthread_id() to thread.c
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.
This commit is contained in:
parent
d10385ac4b
commit
4eeb88363c
@ -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 */
|
#else /* !USE_THREAD */
|
||||||
|
|
||||||
/********************** THREADS ENABLED ************************/
|
/********************** THREADS ENABLED ************************/
|
||||||
@ -181,6 +186,7 @@ void ha_rwlock_init(HA_RWLOCK_T *l);
|
|||||||
void setup_extra_threads(void *(*handler)(void *));
|
void setup_extra_threads(void *(*handler)(void *));
|
||||||
void wait_for_threads_completion();
|
void wait_for_threads_completion();
|
||||||
void set_thread_cpu_affinity();
|
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 all_threads_mask;
|
||||||
extern volatile unsigned long threads_harmless_mask;
|
extern volatile unsigned long threads_harmless_mask;
|
||||||
|
|||||||
@ -29,38 +29,4 @@
|
|||||||
extern struct thread_info ha_thread_info[MAX_THREADS];
|
extern struct thread_info ha_thread_info[MAX_THREADS];
|
||||||
extern THREAD_LOCAL struct thread_info *ti; /* thread_info for the current thread */
|
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 */
|
#endif /* _HAPROXY_TINFO_H */
|
||||||
|
|||||||
30
src/thread.c
30
src/thread.c
@ -254,6 +254,36 @@ void set_thread_cpu_affinity()
|
|||||||
#endif /* USE_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> */
|
/* send signal <sig> to thread <thr> */
|
||||||
void ha_tkill(unsigned int thr, int sig)
|
void ha_tkill(unsigned int thr, int sig)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user