diff options
author | Lionel Landwerlin <lionel.g.landwerlin@intel.com> | 2014-09-12 13:48:35 +0100 |
---|---|---|
committer | Damien Lespiau <damien.lespiau@intel.com> | 2014-09-15 14:50:47 +0100 |
commit | 63fc571863aa646834004fae2a8aee1326b775dc (patch) | |
tree | fa81323735b903d95068a7491e472065916fd39b /xf86atomic.h | |
parent | 8c2ae1695913990cbe6c6a8aa294f354eba33bd0 (diff) | |
download | libdrm-63fc571863aa646834004fae2a8aee1326b775dc.tar.gz libdrm-63fc571863aa646834004fae2a8aee1326b775dc.tar.bz2 libdrm-63fc571863aa646834004fae2a8aee1326b775dc.zip |
atomic: add atomic_add_unless()
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: Damien Lespiau <damien.lespiau@intel.com>
Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Diffstat (limited to 'xf86atomic.h')
-rw-r--r-- | xf86atomic.h | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/xf86atomic.h b/xf86atomic.h index db2f6195..bc482c92 100644 --- a/xf86atomic.h +++ b/xf86atomic.h @@ -96,4 +96,13 @@ typedef struct { uint_t atomic; } atomic_t; #error libdrm requires atomic operations, please define them for your CPU/compiler. #endif +static inline int atomic_add_unless(atomic_t *v, int add, int unless) +{ + int c, old; + c = atomic_read(v); + while (c != unless && (old = atomic_cmpxchg(v, c, c + add)) != c) + c = old; + return c == unless; +} + #endif |