Implement run_once() without atomic_t (XCC)
authorBarret Rhoden <brho@cs.berkeley.edu>
Wed, 6 Jan 2016 15:01:59 +0000 (10:01 -0500)
committerBarret Rhoden <brho@cs.berkeley.edu>
Thu, 14 Jan 2016 21:04:46 +0000 (16:04 -0500)
Using the atomic_t created a dependency on an atomic header.  It's not a
huge deal, since most every place that uses run_once() was already
including the header, but it was a minor annoyance.

Reinstall your kernel headers.

Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
kern/include/ros/common.h

index f55504c..eda5dab 100644 (file)
@@ -159,9 +159,10 @@ static inline bool mult_will_overflow_u64(uint64_t a, uint64_t b)
 #define run_once(func)                                                         \
 do {                                                                           \
        static bool ran_once = FALSE;                                              \
-       static atomic_t is_running = FALSE;                                        \
+       static bool is_running = FALSE;                                            \
        if (!ran_once) {                                                           \
-               if (!atomic_swap(&is_running, TRUE)) {                                 \
+               /* fetch and set TRUE, without a header or test_and_set weirdness */   \
+               if (!__sync_fetch_and_or(&is_running, TRUE)) {                         \
                        /* we won the race and get to run the func */                      \
                        func;                                                              \
                        wmb();  /* don't let the ran_once write pass previous writes */    \
@@ -170,7 +171,6 @@ do {                                                                           \
                        /* someone else won, wait til they are done to break out */        \
                        while (!ran_once)                                                  \
                                cpu_relax();                                                   \
-                                                                               \
                }                                                                      \
        }                                                                          \
 } while (0)