summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sys/arch/sh/include/atomic.h83
1 files changed, 70 insertions, 13 deletions
diff --git a/sys/arch/sh/include/atomic.h b/sys/arch/sh/include/atomic.h
index 0b9afec6470..9fc2a83dc3f 100644
--- a/sys/arch/sh/include/atomic.h
+++ b/sys/arch/sh/include/atomic.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: atomic.h,v 1.7 2014/09/24 07:38:04 dlg Exp $ */
+/* $OpenBSD: atomic.h,v 1.8 2014/11/17 23:51:32 dlg Exp $ */
/* Public Domain */
@@ -27,7 +27,7 @@ __atomic_leave(unsigned int sr)
}
static inline unsigned int
-_atomic_cas_word(volatile unsigned int *uip, unsigned int o, unsigned int n)
+_atomic_cas_uint(volatile unsigned int *uip, unsigned int o, unsigned int n)
{
unsigned int sr;
unsigned int rv;
@@ -40,8 +40,23 @@ _atomic_cas_word(volatile unsigned int *uip, unsigned int o, unsigned int n)
return (rv);
}
-#define atomic_cas_uint(_p, _o, _n) _atomic_cas_word((_p), (_o), (_n))
-#define atomic_cas_ulong(_p, _o, _n) _atomic_cas_word((_p), (_o), (_n))
+#define atomic_cas_uint(_p, _o, _n) _atomic_cas_uint((_p), (_o), (_n))
+
+static inline unsigned long
+_atomic_cas_ulong(volatile unsigned long *uip, unsigned long o, unsigned long n)
+{
+ unsigned int sr;
+ unsigned long rv;
+
+ sr = __atomic_enter();
+ rv = *uip;
+ if (rv == o)
+ *uip = n;
+ __atomic_leave(sr);
+
+ return (rv);
+}
+#define atomic_cas_ulong(_p, _o, _n) _atomic_cas_ulong((_p), (_o), (_n))
static inline void *
_atomic_cas_ptr(volatile void *uip, void *o, void *n)
@@ -61,7 +76,7 @@ _atomic_cas_ptr(volatile void *uip, void *o, void *n)
#define atomic_cas_ptr(_p, _o, _n) _atomic_cas_ptr((_p), (_o), (_n))
static inline unsigned int
-_atomic_swap_word(volatile unsigned int *uip, unsigned int n)
+_atomic_swap_uint(volatile unsigned int *uip, unsigned int n)
{
unsigned int sr;
unsigned int rv;
@@ -73,8 +88,22 @@ _atomic_swap_word(volatile unsigned int *uip, unsigned int n)
return (rv);
}
-#define atomic_swap_uint(_p, _n) _atomic_swap_word((_p), (_n))
-#define atomic_swap_ulong(_p, _n) _atomic_swap_word((_p), (_n))
+#define atomic_swap_uint(_p, _n) _atomic_swap_uint((_p), (_n))
+
+static inline unsigned long
+_atomic_swap_ulong(volatile unsigned long *uip, unsigned long n)
+{
+ unsigned int sr;
+ unsigned long rv;
+
+ sr = __atomic_enter();
+ rv = *uip;
+ *uip = n;
+ __atomic_leave(sr);
+
+ return (rv);
+}
+#define atomic_swap_ulong(_p, _n) _atomic_swap_ulong((_p), (_n))
static inline void *
_atomic_swap_ptr(volatile void *uip, void *n)
@@ -93,7 +122,7 @@ _atomic_swap_ptr(volatile void *uip, void *n)
#define atomic_swap_ptr(_p, _n) _atomic_swap_ptr((_p), (_n))
static inline unsigned int
-_atomic_add_word_nv(volatile unsigned int *uip, unsigned int v)
+_atomic_add_int_nv(volatile unsigned int *uip, unsigned int v)
{
unsigned int sr;
unsigned int rv;
@@ -105,11 +134,25 @@ _atomic_add_word_nv(volatile unsigned int *uip, unsigned int v)
return (rv);
}
-#define atomic_add_int_nv(_p, _v) _atomic_add_word_nv((_p), (_v))
-#define atomic_add_long_nv(_p, _v) _atomic_add_word_nv((_p), (_v))
+#define atomic_add_int_nv(_p, _v) _atomic_add_int_nv((_p), (_v))
+
+static inline unsigned long
+_atomic_add_long_nv(volatile unsigned long *uip, unsigned long v)
+{
+ unsigned int sr;
+ unsigned long rv;
+
+ sr = __atomic_enter();
+ rv = *uip + v;
+ *uip = rv;
+ __atomic_leave(sr);
+
+ return (rv);
+}
+#define atomic_add_long_nv(_p, _v) _atomic_add_long_nv((_p), (_v))
static inline unsigned int
-_atomic_sub_word_nv(volatile unsigned int *uip, unsigned int v)
+_atomic_sub_int_nv(volatile unsigned int *uip, unsigned int v)
{
unsigned int sr;
unsigned int rv;
@@ -121,8 +164,22 @@ _atomic_sub_word_nv(volatile unsigned int *uip, unsigned int v)
return (rv);
}
-#define atomic_sub_int_nv(_p, _v) _atomic_sub_word_nv((_p), (_v))
-#define atomic_sub_long_nv(_p, _v) _atomic_sub_word_nv((_p), (_v))
+#define atomic_sub_int_nv(_p, _v) _atomic_sub_int_nv((_p), (_v))
+
+static inline unsigned long
+_atomic_sub_long_nv(volatile unsigned long *uip, unsigned long v)
+{
+ unsigned int sr;
+ unsigned long rv;
+
+ sr = __atomic_enter();
+ rv = *uip - v;
+ *uip = rv;
+ __atomic_leave(sr);
+
+ return (rv);
+}
+#define atomic_sub_long_nv(_p, _v) _atomic_sub_long_nv((_p), (_v))
static inline void
atomic_setbits_int(volatile unsigned int *uip, unsigned int v)