Make some macros correct when used within IF clauses without brackets
authorDavide Libenzi <dlibenzi@google.com>
Fri, 11 Dec 2015 20:02:25 +0000 (12:02 -0800)
committerBarret Rhoden <brho@cs.berkeley.edu>
Wed, 16 Dec 2015 21:27:06 +0000 (16:27 -0500)
Make some macros correct when used within IF clauses without brackets.

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

index 6e8613e..f55504c 100644 (file)
@@ -157,7 +157,7 @@ static inline bool mult_will_overflow_u64(uint64_t a, uint64_t b)
 /* Makes sure func is run exactly once.  Can handle concurrent callers, and
  * other callers spin til the func is complete. */
 #define run_once(func)                                                         \
-{                                                                              \
+do {                                                                           \
        static bool ran_once = FALSE;                                              \
        static atomic_t is_running = FALSE;                                        \
        if (!ran_once) {                                                           \
@@ -173,28 +173,28 @@ static inline bool mult_will_overflow_u64(uint64_t a, uint64_t b)
                                                                                \
                }                                                                      \
        }                                                                          \
-}
+} while (0)
 
 /* Unprotected, single-threaded version, makes sure func is run exactly once */
 #define run_once_racy(func)                                                    \
-{                                                                              \
+do {                                                                           \
        static bool ran_once = FALSE;                                              \
        if (!ran_once) {                                                           \
                func;                                                                  \
                ran_once = TRUE;                                                       \
        }                                                                          \
-}
+} 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__ */