[PATCH] Atomic swap and test-and-set

Konstantin Belousov kostikbel at gmail.com
Wed Jul 31 17:32:52 UTC 2013


On Tue, Jul 30, 2013 at 03:56:36PM -0400, Jung-uk Kim wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> The attached patch implements atomic_swap_<type>() and
> atomic_testandset_<type>() for x86.  <type> is int or long ATM.
> 
> The semantics of each operation (in atomic(9) style):
> 
> atomic_swap(p, v)
> 	r = *p;
> 	*p = v;
> 	return (r);
> 
> atomic_testandset(p, s)
> 	v = (<type>)1 << s % (sizeof(<type>) * NBBY);
> 	r = (*p & v) != 0;
> 	*p |= v;
> 	return (r);
> 
> Note atomic_readandclear_<type>() is now obsolete and implemented as a
> macro around atomic_swap_<type>() where the new value v is 0.
> 
> Please let me know if you have any objection.
I think that the atomic.diff is fine.

You did not documented swap and testandset, which would be good to have
in the manpage.

I think that constraints for all added inlines contradict the explicit
requirement in the gcc documentation, which states that rmw operands
should be specified using the 'same location' output operand for the
input operand (hopefully this can be parsed).  It just happens so that
for "m" compiler cannot do anything else then passing the address.

The problem is not specific to the new functions, it seems to be present
in other functions as well, e.g. cmpset.  This probably can be postponed.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 834 bytes
Desc: not available
URL: <http://lists.freebsd.org/pipermail/freebsd-arch/attachments/20130731/f6c55af0/attachment.sig>


More information about the freebsd-arch mailing list