xref: /openbsd/share/man/man9/atomic_cas_uint.9 (revision f6aab3d8)
1.\" $OpenBSD: atomic_cas_uint.9,v 1.7 2019/02/06 01:35:07 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 6 2019 $
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.Fo atomic_cas_uint
30.Fa "volatile unsigned int *p"
31.Fa "unsigned int expected"
32.Fa "unsigned int new"
33.Fc
34.Ft unsigned long
35.Fo atomic_cas_ulong
36.Fa "volatile unsigned long *p"
37.Fa "unsigned long expected"
38.Fa "unsigned long new"
39.Fc
40.Ft void *
41.Fo atomic_cas_ptr
42.Fa "volatile void *p"
43.Fa "void *expected"
44.Fa "void *new"
45.Fc
46.Sh DESCRIPTION
47The atomic_cas set of functions provide an interface for atomically
48performing compare-and-swap operations with respect to interrupts
49and multiple processors in the system.
50.Pp
51The value referenced by the pointer
52.Fa p
53is compared against
54.Fa expected .
55If these values are equal then
56.Fa new
57replaces the value stored at
58.Fa p .
59.Sh CONTEXT
60.Fn atomic_cas_uint ,
61.Fn atomic_cas_ulong ,
62and
63.Fn atomic_cas_ptr
64can all be called during autoconf, from process context, or from
65interrupt context.
66.Sh RETURN VALUES
67These functions return the value at
68.Fa p
69as it was before the attempt to swap it.
70.Sh SEE ALSO
71.Xr atomic_swap_uint 9
72.Sh HISTORY
73The atomic_cas functions first appeared in
74.Nx 5.0
75and
76.Ox 5.5 .
77