Support atomic printks
[akaros.git] / kern / include / ros / common.h
index f130e9b..7bf4958 100644 (file)
@@ -120,10 +120,6 @@ static inline bool mult_will_overflow_u64(uint64_t a, uint64_t b)
        (type*)((char*)ptr - offsetof(type, member));                             \
 })
 
-/* Force the reading exactly once of x.  You may still need mbs().  See
- * http://lwn.net/Articles/508991/ for more info. */
-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
-
 /* Makes sure func is run exactly once.  Can handle concurrent callers, and
  * other callers spin til the func is complete. */
 #define run_once(func)                                                         \
@@ -155,16 +151,14 @@ do {                                                                           \
        }                                                                          \
 } while (0)
 
-/* Aborts with 'retcmd' if this function has already been called.  Compared to
- * run_once, this is put at the top of a function that can be called from
- * multiple sources but should only execute once. */
-#define init_once_racy(retcmd)                                                 \
-do {                                                                           \
-       static bool initialized = FALSE;                                           \
-       if (initialized) {                                                         \
-               retcmd;                                                                \
-       }                                                                          \
-       initialized = TRUE;                                                        \
-} while (0)
+#ifdef ROS_KERNEL
+#include <compiler.h>
+#else
+/* Force the reading/writing exactly once of x.  You may still need mbs().  See
+ * http://lwn.net/Articles/508991/ for more info. */
+#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
+#define READ_ONCE(x) ACCESS_ONCE(x)
+#define WRITE_ONCE(x, val) ((*(volatile typeof(x) *)&(x)) = val)
+#endif
 
 #endif /* __ASSEMBLER__ */