summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Kettenis <kettenis@cvs.openbsd.org>2016-04-05 08:17:35 +0000
committerMark Kettenis <kettenis@cvs.openbsd.org>2016-04-05 08:17:35 +0000
commite67c399afdd802486451827f8676be7f18808ebd (patch)
tree87b2bdf1ba036a8f3e49a45ebfa21402ddd01304
parent414172fb114453ef706c1255823f110a40a8fe6c (diff)
Add atomic_add_unless(), another strange linux interface.
ok jsg@
-rw-r--r--sys/dev/pci/drm/drm_atomic.h16
1 files changed, 15 insertions, 1 deletions
diff --git a/sys/dev/pci/drm/drm_atomic.h b/sys/dev/pci/drm/drm_atomic.h
index 5c3bdfbb00f..ef924ffcd8c 100644
--- a/sys/dev/pci/drm/drm_atomic.h
+++ b/sys/dev/pci/drm/drm_atomic.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: drm_atomic.h,v 1.13 2015/09/23 23:12:11 kettenis Exp $ */
+/* $OpenBSD: drm_atomic.h,v 1.14 2016/04/05 08:17:34 kettenis Exp $ */
/**
* \file drm_atomic.h
* Atomic operations used in the DRM which may or may not be provided by the OS.
@@ -54,6 +54,20 @@ atomic_xchg(volatile int *v, int n)
return __sync_lock_test_and_set(v, n);
}
+static __inline int
+atomic_add_unless(volatile int *v, int n, int u)
+{
+ int o = *v;
+
+ do {
+ o = *v;
+ if (o == u)
+ return 0;
+ } while (__sync_val_compare_and_swap(v, o, o +n) != o);
+
+ return 1;
+}
+
#ifdef __LP64__
typedef uint64_t atomic64_t;