mirror of
https://gitlab.freedesktop.org/mesa/drm.git
synced 2025-12-20 03:30:22 +01:00
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>
This commit is contained in:
parent
8c2ae16959
commit
63fc571863
1 changed files with 9 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue