xref: /minix3/lib/libc/atomic/atomic_swap.3 (revision 2fe8fb192fe7e8720e3e7a77f928da545e872a6a)
1.\"	$NetBSD: atomic_swap.3,v 1.1 2008/06/23 10:22:40 ad Exp $
2.\"
3.\" Copyright (c) 2007 The NetBSD Foundation, Inc.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to The NetBSD Foundation
7.\" by Jason R. Thorpe.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright
13.\" notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in the
16.\" documentation and/or other materials provided with the distribution.
17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28.\" POSSIBILITY OF SUCH DAMAGE.
29.\"
30.Dd April 11, 2007
31.Dt ATOMIC_SWAP 3
32.Os
33.Sh NAME
34.Nm atomic_swap ,
35.Nm atomic_swap_32 ,
36.Nm atomic_swap_uint ,
37.Nm atomic_swap_ulong ,
38.Nm atomic_swap_ptr ,
39.Nm atomic_swap_64
40.Nd atomic swap operations
41.\" .Sh LIBRARY
42.\" .Lb libc
43.Sh SYNOPSIS
44.In sys/atomic.h
45.Ft uint32_t
46.Fn atomic_swap_32 "volatile uint32_t *ptr" "uint32_t new"
47.Ft unsigned int
48.Fn atomic_swap_uint "volatile unsigned int *ptr" "unsigned int new"
49.Ft unsigned long
50.Fn atomic_swap_ulong "volatile unsigned long *ptr" "unsigned long new"
51.Ft void *
52.Fn atomic_swap_ptr "volatile void *ptr" "void *new"
53.Ft uint64_t
54.Fn atomic_swap_64 "volatile uint64_t *ptr" "uint64_t new"
55.Sh DESCRIPTION
56The
57.Nm atomic_swap
58family of functions perform a swap operation in an atomic fashion.
59The value of the variable referenced by
60.Fa ptr
61is replaced by
62.Fa new
63and the old value returned.
64.Pp
65The 64-bit variants of these functions are available only on platforms
66that can support atomic 64-bit memory access.
67Applications can check for the availability of 64-bit atomic memory
68operations by testing if the pre-processor macro
69.Dv __HAVE_ATOMIC64_OPS
70is defined.
71.Sh SEE ALSO
72.Xr atomic_ops 3
73.Sh HISTORY
74The
75.Nm atomic_swap
76functions first appeared in
77.Nx 5.0 .
78