[Mesa-dev] [PATCH] util: Fix atomics
nobled
nobled at dreamwidth.org
Wed Aug 18 15:50:04 PDT 2010
1. Fix the single-threaded p_atomic_cmpxchg to return the
original value, not the current/new value.
2. Fix the single-threaded and Solaris implementations of
p_atomic_dec_zero to return true when the value reaches zero,
not the other way around. (Also edit the assembly-based ones
to be more clear that 'c' is basically a boolean.)
---
src/gallium/auxiliary/util/u_atomic.h | 19 ++++++++++++++-----
1 files changed, 14 insertions(+), 5 deletions(-)
diff --git a/src/gallium/auxiliary/util/u_atomic.h
b/src/gallium/auxiliary/util/u_atomic.h
index a156823..aa0c76e 100644
--- a/src/gallium/auxiliary/util/u_atomic.h
+++ b/src/gallium/auxiliary/util/u_atomic.h
@@ -56,7 +56,7 @@ p_atomic_dec_zero(int32_t *v)
__asm__ __volatile__("lock; decl %0; sete %1":"+m"(*v), "=qm"(c)
::"memory");
- return c != 0;
+ return !!c;
}
static INLINE void
@@ -139,10 +139,19 @@ p_atomic_cmpxchg(int32_t *v, int32_t old, int32_t _new)
#define p_atomic_set(_v, _i) (*(_v) = (_i))
#define p_atomic_read(_v) (*(_v))
-#define p_atomic_dec_zero(_v) ((boolean) --(*(_v)))
+#define p_atomic_dec_zero(_v) ((boolean) !(--(*(_v))) )
#define p_atomic_inc(_v) ((void) (*(_v))++)
#define p_atomic_dec(_v) ((void) (*(_v))--)
-#define p_atomic_cmpxchg(_v, old, _new) (*(_v) == old ? *(_v) = (_new) : *(_v))
+static INLINE int32_t
+p_atomic_cmpxchg(int32_t *v, int32_t old, int32_t _new)
+{
+ int32_t orig = *v;
+
+ if (*v == old)
+ *v = new;
+
+ return orig;
+}
#endif
@@ -171,7 +180,7 @@ p_atomic_dec_zero(int32_t *v)
sete byte ptr [c]
}
- return c != 0;
+ return !!c;
}
static INLINE void
@@ -280,7 +289,7 @@ p_atomic_dec_zero(int32_t *v)
{
uint32_t n = atomic_dec_32_nv((uint32_t *) v);
- return n != 0;
+ return n == 0;
}
#define p_atomic_inc(_v) atomic_inc_32((uint32_t *) _v)
--
1.5.4.3
More information about the mesa-dev
mailing list