Add READ_ONCE and WRITE_ONCE (XCC)
[akaros.git] / kern / include / ros / common.h
index f130e9b..bb23ca2 100644 (file)
@@ -120,9 +120,11 @@ 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
+/* 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)
 
 /* Makes sure func is run exactly once.  Can handle concurrent callers, and
  * other callers spin til the func is complete. */
@@ -155,16 +157,4 @@ 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)
-
 #endif /* __ASSEMBLER__ */