summaryrefslogtreecommitdiff
path: root/na/include
diff options
context:
space:
mode:
Diffstat (limited to 'na/include')
-rw-r--r--na/include/lume/compiler.h27
-rw-r--r--na/include/lume/rbtree.h5
-rw-r--r--na/include/lume/rbtree_augmented.h20
3 files changed, 28 insertions, 24 deletions
diff --git a/na/include/lume/compiler.h b/na/include/lume/compiler.h
new file mode 100644
index 0000000..fa05363
--- /dev/null
+++ b/na/include/lume/compiler.h
@@ -0,0 +1,27 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/* Copyright (C) 2026 Richard Qin */
+
+#pragma once
+
+/**
+ * compiler.h - Centralized management of compiler-specific macros and built-in wrappers.
+ */
+
+/* Memory barrier macros */
+#define WRITE_ONCE(x, val) \
+ do { \
+ __asm__ volatile("" ::: "memory"); \
+ (x) = (val); \
+ __asm__ volatile("" ::: "memory"); \
+ } while (0)
+
+#define READ_ONCE(x) (*(volatile __typeof__(x) *)&(x))
+
+#define barrier() __asm__ volatile("" ::: "memory")
+
+/* Branch prediction hints */
+#define unlikely(x) __builtin_expect(!!(x), 0)
+#define likely(x) __builtin_expect(!!(x), 1)
+
+/* Function attributes */
+#define __always_inline inline __attribute__((always_inline))
diff --git a/na/include/lume/rbtree.h b/na/include/lume/rbtree.h
index 331875c..8bc8104 100644
--- a/na/include/lume/rbtree.h
+++ b/na/include/lume/rbtree.h
@@ -8,6 +8,7 @@
#pragma once
+#include <lume/compiler.h>
#include <lume/rbtree_types.h>
/* ------------------------------------------------------------------ */
@@ -20,10 +21,6 @@
reinterpret_cast<char *>(ptr) - __builtin_offsetof(type, member))
#endif
-#ifndef READ_ONCE
-#define READ_ONCE(x) (*(volatile __typeof__(x) *)&(x))
-#endif
-
/* ------------------------------------------------------------------ */
/* Core macros */
/* ------------------------------------------------------------------ */
diff --git a/na/include/lume/rbtree_augmented.h b/na/include/lume/rbtree_augmented.h
index 07f367b..d4559c4 100644
--- a/na/include/lume/rbtree_augmented.h
+++ b/na/include/lume/rbtree_augmented.h
@@ -13,26 +13,6 @@
#include <lume/rbtree.h>
/* ------------------------------------------------------------------ */
-/* Linux-compat macros for freestanding kernel */
-/* ------------------------------------------------------------------ */
-
-#ifndef WRITE_ONCE
-#define WRITE_ONCE(x, val) do { \
- __asm__ volatile("" ::: "memory"); \
- (x) = (val); \
- __asm__ volatile("" ::: "memory"); \
-} while (0)
-#endif
-
-#ifndef unlikely
-#define unlikely(x) __builtin_expect(!!(x), 0)
-#endif
-
-#ifndef __always_inline
-#define __always_inline inline __attribute__((always_inline))
-#endif
-
-/* ------------------------------------------------------------------ */
/* Augmented callback structure */
/* ------------------------------------------------------------------ */