1.\" $OpenBSD: membar_sync.9,v 1.4 2022/03/13 22:16:59 bluhm Exp $ 2.\" 3.\" Copyright (c) 2007, 2008 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 $Mdocdate: March 13 2022 $ 31.Dt MEMBAR 9 32.Os 33.Sh NAME 34.Nm membar_enter , 35.Nm membar_exit , 36.Nm membar_producer , 37.Nm membar_consumer , 38.Nm membar_sync , 39.Nm membar_enter_after_atomic , 40.Nm membar_exit_before_atomic 41.Nd memory access barrier operations 42.Sh SYNOPSIS 43.In sys/atomic.h 44.Ft void 45.Fn membar_enter "void" 46.Ft void 47.Fn membar_exit "void" 48.Ft void 49.Fn membar_producer "void" 50.Ft void 51.Fn membar_consumer "void" 52.Ft void 53.Fn membar_sync "void" 54.Ft void 55.Fn membar_enter_after_atomic "void" 56.Ft void 57.Fn membar_exit_before_atomic "void" 58.Sh DESCRIPTION 59The membar set of functions provide an interface for issuing memory barrier 60access operations with respect to multiple processors in the system. 61.Bl -tag -width "mem" 62.It Fn membar_enter 63Any store preceding 64.Fn membar_enter 65will reach global visibility before all loads and stores following it. 66.Pp 67.Fn membar_enter 68is typically used in code that implements locking primitives to ensure 69that a lock protects its data. 70.It Fn membar_exit 71All loads and stores preceding 72.Fn membar_exit 73will reach global visibility before any store that follows it. 74.Pp 75.Fn membar_exit 76is typically used in code that implements locking primitives to ensure 77that a lock protects its data. 78.It Fn membar_producer 79All stores preceding the memory barrier will reach global visibility 80before any stores after the memory barrier reach global visibility. 81.It Fn membar_consumer 82All loads preceding the memory barrier will complete before any loads 83after the memory barrier complete. 84.It Fn membar_sync 85All loads and stores preceding the memory barrier will complete and 86reach global visibility before any loads and stores after the memory 87barrier complete and reach global visibility. 88.It Fn membar_enter_after_atomic 89An atomic operation preceding 90.Fn membar_enter_after_atomic 91will reach global visibility before all loads and stores following it. 92The atomic operation is used to protect the start of a critical section. 93.It Fn membar_exit_before_atomic 94All loads and stores preceding 95.Fn membar_exit_before_atomic 96will reach global visibility before atomic operation that follows it. 97The atomic operation is used to protect the end of a critical section. 98.El 99.Pp 100The atomic operations that can be used with 101.Fn membar_enter_after_atomic 102and 103.Fn membar_exit_before_atomic 104are the atomic_add, atomic_sub, atomic_inc, atomic_dec, and atomic_cas 105set of functions. 106For other cases use 107.Fn membar_enter 108or 109.Fn membar_exit . 110.Sh CONTEXT 111.Fn membar_enter , 112.Fn membar_exit , 113.Fn membar_producer , 114.Fn membar_consumer , 115.Fn membar_sync , 116.Fn membar_enter_after_atomic , 117.Fn membar_exit_before_atomic 118can all be called during autoconf, from process context, or from 119interrupt context. 120.Sh HISTORY 121The membar functions first appeared in 122.Nx 5.0 123and 124.Ox 5.5 . 125