]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - include/linux/atomic.h
New upstream release
[bcachefs-tools-debian] / include / linux / atomic.h
index a9852fa1f99a3370f0baa1c489dada515e1402a2..f4d047c1505e207049956ba63511b8a7be0681f0 100644 (file)
@@ -32,6 +32,8 @@ typedef struct {
 #define __ATOMIC_SUB(v, p)             uatomic_sub(p, v)
 #define __ATOMIC_INC(p)                        uatomic_inc(p)
 #define __ATOMIC_DEC(p)                        uatomic_dec(p)
+#define __ATOMIC_AND(v, p)             uatomic_and(p, v)
+#define __ATOMIC_OR(v, p)              uatomic_or(p, v)
 
 #define xchg(p, v)                     uatomic_xchg(p, v)
 #define xchg_acquire(p, v)             uatomic_xchg(p, v)
@@ -56,6 +58,8 @@ typedef struct {
 #define __ATOMIC_SUB_RETURN(v, p)      __atomic_sub_fetch(p, v, __ATOMIC_RELAXED)
 #define __ATOMIC_SUB_RETURN_RELEASE(v, p)                              \
                                        __atomic_sub_fetch(p, v, __ATOMIC_RELEASE)
+#define __ATOMIC_AND(p)                        __atomic_and_fetch(p, v, __ATOMIC_RELAXED)
+#define __ATOMIC_OR(p)                 __atomic_or_fetch(p, v, __ATOMIC_RELAXED)
 
 #define xchg(p, v)                     __atomic_exchange_n(p, v, __ATOMIC_SEQ_CST)
 #define xchg_acquire(p, v)             __atomic_exchange_n(p, v, __ATOMIC_ACQUIRE)
@@ -244,6 +248,16 @@ static inline bool a_type##_inc_not_zero(a_type##_t *v)                    \
        return a_type##_add_unless(v, 1, 0);                            \
 }                                                                      \
                                                                        \
+static inline void a_type##_and(i_type a, a_type##_t *v)               \
+{                                                                      \
+       __ATOMIC_AND(a, v);                                             \
+}                                                                      \
+                                                                       \
+static inline void a_type##_or(i_type a, a_type##_t *v)                        \
+{                                                                      \
+       __ATOMIC_OR(a, v);                                              \
+}                                                                      \
+                                                                       \
 static inline i_type a_type##_xchg(a_type##_t *v, i_type i)            \
 {                                                                      \
        return xchg(&v->counter, i);                                    \
@@ -257,6 +271,13 @@ static inline i_type a_type##_cmpxchg(a_type##_t *v, i_type old, i_type new)\
 static inline i_type a_type##_cmpxchg_acquire(a_type##_t *v, i_type old, i_type new)\
 {                                                                      \
        return cmpxchg_acquire(&v->counter, old, new);                  \
+}                                                                      \
+                                                                       \
+static inline bool a_type##_try_cmpxchg_acquire(a_type##_t *v, i_type *old, i_type new)\
+{                                                                      \
+       i_type prev = *old;                                             \
+       *old = cmpxchg_acquire(&v->counter, *old, new);                 \
+       return prev == *old;                                            \
 }
 
 DEF_ATOMIC_OPS(atomic,         int)