[PATCH] Atomic swap and test-and-set

Jung-uk Kim jkim at FreeBSD.org
Tue Jul 30 19:58:02 UTC 2013


-----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.

Thanks!

Jung-uk Kim

* Note 1: This patch is also available from here.

http://people.freebsd.org/~jkim/atomic.diff

* Note 2: These atomic ops are useful for porting Linux drivers and it
may simplify diffs, e.g., drm2 for AMD GPUs project.  Currently, I am
using the following wrapper:

http://people.freebsd.org/~jkim/drm_atomic.h

A full patch against kms-radeon tree is here:

http://people.freebsd.org/~jkim/drm_atomic.diff
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.20 (FreeBSD)

iQEcBAEBAgAGBQJR+Bp0AAoJECXpabHZMqHOpIsIAMqEjNehGRe7q7B7CPC2cqdY
aEWiRlKXLa0K3Vi2f9asYFlbhIm+PstV8Juhw2ijT/P3i55xoQTc4DqP6H4ISUgK
pKM8TLAFJWlItf3o8HV/q7Tns/iaqb8cnB0D2jLUtheeM8UTXEim+XOSWILL+csR
zuXGDSDGC0vTxip00ocPUdtdG/Y5Sg/Eq+5CZYp58DSoEBDfuKhGJc3xrC6QrMGx
zwBkmAp5escfFkyE1WLI99tJevrQZpqJViD+66dDcLW56w4Aqpqib69sMMEs/meJ
KrwKRwt9+kgvwEFiDGXzDsjVfcTky9Cb8zn3jbBrGxtNxd4aHgCNY1xeG98kHaM=
=6LmO
-----END PGP SIGNATURE-----
-------------- next part --------------
A non-text attachment was scrubbed...
Name: atomic.diff
Type: text/x-patch
Size: 9747 bytes
Desc: not available
URL: <http://lists.freebsd.org/pipermail/freebsd-arch/attachments/20130730/10fe0742/attachment.bin>


More information about the freebsd-arch mailing list