[sheepdog] [PATCH 1/2] util: change type of uatomic_bool from unsigned long to struct
Hitoshi Mitake
mitake.hitoshi at lab.ntt.co.jp
Tue Jan 29 06:51:05 CET 2013
uatomic_bool shouldn't be typedefed unsigned long. Because it allows
simple assignment statements whose left expression is uatomic_bool
typed. This would cause subtle bugs.
This patch makes uatomic_bool as a typedefed struct. This forbid
illegal direct assignments to uatomic_bool variables.
Signed-off-by: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>
---
include/util.h | 8 ++++----
1 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/include/util.h b/include/util.h
index 109af06..0a89985 100644
--- a/include/util.h
+++ b/include/util.h
@@ -107,23 +107,23 @@ void untrim_zero_sectors(void *buf, uint64_t offset, uint32_t len,
/* urcu helpers */
/* Boolean data type which can be accessed by multiple threads */
-typedef unsigned long uatomic_bool;
+typedef struct { unsigned long val; } uatomic_bool;
static inline bool uatomic_is_true(uatomic_bool *val)
{
- return uatomic_read(val) == 1;
+ return uatomic_read(&val->val) == 1;
}
/* success if the old value is false */
static inline bool uatomic_set_true(uatomic_bool *val)
{
- return uatomic_cmpxchg(val, 0, 1) == 0;
+ return uatomic_cmpxchg(&val->val, 0, 1) == 0;
}
static inline void uatomic_set_false(uatomic_bool *val)
{
assert(uatomic_is_true(val));
- uatomic_set(val, 0);
+ uatomic_set(&val->val, 0);
}
#endif
--
1.7.2.5
More information about the sheepdog
mailing list