Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/common/lib/libc/atomic Rework so that __sync_fetch_and_<OP>_...
details: https://anonhg.NetBSD.org/src/rev/acabc1024650
branches: trunk
changeset: 326372:acabc1024650
user: matt <matt%NetBSD.org@localhost>
date: Mon Jan 27 18:29:47 2014 +0000
description:
Rework so that __sync_fetch_and_<OP>_<N> actually returns a value.
diffstat:
common/lib/libc/atomic/atomic_add_32_cas.c | 16 ++++++++++++----
common/lib/libc/atomic/atomic_add_64_cas.c | 16 ++++++++++++----
common/lib/libc/atomic/atomic_and_32_cas.c | 16 ++++++++++++----
common/lib/libc/atomic/atomic_and_64_cas.c | 15 +++++++++++----
common/lib/libc/atomic/atomic_or_32_cas.c | 16 ++++++++++++----
common/lib/libc/atomic/atomic_or_64_cas.c | 14 +++++++++++---
6 files changed, 70 insertions(+), 23 deletions(-)
diffs (245 lines):
diff -r 02aba145ba9a -r acabc1024650 common/lib/libc/atomic/atomic_add_32_cas.c
--- a/common/lib/libc/atomic/atomic_add_32_cas.c Mon Jan 27 18:12:57 2014 +0000
+++ b/common/lib/libc/atomic/atomic_add_32_cas.c Mon Jan 27 18:29:47 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: atomic_add_32_cas.c,v 1.5 2014/01/27 18:08:37 matt Exp $ */
+/* $NetBSD: atomic_add_32_cas.c,v 1.6 2014/01/27 18:29:47 matt Exp $ */
/*-
* Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -33,8 +33,10 @@
#include <sys/atomic.h>
-void
-atomic_add_32(volatile uint32_t *addr, int32_t val)
+uint32_t __sync_fetch_and_add_4(volatile uint32_t *, int32_t);
+
+uint32_t
+__sync_fetch_and_add_4(volatile uint32_t *addr, int32_t val)
{
uint32_t old, new;
@@ -42,6 +44,13 @@
old = *addr;
new = old + val;
} while (atomic_cas_32(addr, old, new) != old);
+ return old;
+}
+
+void
+atomic_add_32(volatile uint32_t *addr, int32_t val)
+{
+ (void) __sync_fetch_and_add_4(addr, val);
}
#undef atomic_add_32
@@ -50,7 +59,6 @@
#undef atomic_add_int
atomic_op_alias(atomic_add_int,_atomic_add_32)
__strong_alias(_atomic_add_int,_atomic_add_32)
-__strong_alias(__sync_fetch_and_add_4,_atomic_add_32)
#if !defined(_LP64)
#undef atomic_add_long
diff -r 02aba145ba9a -r acabc1024650 common/lib/libc/atomic/atomic_add_64_cas.c
--- a/common/lib/libc/atomic/atomic_add_64_cas.c Mon Jan 27 18:12:57 2014 +0000
+++ b/common/lib/libc/atomic/atomic_add_64_cas.c Mon Jan 27 18:29:47 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: atomic_add_64_cas.c,v 1.6 2014/01/27 18:09:51 matt Exp $ */
+/* $NetBSD: atomic_add_64_cas.c,v 1.7 2014/01/27 18:29:47 matt Exp $ */
/*-
* Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -35,8 +35,10 @@
#ifdef __HAVE_ATOMIC64_OPS
-void
-atomic_add_64(volatile uint64_t *addr, int64_t val)
+uint64_t __sync_fetch_and_add_8(volatile uint64_t *, int64_t);
+
+uint64_t
+__sync_fetch_and_add_8(volatile uint64_t *addr, int64_t val)
{
uint64_t old, new;
@@ -44,11 +46,17 @@
old = *addr;
new = old + val;
} while (atomic_cas_64(addr, old, new) != old);
+ return old;
+}
+
+void
+atomic_add_64(volatile uint64_t *addr, int64_t val)
+{
+ (void) __sync_fetch_and_add_8(addr, val);
}
#undef atomic_add_64
atomic_op_alias(atomic_add_64,_atomic_add_64)
-__strong_alias(__sync_fetch_and_add_8,_atomic_add_64)
#if defined(_LP64)
#undef atomic_add_long
diff -r 02aba145ba9a -r acabc1024650 common/lib/libc/atomic/atomic_and_32_cas.c
--- a/common/lib/libc/atomic/atomic_and_32_cas.c Mon Jan 27 18:12:57 2014 +0000
+++ b/common/lib/libc/atomic/atomic_and_32_cas.c Mon Jan 27 18:29:47 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: atomic_and_32_cas.c,v 1.5 2014/01/27 18:12:57 matt Exp $ */
+/* $NetBSD: atomic_and_32_cas.c,v 1.6 2014/01/27 18:29:47 matt Exp $ */
/*-
* Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -33,8 +33,10 @@
#include <sys/atomic.h>
-void
-atomic_and_32(volatile uint32_t *addr, uint32_t val)
+uint32_t atomic_and_32(volatile uint32_t *, uint32_t);
+
+uint32_t
+__sync_fetch_and_and_4(volatile uint32_t *addr, uint32_t val)
{
uint32_t old, new;
@@ -42,11 +44,17 @@
old = *addr;
new = old & val;
} while (atomic_cas_32(addr, old, new) != old);
+ return old;
+}
+
+void
+atomic_and_32(volatile uint32_t *addr, uint32_t val)
+{
+ (void) __sync_fetch_and_and_4(addr, val);
}
#undef atomic_and_32
atomic_op_alias(atomic_and_32,_atomic_and_32)
-__strong_alias(__sync_fetch_and_and_4,_atomic_and_32)
#undef atomic_and_uint
atomic_op_alias(atomic_and_uint,_atomic_and_32)
diff -r 02aba145ba9a -r acabc1024650 common/lib/libc/atomic/atomic_and_64_cas.c
--- a/common/lib/libc/atomic/atomic_and_64_cas.c Mon Jan 27 18:12:57 2014 +0000
+++ b/common/lib/libc/atomic/atomic_and_64_cas.c Mon Jan 27 18:29:47 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: atomic_and_64_cas.c,v 1.6 2014/01/27 18:12:57 matt Exp $ */
+/* $NetBSD: atomic_and_64_cas.c,v 1.7 2014/01/27 18:29:47 matt Exp $ */
/*-
* Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -35,8 +35,10 @@
#ifdef __HAVE_ATOMIC64_OPS
-void
-atomic_and_64(volatile uint64_t *addr, uint64_t val)
+uint64_t __sync_fetch_and_and_8(volatile uint64_t *, uint64_t);
+
+uint64_t
+__sync_fetch_and_and_8(volatile uint64_t *addr, uint64_t val)
{
uint64_t old, new;
@@ -46,9 +48,14 @@
} while (atomic_cas_64(addr, old, new) != old);
}
+void
+atomic_and_64(volatile uint64_t *addr, uint64_t val)
+{
+ (void) __sync_fetch_and_and_8(addr, val);
+}
+
#undef atomic_and_64
atomic_op_alias(atomic_and_64,_atomic_and_64)
-__strong_alias(__sync_fetch_and_and_8,_atomic_and_64)
#if defined(_LP64)
#undef atomic_and_ulong
diff -r 02aba145ba9a -r acabc1024650 common/lib/libc/atomic/atomic_or_32_cas.c
--- a/common/lib/libc/atomic/atomic_or_32_cas.c Mon Jan 27 18:12:57 2014 +0000
+++ b/common/lib/libc/atomic/atomic_or_32_cas.c Mon Jan 27 18:29:47 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: atomic_or_32_cas.c,v 1.5 2014/01/27 18:12:57 matt Exp $ */
+/* $NetBSD: atomic_or_32_cas.c,v 1.6 2014/01/27 18:29:47 matt Exp $ */
/*-
* Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -33,8 +33,10 @@
#include <sys/atomic.h>
-void
-atomic_or_32(volatile uint32_t *addr, uint32_t val)
+uint32_t __sync_fetch_and_or_4(volatile uint32_t *, uint32_t);
+
+uint32_t
+__sync_fetch_and_or_4(volatile uint32_t *addr, uint32_t val)
{
uint32_t old, new;
@@ -42,11 +44,17 @@
old = *addr;
new = old | val;
} while (atomic_cas_32(addr, old, new) != old);
+ return old;
+}
+
+void
+atomic_or_32(volatile uint32_t *addr, uint32_t val)
+{
+ (void) __sync_val_compare_and_swap_4(addr, val);
}
#undef atomic_or_32
atomic_op_alias(atomic_or_32,_atomic_or_32)
-__strong_alias(__sync_fetch_and_or_4,_atomic_or_32)
#undef atomic_or_uint
atomic_op_alias(atomic_or_uint,_atomic_or_32)
diff -r 02aba145ba9a -r acabc1024650 common/lib/libc/atomic/atomic_or_64_cas.c
--- a/common/lib/libc/atomic/atomic_or_64_cas.c Mon Jan 27 18:12:57 2014 +0000
+++ b/common/lib/libc/atomic/atomic_or_64_cas.c Mon Jan 27 18:29:47 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: atomic_or_64_cas.c,v 1.6 2014/01/27 18:12:57 matt Exp $ */
+/* $NetBSD: atomic_or_64_cas.c,v 1.7 2014/01/27 18:29:47 matt Exp $ */
/*-
* Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -35,8 +35,10 @@
#ifdef __HAVE_ATOMIC64_OPS
+uint64_t __sync_fetch_and_or_8(volatile uint64_t *addr, uint64_t val);
+
void
-atomic_or_64(volatile uint64_t *addr, uint64_t val)
+__sync_fetch_and_or_8(volatile uint64_t *addr, uint64_t val)
{
uint64_t old, new;
@@ -44,11 +46,17 @@
old = *addr;
new = old | val;
} while (atomic_cas_64(addr, old, new) != old);
+ return old;
+}
+
+void
+atomic_or_64(volatile uint64_t *addr, uint64_t val)
+{
+ (void) __sync_fetch_and_or_8(addr, val);
}
#undef atomic_or_64
atomic_op_alias(atomic_or_64,_atomic_or_64)
-__strong_alias(__sync_fetch_and_or_8,_atomic_or_64)
#if defined(_LP64)
#undef atomic_or_ulong
Home |
Main Index |
Thread Index |
Old Index