diff options
author | jhb <jhb@FreeBSD.org> | 2005-09-27 17:39:11 +0000 |
---|---|---|
committer | jhb <jhb@FreeBSD.org> | 2005-09-27 17:39:11 +0000 |
commit | 89caa56972d968272278a67fe10affb38d9e88eb (patch) | |
tree | 368df1c62ea6aa397797927efbf9c7ccc4b3b92e /sys/powerpc/include | |
parent | aa790ae8700e7fed7ef83f2549c6bc53d6ae7f8f (diff) | |
download | FreeBSD-src-89caa56972d968272278a67fe10affb38d9e88eb.zip FreeBSD-src-89caa56972d968272278a67fe10affb38d9e88eb.tar.gz |
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
Diffstat (limited to 'sys/powerpc/include')
-rw-r--r-- | sys/powerpc/include/atomic.h | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/sys/powerpc/include/atomic.h b/sys/powerpc/include/atomic.h index 0bc8f21..9faa5bc 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_ */ |