From 4ea211a4f4417ce2d860dae6f3dee5601eba2e62 Mon Sep 17 00:00:00 2001 From: John Baldwin Date: Tue, 27 Sep 2005 17:59:29 +0000 Subject: [PATCH] - 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 --- share/man/man9/Makefile | 1 + share/man/man9/atomic.9 | 46 ++++++++++++++++++++++++++++++++++------- 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/share/man/man9/Makefile b/share/man/man9/Makefile index 0afeb43d608a..f472d32a5d78 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 747b81d1eac3..49334325946c 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 " new" .Fc .Ft +.Fn atomic_fetchadd_ "volatile *p" " v" +.Ft .Fn atomic_load_acq_ "volatile *p" .Ft .Fn atomic_readandclear_ "volatile *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 .