- 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
This commit is contained in:
parent
89caa56972
commit
c95731aa8e
@ -352,6 +352,7 @@ MLINKS+=altq.9 ALTQ.9
|
|||||||
MLINKS+=atomic.9 atomic_add.9 \
|
MLINKS+=atomic.9 atomic_add.9 \
|
||||||
atomic.9 atomic_clear.9 \
|
atomic.9 atomic_clear.9 \
|
||||||
atomic.9 atomic_cmpset.9 \
|
atomic.9 atomic_cmpset.9 \
|
||||||
|
atomic.9 atomic_fetchadd.9 \
|
||||||
atomic.9 atomic_load.9 \
|
atomic.9 atomic_load.9 \
|
||||||
atomic.9 atomic_readandclear.9 \
|
atomic.9 atomic_readandclear.9 \
|
||||||
atomic.9 atomic_set.9 \
|
atomic.9 atomic_set.9 \
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
.Nm atomic_add ,
|
.Nm atomic_add ,
|
||||||
.Nm atomic_clear ,
|
.Nm atomic_clear ,
|
||||||
.Nm atomic_cmpset ,
|
.Nm atomic_cmpset ,
|
||||||
|
.Nm atomic_fetchadd ,
|
||||||
.Nm atomic_load ,
|
.Nm atomic_load ,
|
||||||
.Nm atomic_readandclear ,
|
.Nm atomic_readandclear ,
|
||||||
.Nm atomic_set ,
|
.Nm atomic_set ,
|
||||||
@ -50,6 +51,8 @@
|
|||||||
.Fa "<type> new"
|
.Fa "<type> new"
|
||||||
.Fc
|
.Fc
|
||||||
.Ft <type>
|
.Ft <type>
|
||||||
|
.Fn atomic_fetchadd_<type> "volatile <type> *p" "<type> v"
|
||||||
|
.Ft <type>
|
||||||
.Fn atomic_load_acq_<type> "volatile <type> *p"
|
.Fn atomic_load_acq_<type> "volatile <type> *p"
|
||||||
.Ft <type>
|
.Ft <type>
|
||||||
.Fn atomic_readandclear_<type> "volatile <type> *p"
|
.Fn atomic_readandclear_<type> "volatile <type> *p"
|
||||||
@ -197,6 +200,22 @@ functions are not implemented for the types
|
|||||||
and
|
and
|
||||||
.Dq Li 16 .
|
.Dq Li 16 .
|
||||||
.Bl -hang
|
.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
|
.It Fn atomic_load addr
|
||||||
.Bd -literal -compact
|
.Bd -literal -compact
|
||||||
return (*addr)
|
return (*addr)
|
||||||
@ -248,15 +267,19 @@ functions always have release semantics.
|
|||||||
The type
|
The type
|
||||||
.Dq Li 64
|
.Dq Li 64
|
||||||
is currently not implemented for any of the atomic operations on the
|
is currently not implemented for any of the atomic operations on the
|
||||||
.Tn i386
|
.Tn arm ,
|
||||||
architecture.
|
.Tn i386 ,
|
||||||
|
and
|
||||||
|
.Tn powerpc
|
||||||
|
architectures.
|
||||||
.Sh RETURN VALUES
|
.Sh RETURN VALUES
|
||||||
The
|
The
|
||||||
.Fn atomic_cmpset
|
.Fn atomic_cmpset
|
||||||
function
|
function
|
||||||
returns the result of the compare operation.
|
returns the result of the compare operation.
|
||||||
The
|
The
|
||||||
.Fn atomic_load
|
.Fn atomic_fetchadd ,
|
||||||
|
.Fn atomic_load ,
|
||||||
and
|
and
|
||||||
.Fn atomic_readandclear
|
.Fn atomic_readandclear
|
||||||
functions
|
functions
|
||||||
@ -275,14 +298,17 @@ is a pointer, the
|
|||||||
.Dq Li ptr
|
.Dq Li ptr
|
||||||
type is used.
|
type is used.
|
||||||
.Bd -literal
|
.Bd -literal
|
||||||
|
/* Try to obtain mtx_lock once. */
|
||||||
#define _obtain_lock(mp, tid) \\
|
#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. */
|
/* 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 (!_obtain_lock(mp, tid)) { \\
|
||||||
if (((mp)->mtx_lock & MTX_FLAGMASK) != ((uintptr_t)(tid)))\\
|
if (((mp)->mtx_lock & MTX_FLAGMASK) != _tid) \\
|
||||||
mtx_enter_hard(mp, (type) & MTX_HARDOPTS, 0); \\
|
_mtx_lock_sleep((mp), _tid, (opts), (file), (line));\\
|
||||||
else { \\
|
else { \\
|
||||||
atomic_set_ptr(&(mp)->mtx_lock, MTX_RECURSE); \\
|
atomic_set_ptr(&(mp)->mtx_lock, MTX_RECURSE); \\
|
||||||
(mp)->mtx_recurse++; \\
|
(mp)->mtx_recurse++; \\
|
||||||
@ -319,8 +345,12 @@ The types
|
|||||||
.Dq Li 32 ,
|
.Dq Li 32 ,
|
||||||
.Dq Li 64 ,
|
.Dq Li 64 ,
|
||||||
and
|
and
|
||||||
.Dq Li ptr ,
|
.Dq Li ptr
|
||||||
and all of the acquire and release variants
|
and all of the acquire and release variants
|
||||||
were added in
|
were added in
|
||||||
.Fx 5.0
|
.Fx 5.0
|
||||||
as well.
|
as well.
|
||||||
|
The
|
||||||
|
.Fn atomic_fetchadd
|
||||||
|
operations were added in
|
||||||
|
.Fx 6.0 .
|
||||||
|
Loading…
x
Reference in New Issue
Block a user