linuxkpi: Add try_cmpxchg and atomic_try_cmpxchg

Needed by drm-kmod

Obtain from:	drm-kmod
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D36015
This commit is contained in:
Emmanuel Vadot 2022-07-27 09:41:04 +02:00
parent fa1f02baaf
commit 39da3678b1

View File

@ -268,6 +268,28 @@ atomic_cmpxchg(atomic_t *v, int old, int new)
__ret.val; \
})
#define try_cmpxchg(p, op, n) \
({ \
__typeof(p) __op = (__typeof((p)))(op); \
__typeof(*(p)) __o = *__op; \
__typeof(*(p)) __p = __sync_val_compare_and_swap((p), (__o), (n)); \
if (__p != __o) \
*__op = __p; \
(__p == __o); \
})
#define __atomic_try_cmpxchg(type, _p, _po, _n) \
({ \
__typeof(_po) __po = (_po); \
__typeof(*(_po)) __r, __o = *__po; \
__r = atomic_cmpxchg##type((_p), __o, (_n)); \
if (unlikely(__r != __o)) \
*__po = __r; \
likely(__r == __o); \
})
#define atomic_try_cmpxchg(_p, _po, _n) __atomic_try_cmpxchg(, _p, _po, _n)
static inline int
atomic_dec_if_positive(atomic_t *v)
{