Mesa (master): util/u_atomic: Fix the unlocked implementation.

Matt Turner mattst88 at kemper.freedesktop.org
Mon Dec 1 19:42:42 UTC 2014


Module: Mesa
Branch: master
Commit: a5299e9e1ca45f7bcf72347dc0fd47986d779769
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=a5299e9e1ca45f7bcf72347dc0fd47986d779769

Author: José Fonseca <jfonseca at vmware.com>
Date:   Tue Nov 25 14:25:28 2014 +0000

util/u_atomic: Fix the unlocked implementation.

It was totally broken:

- p_atomic_dec_zero() was returning the negation of the expected value

- p_atomic_inc_return()/p_atomic_dec_return() was
  post-incrementing/decrementing, hence returning the old value instead
  of the new

- p_atomic_cmpxchg() was returning the new value on success, instead of
  the old

It is clear this never used in the past. I wonder if it wouldn't be better to
yank it altogether.

Reviewed-by: Matt Turner <mattst88 at gmail.com>

---

 src/util/u_atomic.h |   12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/util/u_atomic.h b/src/util/u_atomic.h
index 5867a0f..56c5740 100644
--- a/src/util/u_atomic.h
+++ b/src/util/u_atomic.h
@@ -57,12 +57,12 @@
 
 #define p_atomic_set(_v, _i) (*(_v) = (_i))
 #define p_atomic_read(_v) (*(_v))
-#define p_atomic_dec_zero(_v) ((bool) --(*(_v)))
-#define p_atomic_inc(_v) ((void) (*(_v))++)
-#define p_atomic_dec(_v) ((void) (*(_v))--)
-#define p_atomic_inc_return(_v) ((*(_v))++)
-#define p_atomic_dec_return(_v) ((*(_v))--)
-#define p_atomic_cmpxchg(_v, old, _new) (*(_v) == old ? *(_v) = (_new) : *(_v))
+#define p_atomic_dec_zero(_v) (p_atomic_dec_return(_v) == 0)
+#define p_atomic_inc(_v) ((void) p_atomic_inc_return(_v))
+#define p_atomic_dec(_v) ((void) p_atomic_dec_return(_v))
+#define p_atomic_inc_return(_v) (++(*(_v)))
+#define p_atomic_dec_return(_v) (--(*(_v)))
+#define p_atomic_cmpxchg(_v, _old, _new) (*(_v) == (_old) ? (*(_v) = (_new), (_old)) : *(_v))
 
 #endif
 




More information about the mesa-commit mailing list