mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2025-01-04 19:19:33 +00:00
MINOR: compiler: add new alignment macros
This commit adds ALWAYS_ALIGN(), MAYBE_ALIGN() and ATOMIC_ALIGN() to be placed as delimitors inside structures to force alignment to a given size. These depend on the architecture's capabilities so that it is possible to always align, align only on archs not supporting unaligned accesses at all, or only on those not supporting them for atomic accesses (e.g. before a lock).
This commit is contained in:
parent
7f26391bc5
commit
226ef26056
@ -144,4 +144,55 @@
|
||||
#define HA_HAVE_CAS_DW
|
||||
#endif
|
||||
|
||||
|
||||
/* sets alignment for current field or variable */
|
||||
#ifndef ALIGNED
|
||||
#define ALIGNED(x) __attribute__((aligned(x)))
|
||||
#endif
|
||||
|
||||
/* sets alignment only on architectures preventing unaligned atomic accesses */
|
||||
#ifndef MAYBE_ALIGNED
|
||||
#ifndef HA_UNALIGNED
|
||||
#define MAYBE_ALIGNED(x) ALIGNED(x)
|
||||
#else
|
||||
#define MAYBE_ALIGNED(x)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* sets alignment only on architectures preventing unaligned atomic accesses */
|
||||
#ifndef ATOMIC_ALIGNED
|
||||
#ifndef HA_UNALIGNED_ATOMIC
|
||||
#define ATOMIC_ALIGNED(x) ALIGNED(x)
|
||||
#else
|
||||
#define ATOMIC_ALIGNED(x)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* add a mandatory alignment for next fields in a structure */
|
||||
#ifndef ALWAYS_ALIGN
|
||||
#define ALWAYS_ALIGN(x) union { } ALIGNED(x)
|
||||
#endif
|
||||
|
||||
/* add an optional alignment for next fields in a structure, only for archs
|
||||
* which do not support unaligned accesses.
|
||||
*/
|
||||
#ifndef MAYBE_ALIGN
|
||||
#ifndef HA_UNALIGNED
|
||||
#define MAYBE_ALIGN(x) union { } ALIGNED(x)
|
||||
#else
|
||||
#define MAYBE_ALIGN(x)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* add an optional alignment for next fields in a structure, only for archs
|
||||
* which do not support unaligned accesses for atomic operations.
|
||||
*/
|
||||
#ifndef ATOMIC_ALIGN
|
||||
#ifndef HA_UNALIGNED_ATOMIC
|
||||
#define ATOMIC_ALIGN(x) union { } ALIGNED(x)
|
||||
#else
|
||||
#define ATOMIC_ALIGN(x)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif /* _COMMON_COMPILER_H */
|
||||
|
Loading…
Reference in New Issue
Block a user