git: 39da3678b1ce - main - linuxkpi: Add try_cmpxchg and atomic_try_cmpxchg
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 08 Aug 2022 14:04:20 UTC
The branch main has been updated by manu:
URL: https://cgit.FreeBSD.org/src/commit/?id=39da3678b1ce2d4fac300e022e544b1db5c117c0
commit 39da3678b1ce2d4fac300e022e544b1db5c117c0
Author: Emmanuel Vadot <manu@FreeBSD.org>
AuthorDate: 2022-07-27 07:41:04 +0000
Commit: Emmanuel Vadot <manu@FreeBSD.org>
CommitDate: 2022-08-08 13:22:35 +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
---
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)
{