mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-11-29 23:01:03 +01:00
CLEANUP: compiler: add a THREAD_ALIGNED macro and use it where appropriate
Sometimes we need to align a struct member or a struct's size only when threads are enabled. This is the case on fdtab for example. Instead of using ugly ifdefs in the code itself, let's have a THREAD_ALIGNED() macro performing the alignment only when threads are enabled. For now this was only applied to fd-t.h as it was the only place found.
This commit is contained in:
parent
920214e8c4
commit
8e3f5c6661
@ -173,6 +173,17 @@
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* sets alignment for current field or variable only when threads are enabled.
|
||||||
|
* Typically used to respect cache line alignment to avoid false sharing.
|
||||||
|
*/
|
||||||
|
#ifndef THREAD_ALIGNED
|
||||||
|
#ifdef USE_THREAD
|
||||||
|
#define THREAD_ALIGNED(x) __attribute__((aligned(x)))
|
||||||
|
#else
|
||||||
|
#define THREAD_ALIGNED(x)
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
/* add a mandatory alignment for next fields in a structure */
|
/* add a mandatory alignment for next fields in a structure */
|
||||||
#ifndef ALWAYS_ALIGN
|
#ifndef ALWAYS_ALIGN
|
||||||
#define ALWAYS_ALIGN(x) union { } ALIGNED(x)
|
#define ALWAYS_ALIGN(x) union { } ALIGNED(x)
|
||||||
@ -200,4 +211,16 @@
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* add an optional alignment for next fields in a structure, only when threads
|
||||||
|
* are enabled. Typically used to respect cache line alignment to avoid false
|
||||||
|
* sharing.
|
||||||
|
*/
|
||||||
|
#ifndef THREAD_ALIGN
|
||||||
|
#ifdef USE_THREAD
|
||||||
|
#define THREAD_ALIGN(x) union { } ALIGNED(x)
|
||||||
|
#else
|
||||||
|
#define THREAD_ALIGN(x)
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* _HAPROXY_COMPILER_H */
|
#endif /* _HAPROXY_COMPILER_H */
|
||||||
|
|||||||
@ -114,7 +114,9 @@ struct fdlist {
|
|||||||
int last;
|
int last;
|
||||||
} ALIGNED(8);
|
} ALIGNED(8);
|
||||||
|
|
||||||
/* info about one given fd */
|
/* info about one given fd. Note: only align on cache lines when using threads;
|
||||||
|
* 32-bit small archs can put everything in 32-bytes when threads are disabled.
|
||||||
|
*/
|
||||||
struct fdtab {
|
struct fdtab {
|
||||||
unsigned long running_mask; /* mask of thread IDs currently using the fd */
|
unsigned long running_mask; /* mask of thread IDs currently using the fd */
|
||||||
unsigned long thread_mask; /* mask of thread IDs authorized to process the fd */
|
unsigned long thread_mask; /* mask of thread IDs authorized to process the fd */
|
||||||
@ -127,14 +129,7 @@ struct fdtab {
|
|||||||
unsigned char linger_risk:1; /* 1 if we must kill lingering before closing */
|
unsigned char linger_risk:1; /* 1 if we must kill lingering before closing */
|
||||||
unsigned char cloned:1; /* 1 if a cloned socket, requires EPOLL_CTL_DEL on close */
|
unsigned char cloned:1; /* 1 if a cloned socket, requires EPOLL_CTL_DEL on close */
|
||||||
unsigned char initialized:1; /* 1 if init phase was done on this fd (e.g. set non-blocking) */
|
unsigned char initialized:1; /* 1 if init phase was done on this fd (e.g. set non-blocking) */
|
||||||
}
|
} THREAD_ALIGNED(64);
|
||||||
#ifdef USE_THREAD
|
|
||||||
/* only align on cache lines when using threads; 32-bit small archs
|
|
||||||
* can put everything in 32-bytes when threads are disabled.
|
|
||||||
*/
|
|
||||||
ALIGNED(64)
|
|
||||||
#endif
|
|
||||||
;
|
|
||||||
|
|
||||||
/* polled mask, one bit per thread and per direction for each FD */
|
/* polled mask, one bit per thread and per direction for each FD */
|
||||||
struct polled_mask {
|
struct polled_mask {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user