Merge commit '9276b3991ba20d5a5660887ba81b0bc7bed25a0c'
[unleashed.git] / share / man / man9f / membar_ops.9f
blobd37b2452f6f5108e15028abd801d6deaaf42436a
1 '\" te
2 .\" Copyright (c) 2006, Sun Microsystems, Inc. All Rights Reserved.
3 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
4 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
5 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
6 .TH MEMBAR_OPS 9F "Jan 16, 2006"
7 .SH NAME
8 membar_ops, membar_enter, membar_exit, membar_producer, membar_consumer \-
9 memory access synchronization barrier operations
10 .SH SYNOPSIS
11 .LP
12 .nf
13 #include <sys/atomic.h>
15 \fBvoid\fR \fBmembar_enter\fR(\fBvoid\fR);
16 .fi
18 .LP
19 .nf
20 \fBvoid\fR \fBmembar_exit\fR(\fBvoid\fR);
21 .fi
23 .LP
24 .nf
25 \fBvoid\fR \fBmembar_producer\fR(\fBvoid\fR);
26 .fi
28 .LP
29 .nf
30 \fBvoid\fR \fBmembar_consumer\fR(\fBvoid\fR);
31 .fi
33 .SH DESCRIPTION
34 .sp
35 .LP
36 The \fBmembar_enter()\fR function is a generic memory barrier used during lock
37 entry. It is placed after the memory operation that acquires the lock to
38 guarantee that the lock protects its data. No stores from after the memory
39 barrier will reach visibility and no loads from after the barrier will be
40 resolved before the lock acquisition reaches global visibility.
41 .sp
42 .LP
43 The \fBmembar_exit()\fR function is a generic memory barrier used during lock
44 exit. It is placed before the memory operation that releases the lock to
45 guarantee that the lock protects its data. All loads and stores issued before
46 the barrier will be resolved before the subsequent lock update reaches
47 visibility.
48 .sp
49 .LP
50 The \fBmembar_enter()\fR and \fBmembar_exit()\fR functions are used together to
51 allow regions of code to be in relaxed store order and then ensure that the
52 load or store order is maintained at a higher level. They are useful in the
53 implementation of mutex exclusion locks.
54 .sp
55 .LP
56 The \fBmembar_producer()\fR function arranges for all stores issued before this
57 point in the code to reach global visibility before any stores that follow.
58 This is useful in producer modules that update a data item, then set a flag
59 that it is available. The memory barrier guarantees that the available flag is
60 not visible earlier than the updated data, thereby imposing store ordering.
61 .sp
62 .LP
63 The \fBmembar_consumer()\fR function arranges for all loads issued before this
64 point in the code to be completed before any subsequent loads. This is useful
65 in consumer modules that check if data is available and read the data. The
66 memory barrier guarantees that the data is not sampled until after the
67 available flag has been seen, thereby imposing load ordering.
68 .SH RETURN VALUES
69 .sp
70 .LP
71 No values are returned.
72 .SH ERRORS
73 .sp
74 .LP
75 No errors are defined.
76 .SH CONTEXT
77 .sp
78 .LP
79 These functions can be called from user, interrupt, or kernel context.
80 .SH ATTRIBUTES
81 .sp
82 .LP
83 See \fBattributes\fR(5) for descriptions of the following attributes:
84 .sp
86 .sp
87 .TS
88 box;
89 c | c
90 l | l .
91 ATTRIBUTE TYPE  ATTRIBUTE VALUE
93 Interface Stability     Committed
94 .TE
96 .SH SEE ALSO
97 .sp
98 .LP
99 \fBatomic_add\fR(9F), \fBatomic_and\fR(9F), \fBatomic_bits\fR(9F),
100 \fBatomic_cas\fR(9F), \fBatomic_dec\fR(9F), \fBatomic_inc\fR(9F),
101 \fBatomic_ops\fR(9F), \fBatomic_or\fR(9F), \fBatomic_swap\fR(9F),
102 \fBattributes\fR(5), \fBatomic_ops\fR(3C)
103 .SH NOTES
106 Atomic instructions (see \fBatomic_ops\fR(9F)) ensure global visibility of
107 atomically-modified variables on completion. In a relaxed store order system,
108 this does not guarantee that the visibility of other variables will be
109 synchronized with the completion of the atomic instruction. If such
110 synchronization is required, memory barrier instructions must be used.