aboutsummaryrefslogtreecommitdiff
path: root/sys/powerpc
diff options
context:
space:
mode:
authorJohn Baldwin <jhb@FreeBSD.org>2005-09-27 17:39:11 +0000
committerJohn Baldwin <jhb@FreeBSD.org>2005-09-27 17:39:11 +0000
commit3c2bc2bf26924c35cace669bf4163670112ffe50 (patch)
tree368df1c62ea6aa397797927efbf9c7ccc4b3b92e /sys/powerpc
parent732c9a17013204144a82c8de5c63d26f8d07bb5d (diff)
downloadsrc-3c2bc2bf26924c35cace669bf4163670112ffe50.tar.gz
src-3c2bc2bf26924c35cace669bf4163670112ffe50.zip
Add a new atomic_fetchadd() primitive that atomically adds a value to a
variable and returns the previous value of the variable. Tested on: i386, alpha, sparc64, arm (cognet) Reviewed by: arch@ Submitted by: cognet (arm) MFC after: 1 week
Notes
Notes: svn path=/head/; revision=150627
Diffstat (limited to 'sys/powerpc')
-rw-r--r--sys/powerpc/include/atomic.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/sys/powerpc/include/atomic.h b/sys/powerpc/include/atomic.h
index 0bc8f2176b2b..9faa5bc94611 100644
--- a/sys/powerpc/include/atomic.h
+++ b/sys/powerpc/include/atomic.h
@@ -444,4 +444,17 @@ atomic_cmpset_rel_32(volatile uint32_t *p, uint32_t cmpval, uint32_t newval)
#define atomic_cmpset_acq_ptr atomic_cmpset_acq_32
#define atomic_cmpset_rel_ptr atomic_cmpset_rel_32
+static __inline uint32_t
+atomic_fetchadd_32(volatile uint32_t *p, uint32_t v)
+{
+ uint32_t value;
+
+ do {
+ value = *p;
+ } while (!atomic_cmpset_32(p, value, value + v));
+ return (value);
+}
+
+#define atomic_fetchadd_int atomic_fetchadd_32
+
#endif /* ! _MACHINE_ATOMIC_H_ */