summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Gray <jsg@cvs.openbsd.org>2018-01-30 08:15:18 +0000
committerJonathan Gray <jsg@cvs.openbsd.org>2018-01-30 08:15:18 +0000
commit96fbb4463162856b2d8a588d02f536abad314d4f (patch)
tree8ef9aab02fdd7fbf4abd75c236ed16e5bb05680a
parent193a6cb38c49f3b9808a03e0280182d279aa29b0 (diff)
add atomic_cmpxchg()/atomic64_add()/atomic64_sub()
-rw-r--r--sys/dev/pci/drm/drm_linux_atomic.h22
1 files changed, 21 insertions, 1 deletions
diff --git a/sys/dev/pci/drm/drm_linux_atomic.h b/sys/dev/pci/drm/drm_linux_atomic.h
index 8f23b37b2f6..a82e95d1936 100644
--- a/sys/dev/pci/drm/drm_linux_atomic.h
+++ b/sys/dev/pci/drm/drm_linux_atomic.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: drm_linux_atomic.h,v 1.1 2017/07/01 16:14:10 kettenis Exp $ */
+/* $OpenBSD: drm_linux_atomic.h,v 1.2 2018/01/30 08:15:17 jsg Exp $ */
/**
* \file drm_atomic.h
* Atomic operations used in the DRM which may or may not be provided by the OS.
@@ -50,6 +50,7 @@ typedef uint32_t atomic_t;
#define atomic_dec_and_test(v) (atomic_dec_return(v) == 0)
#define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
#define atomic_or(n, p) atomic_setbits_int(p, n)
+#define atomic_cmpxchg(p, o, n) __sync_val_compare_and_swap(p, o, n)
static __inline int
atomic_xchg(volatile int *v, int n)
@@ -87,6 +88,9 @@ atomic64_xchg(volatile int64_t *v, int64_t n)
return __sync_lock_test_and_set(v, n);
}
+#define atomic64_add(n, p) __sync_fetch_and_add_8(p, n)
+#define atomic64_sub(n, p) __sync_fetch_and_sub_8(p, n)
+
#else
typedef struct {
@@ -125,6 +129,22 @@ atomic64_xchg(atomic64_t *v, int64_t n)
return val;
}
+
+static __inline void
+atomic64_add(int i, atomic64_t *v)
+{
+ mtx_enter(&v->lock);
+ v->val += i;
+ mtx_leave(&v->lock);
+}
+
+static __inline void
+atomic64_sub(int i, atomic64_t *v)
+{
+ mtx_enter(&v->lock);
+ v->val -= i;
+ mtx_leave(&v->lock);
+}
#endif
static inline int