git: 56557fd4c43a - stable/13 - linuxkpi: Add try_cmpxchg and atomic_try_cmpxchg
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 07 Sep 2022 15:10:11 UTC
The branch stable/13 has been updated by manu:
URL: https://cgit.FreeBSD.org/src/commit/?id=56557fd4c43a9fb25200f2afff7a557eb2028845
commit 56557fd4c43a9fb25200f2afff7a557eb2028845
Author: Emmanuel Vadot <manu@FreeBSD.org>
AuthorDate: 2022-07-27 07:41:04 +0000
Commit: Emmanuel Vadot <manu@FreeBSD.org>
CommitDate: 2022-09-07 15:09:03 +0000
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
(cherry picked from commit 39da3678b1ce2d4fac300e022e544b1db5c117c0)
---
sys/compat/linuxkpi/common/include/asm/atomic.h | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/sys/compat/linuxkpi/common/include/asm/atomic.h b/sys/compat/linuxkpi/common/include/asm/atomic.h
index 7c7a2c4d4b92..d7e5338c0356 100644
--- a/sys/compat/linuxkpi/common/include/asm/atomic.h
+++ b/sys/compat/linuxkpi/common/include/asm/atomic.h
@@ -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)
{