2 .\" The contents of this file are subject to the terms of the
3 .\" Common Development and Distribution License (the "License").
4 .\" You may not use this file except in compliance with the License.
6 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
7 .\" or http://www.opensolaris.org/os/licensing.
8 .\" See the License for the specific language governing permissions
9 .\" and limitations under the License.
11 .\" When distributing Covered Code, include this CDDL HEADER in each
12 .\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
13 .\" If applicable, add the following below this CDDL HEADER, with the
14 .\" fields enclosed by brackets "[]" replaced with your own identifying
15 .\" information: Portions Copyright [yyyy] [name of copyright owner]
18 .\" Copyright (c) 2006, Sun Microsystems, Inc. All Rights Reserved
19 .\" Copyright 2018 Nexenta Systems, Inc.
32 .Nd semaphore functions
40 .Fa "ksema_type_t type"
64 illumos DDI specific (illumos DDI).
68 A pointer to a semaphore, type
71 Initial value for semaphore.
74 This is obsolete and should be
78 strings are legal, but they are a waste of kernel memory.
81 Variant type of the semaphore.
86 Type-specific argument; should be
90 These functions implement counting semaphores as described by Dijkstra.
91 A semaphore has a value which is atomically decremented by
93 and atomically incremented by
95 The value must always be greater than or equal to zero.
98 is called and the value is zero, the calling thread is blocked until another
101 operation on the semaphore.
103 Semaphores are initialized by calling
107 gives the initial value for the semaphore.
108 The semaphore storage is provided by the caller but more may be dynamically
109 allocated, if necessary, by
113 should be called before deallocating the storage containing the semaphore.
117 function decrements the semaphore, as does
119 However, if the semaphore value is zero,
121 will return without decrementing the value if a signal
125 is pending for the thread.
129 function will decrement the semaphore value only if it is greater than zero, and
132 These functions can be called from user, interrupt, or kernel context, except
137 which can be called from user or kernel context only.
138 None of these functions can be called from a high-level interrupt context.
143 should not be called from any interrupt context.
147 is used from interrupt context, lower-priority interrupts will not be serviced
149 This means that if the thread that will eventually perform the
151 becomes blocked on anything that requires the lower-priority interrupt, the
154 For example, the thread that will perform the
156 may need to first allocate memory.
157 This memory allocation may require waiting for paging I/O to complete, which may
158 require a lower-priority disk or network interrupt to be serviced.
159 In general, situations like this are hard to predict, so it is advisable to
160 avoid waiting on semaphores or condition variables in an interrupt context.
162 Similar to many other synchronization mechanisms, semaphores should not be used
163 in any code path that requires synchronization while handling system panic, at
164 which time many of the semaphore operations become no-ops.
169 could not decrement the semaphore value because it was zero.
172 was not able to decrement the semaphore value and detected a pending signal.
179 .Em Writing Device Drivers