summaryrefslogtreecommitdiffstats
path: root/share
diff options
context:
space:
mode:
authorjhb <jhb@FreeBSD.org>2005-09-27 17:59:29 +0000
committerjhb <jhb@FreeBSD.org>2005-09-27 17:59:29 +0000
commitc95731aa8e574871eaa6b7ddb9db434fab4f9c4d (patch)
treed7f68757b87d4608abfd449df9344dc200b83bc9 /share
parent89caa56972d968272278a67fe10affb38d9e88eb (diff)
downloadFreeBSD-src-c95731aa8e574871eaa6b7ddb9db434fab4f9c4d.zip
FreeBSD-src-c95731aa8e574871eaa6b7ddb9db434fab4f9c4d.tar.gz
- Document atomic_fetchadd(9) and add a MLINK.
- Add arm and ppc to the list of archs not supporting operations on 64-bit integers. - Update the sample code for acquiring a mutex to be more recent and to take into account the recent atomic_foo_ptr() changes. MFC after: 1 week
Diffstat (limited to 'share')
-rw-r--r--share/man/man9/Makefile1
-rw-r--r--share/man/man9/atomic.946
2 files changed, 39 insertions, 8 deletions
diff --git a/share/man/man9/Makefile b/share/man/man9/Makefile
index 0afeb43..f472d32 100644
--- a/share/man/man9/Makefile
+++ b/share/man/man9/Makefile
@@ -352,6 +352,7 @@ MLINKS+=altq.9 ALTQ.9
MLINKS+=atomic.9 atomic_add.9 \
atomic.9 atomic_clear.9 \
atomic.9 atomic_cmpset.9 \
+ atomic.9 atomic_fetchadd.9 \
atomic.9 atomic_load.9 \
atomic.9 atomic_readandclear.9 \
atomic.9 atomic_set.9 \
diff --git a/share/man/man9/atomic.9 b/share/man/man9/atomic.9
index 747b81d..4933432 100644
--- a/share/man/man9/atomic.9
+++ b/share/man/man9/atomic.9
@@ -30,6 +30,7 @@
.Nm atomic_add ,
.Nm atomic_clear ,
.Nm atomic_cmpset ,
+.Nm atomic_fetchadd ,
.Nm atomic_load ,
.Nm atomic_readandclear ,
.Nm atomic_set ,
@@ -50,6 +51,8 @@
.Fa "<type> new"
.Fc
.Ft <type>
+.Fn atomic_fetchadd_<type> "volatile <type> *p" "<type> v"
+.Ft <type>
.Fn atomic_load_acq_<type> "volatile <type> *p"
.Ft <type>
.Fn atomic_readandclear_<type> "volatile <type> *p"
@@ -197,6 +200,22 @@ functions are not implemented for the types
and
.Dq Li 16 .
.Bl -hang
+.It Fn atomic_fetchadd p v
+.Bd -literal -compact
+tmp = *p;
+*p += v;
+return tmp;
+.Ed
+.El
+.Pp
+The
+.Fn atomic_fetchadd
+functions are only implemented for the types
+.Dq Li int
+and
+.Dq Li 32
+and do not have any variants with memory barriers at this time.
+.Bl -hang
.It Fn atomic_load addr
.Bd -literal -compact
return (*addr)
@@ -248,15 +267,19 @@ functions always have release semantics.
The type
.Dq Li 64
is currently not implemented for any of the atomic operations on the
-.Tn i386
-architecture.
+.Tn arm ,
+.Tn i386 ,
+and
+.Tn powerpc
+architectures.
.Sh RETURN VALUES
The
.Fn atomic_cmpset
function
returns the result of the compare operation.
The
-.Fn atomic_load
+.Fn atomic_fetchadd ,
+.Fn atomic_load ,
and
.Fn atomic_readandclear
functions
@@ -275,14 +298,17 @@ is a pointer, the
.Dq Li ptr
type is used.
.Bd -literal
+/* Try to obtain mtx_lock once. */
#define _obtain_lock(mp, tid) \\
- atomic_cmpset_acq_ptr(&(mp)->mtx_lock, (void *)MTX_UNOWNED, (tid))
+ atomic_cmpset_acq_ptr(&(mp)->mtx_lock, MTX_UNOWNED, (tid))
/* Get a sleep lock, deal with recursion inline. */
-#define _getlock_sleep(mp, tid, type) do { \\
+#define _get_sleep_lock(mp, tid, opts, file, line) do { \\
+ uintptr_t _tid = (uintptr_t)(tid); \\
+ \\
if (!_obtain_lock(mp, tid)) { \\
- if (((mp)->mtx_lock & MTX_FLAGMASK) != ((uintptr_t)(tid)))\\
- mtx_enter_hard(mp, (type) & MTX_HARDOPTS, 0); \\
+ if (((mp)->mtx_lock & MTX_FLAGMASK) != _tid) \\
+ _mtx_lock_sleep((mp), _tid, (opts), (file), (line));\\
else { \\
atomic_set_ptr(&(mp)->mtx_lock, MTX_RECURSE); \\
(mp)->mtx_recurse++; \\
@@ -319,8 +345,12 @@ The types
.Dq Li 32 ,
.Dq Li 64 ,
and
-.Dq Li ptr ,
+.Dq Li ptr
and all of the acquire and release variants
were added in
.Fx 5.0
as well.
+The
+.Fn atomic_fetchadd
+operations were added in
+.Fx 6.0 .
OpenPOWER on IntegriCloud