From 215efd60900f28bb543ffab400306fbd01a4f76c Mon Sep 17 00:00:00 2001 From: sigsegv7 Date: Thu, 28 Sep 2023 15:36:22 -0400 Subject: kernel: cdefs: Add memory barrier helper Signed-off-by: sigsegv7 --- sys/include/sys/cdefs.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/sys/include/sys/cdefs.h b/sys/include/sys/cdefs.h index 56d1f87..bec4431 100644 --- a/sys/include/sys/cdefs.h +++ b/sys/include/sys/cdefs.h @@ -38,6 +38,9 @@ #define __used __attr(used) #define __naked __attr(naked) +/* Wrapper for inline asm */ +#define __ASMV __asm__ __volatile__ + /* Pack a structure */ #define __packed __attribute__((__packed__)) @@ -53,6 +56,12 @@ */ #define __cacheline_aligned __aligned(64) +/* + * Memory barrier, ensure compiler doesn't reorder + * memory accesses. + */ +#define __mem_barrier() __ASMV("" ::: "memory") + /* * To be used when an empty body is required like: * @@ -106,9 +115,6 @@ /* Computes 2^x i.e 2 to the power of 'x' */ #define __POW2(x) (1ULL << x) -/* Wrapper for inline asm */ -#define __ASMV __asm__ __volatile__ - /* * Used to give metadata to * a specific module. Example -- cgit v1.2.3