1.\" $OpenBSD: atomic_cas_uint.9,v 1.5 2014/02/13 12:03:47 dlg Exp $ 2.\" 3.\" Copyright (c) 2014 David Gwynne <dlg@openbsd.org> 4.\" All rights reserved. 5.\" 6.\" Permission to use, copy, modify, and distribute this software for any 7.\" purpose with or without fee is hereby granted, provided that the above 8.\" copyright notice and this permission notice appear in all copies. 9.\" 10.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17.\" 18.Dd $Mdocdate: February 13 2014 $ 19.Dt ATOMIC_CAS_UINT 9 20.Os 21.Sh NAME 22.Nm atomic_cas_uint , 23.Nm atomic_cas_ulong , 24.Nm atomic_cas_ptr 25.Nd atomic compare-and-swap operations 26.Sh SYNOPSIS 27.In sys/atomic.h 28.Ft unsigned int 29.Fn atomic_cas_uint "volatile unsigned int *p" "unsigned int expected" "unsigned int new" 30.Ft unsigned long 31.Fn atomic_cas_ulong "volatile unsigned long *p" "unsigned long expected" "unsigned long new" 32.Ft void * 33.Fn atomic_cas_ptr "volatile void **p" "void *expected" "void *new" 34.Sh DESCRIPTION 35The atomic_cas set of functions provide an interface for atomically 36performing compare-and-swap operations with respect to interrupts 37and multiple processors in the system. 38.Pp 39The value referenced by the pointer 40.Fa p 41is compared against 42.Fa expected . 43If these values are equal then 44.Fa new 45replaces the value stored at 46.Fa p . 47.Sh CONTEXT 48.Fn atomic_cas_uint , 49.Fn atomic_cas_ulong , 50and 51.Fn atomic_cas_ptr 52can all be called during autoconf, from process context, or from interrupt context. 53.Sh RETURN VALUES 54These functions return the value at 55.Fa p 56as it was before the attempt to swap it. 57.Sh SEE ALSO 58.Xr atomic_swap_uint 9 59.Sh HISTORY 60The atomic_cas functions first appeared in 61.Nx 5.0 62and 63.Ox 5.5 . 64