diff options
Diffstat (limited to 'src/compat')
-rw-r--r-- | src/compat/atomic/atomic.h | 22 | ||||
-rw-r--r-- | src/compat/compat.h | 5 |
2 files changed, 27 insertions, 0 deletions
diff --git a/src/compat/atomic/atomic.h b/src/compat/atomic/atomic.h new file mode 100644 index 0000000..c8c1c90 --- /dev/null +++ b/src/compat/atomic/atomic.h @@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef atomic_try_cmpxchg + +#define __atomic_try_cmpxchg(type, _p, _po, _n) \ +({ \ + typeof(_po) __po = (_po); \ + typeof(*(_po)) __o = *__po; \ + *__po = atomic_cmpxchg##type((_p), __o, (_n)); \ + (*__po == __o); \ +}) + +#define atomic_try_cmpxchg(_p, _po, _n) __atomic_try_cmpxchg(, _p, _po, _n) +#define atomic_try_cmpxchg_relaxed(_p, _po, _n) __atomic_try_cmpxchg(_relaxed, _p, _po, _n) +#define atomic_try_cmpxchg_acquire(_p, _po, _n) __atomic_try_cmpxchg(_acquire, _p, _po, _n) +#define atomic_try_cmpxchg_release(_p, _po, _n) __atomic_try_cmpxchg(_release, _p, _po, _n) + +#else /* atomic_try_cmpxchg */ +#define atomic_try_cmpxchg_relaxed atomic_try_cmpxchg +#define atomic_try_cmpxchg_acquire atomic_try_cmpxchg +#define atomic_try_cmpxchg_release atomic_try_cmpxchg +#endif /* atomic_try_cmpxchg */ diff --git a/src/compat/compat.h b/src/compat/compat.h index 2853c09..5affedf 100644 --- a/src/compat/compat.h +++ b/src/compat/compat.h @@ -591,6 +591,11 @@ static inline void *skb_put_data(struct sk_buff *skb, const void *data, unsigned } #endif +#include <linux/atomic.h> +#if !defined(atomic_try_cmpxchg) +#include "atomic/atomic.h" +#endif + /* https://lkml.org/lkml/2017/6/23/790 */ #if IS_ENABLED(CONFIG_NF_CONNTRACK) #include <linux/ip.h> |