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/ia64/include/atomic.h | |
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/ia64/include/atomic.h')
-rw-r--r-- | sys/ia64/include/atomic.h | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/sys/ia64/include/atomic.h b/sys/ia64/include/atomic.h index 1119079..f660180 100644 --- a/sys/ia64/include/atomic.h +++ b/sys/ia64/include/atomic.h @@ -342,4 +342,23 @@ atomic_readandclear_64(volatile uint64_t* p) #define atomic_readandclear_int atomic_readandclear_32 #define atomic_readandclear_long atomic_readandclear_64 +/* + * Atomically add the value of v to the integer pointed to by p and return + * the previous value of *p. + * + * XXX: Should we use the fetchadd instruction here? + */ +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_ */ |