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