VirtualBox

source: vbox/trunk/include/iprt/condvar.h

Last change on this file was 98103, checked in by vboxsync, 17 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.3 KB
RevLine 
[31154]1/** @file
2 * IPRT - Condition Variable.
3 */
4
5/*
[98103]6 * Copyright (C) 2006-2023 Oracle and/or its affiliates.
[31154]7 *
[96407]8 * This file is part of VirtualBox base platform packages, as
9 * available from https://www.virtualbox.org.
[31154]10 *
[96407]11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation, in version 3 of the
14 * License.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, see <https://www.gnu.org/licenses>.
23 *
[31154]24 * The contents of this file may alternatively be used under the terms
25 * of the Common Development and Distribution License Version 1.0
[96407]26 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
27 * in the VirtualBox distribution, in which case the provisions of the
[31154]28 * CDDL are applicable instead of those of the GPL.
29 *
30 * You may elect to license modified versions of this file under the
31 * terms and conditions of either the GPL or the CDDL or both.
[96407]32 *
33 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
[31154]34 */
35
[76557]36#ifndef IPRT_INCLUDED_condvar_h
37#define IPRT_INCLUDED_condvar_h
[76507]38#ifndef RT_WITHOUT_PRAGMA_ONCE
39# pragma once
40#endif
[31154]41
42#include <iprt/cdefs.h>
43#include <iprt/types.h>
44#if defined(RT_LOCK_STRICT_ORDER) && defined(IN_RING3)
45# include <iprt/lockvalidator.h>
46#endif
47
48
49RT_C_DECLS_BEGIN
50
51/** @defgroup grp_rt_condvar RTCondVar - Condition Variable
52 *
53 * Condition variables combines mutex semaphore or critical sections with event
54 * semaphores. See @ref grp_rt_sems_mutex, @ref grp_rt_critsect,
55 * @ref grp_rt_sems_event and @ref grp_rt_sems_event_multi.
56 *
57 * @ingroup grp_rt
58 * @{
59 */
60
61
62/**
63 * Create a condition variable.
64 *
65 * @returns iprt status code.
66 * @param phCondVar Where to store the handle to the newly created
67 * condition variable.
68 */
[57926]69RTDECL(int) RTCondVarCreate(PRTCONDVAR phCondVar);
[31154]70
71/**
72 * Create a condition variable.
73 *
74 * @returns iprt status code.
75 * @param phCondVar Where to store the handle to the newly created
76 * condition variable.
77 * @param fFlags Flags, any combination of the
78 * RTCONDVAR_FLAGS_XXX \#defines.
79 * @param hClass The class (no reference consumed). Since we
80 * don't do order checks on condition variables,
81 * the use of the class is limited to controlling
82 * the timeout threshold for deadlock detection.
83 * @param pszNameFmt Name format string for the lock validator,
84 * optional (NULL). Max length is 32 bytes.
85 * @param ... Format string arguments.
86 */
[57926]87RTDECL(int) RTCondVarCreateEx(PRTCONDVAR phCondVar, uint32_t fFlags, RTLOCKVALCLASS hClass,
[57004]88 const char *pszNameFmt, ...) RT_IPRT_FORMAT_ATTR(4, 5);
[31154]89
[57926]90/** @name RTCondVarCreateEx flags
[31154]91 * @{ */
92/** Disables lock validation. */
93#define RTCONDVAR_FLAGS_NO_LOCK_VAL UINT32_C(0x00000001)
94/** @} */
95
96/**
97 * Destroy a condition variable.
98 *
99 * @returns iprt status code.
100 * @param hCondVar Handle of the condition variable. NIL_RTCONDVAR
[33540]101 * is quietly ignored (VINF_SUCCESS).
[31154]102 */
[57926]103RTDECL(int) RTCondVarDestroy(RTCONDVAR hCondVar);
[31154]104
105/**
106 * Signal the condition variable, waking up exactly one thread.
107 *
108 * It is recommended that the caller holds the associated lock, but this is not
109 * strictly speaking necessary.
110 *
111 * If no threads are waiting on the condition variable, the call will have no
112 * effect on the variable.
113 *
114 * @returns iprt status code.
[57926]115 * @param hCondVar The condition variable to signal.
[31154]116 */
[57926]117RTDECL(int) RTCondVarSignal(RTCONDVAR hCondVar);
[31154]118
119/**
120 * Signal the condition variable, waking up all blocked threads.
121 *
122 * It is recommended that the caller holds the associated lock, but this is not
123 * strictly speaking necessary.
124 *
125 * If no threads are waiting on the condition variable, the call will have no
126 * effect on the variable.
127 *
128 * @returns iprt status code.
[57926]129 * @param hCondVar The condition variable to broadcast.
[31154]130 */
[57926]131RTDECL(int) RTCondVarBroadcast(RTCONDVAR hCondVar);
[31154]132
133/**
134 * Wait for the condition variable to be signaled, resume on interruption.
135 *
136 * This function will resume if the wait is interrupted by an async system event
137 * (like a unix signal) or similar.
138 *
139 * @returns iprt status code.
140 * Will not return VERR_INTERRUPTED.
[57926]141 * @param hCondVar The condition variable to wait on.
[31154]142 * @param hMtx The mutex to leave during the wait and which
143 * will be re-enter before returning.
144 * @param cMillies Number of milliseconds to wait. Use
145 * RT_INDEFINITE_WAIT to wait forever.
146 */
[57926]147RTDECL(int) RTCondVarMutexWait(RTCONDVAR hCondVar, RTSEMMUTEX hMtx, RTMSINTERVAL cMillies);
[31154]148
149/**
150 * Wait for the condition variable to be signaled, return on interruption.
151 *
152 * This function will not resume the wait if interrupted.
153 *
154 * @returns iprt status code.
[57926]155 * @param hCondVar The condition variable to wait on.
[31154]156 * @param hMtx The mutex to leave during the wait and which
157 * will be re-enter before returning.
158 * @param cMillies Number of milliseconds to wait. Use
159 * RT_INDEFINITE_WAIT to wait forever.
160 */
[57926]161RTDECL(int) RTCondVarMutexWaitNoResume(RTCONDVAR hCondVar, RTSEMMUTEX hMtx, RTMSINTERVAL cMillies);
[31154]162
163/**
164 * Wait for the condition variable to be signaled, resume on interruption.
165 *
166 * This function will resume if the wait is interrupted by an async system event
167 * (like a unix signal) or similar.
168 *
169 * @returns iprt status code.
170 * Will not return VERR_INTERRUPTED.
[57926]171 * @param hCondVar The condition variable to wait on.
[31154]172 * @param hRWSem The read/write semaphore to write-leave during
173 * the wait and which will be re-enter in write
174 * mode before returning.
175 * @param cMillies Number of milliseconds to wait. Use
176 * RT_INDEFINITE_WAIT to wait forever.
177 */
[57926]178RTDECL(int) RTCondVarRWWriteWait(RTCONDVAR hCondVar, RTSEMRW hRWSem, RTMSINTERVAL cMillies);
[31154]179
180/**
181 * Wait for the condition variable to be signaled, return on interruption.
182 *
183 * This function will not resume the wait if interrupted.
184 *
185 * @returns iprt status code.
[57926]186 * @param hCondVar The condition variable to wait on.
[31154]187 * @param hRWSem The read/write semaphore to write-leave during
188 * the wait and which will be re-enter in write
189 * mode before returning.
190 * @param cMillies Number of milliseconds to wait. Use
191 * RT_INDEFINITE_WAIT to wait forever.
192 */
[57926]193RTDECL(int) RTCondVarRWWriteWaitNoResume(RTCONDVAR hCondVar, RTSEMRW hRWSem, RTMSINTERVAL cMillies);
[31154]194
195/**
196 * Wait for the condition variable to be signaled, resume on interruption.
197 *
198 * This function will resume if the wait is interrupted by an async system event
199 * (like a unix signal) or similar.
200 *
201 * @returns iprt status code.
202 * Will not return VERR_INTERRUPTED.
[57926]203 * @param hCondVar The condition variable to wait on.
[31154]204 * @param hRWSem The read/write semaphore to read-leave during
205 * the wait and which will be re-enter in read mode
206 * before returning.
207 * @param cMillies Number of milliseconds to wait. Use
208 * RT_INDEFINITE_WAIT to wait forever.
209 */
[57926]210RTDECL(int) RTCondVarRWReadWait(RTCONDVAR hCondVar, RTSEMRW hRWSem, RTMSINTERVAL cMillies);
[31154]211
212/**
213 * Wait for the condition variable to be signaled, return on interruption.
214 *
215 * This function will not resume the wait if interrupted.
216 *
217 * @returns iprt status code.
[57926]218 * @param hCondVar The condition variable to wait on.
[31154]219 * @param hRWSem The read/write semaphore to read-leave during
220 * the wait and which will be re-enter in read mode
221 * before returning.
222 * @param cMillies Number of milliseconds to wait. Use
223 * RT_INDEFINITE_WAIT to wait forever.
224 */
[57926]225RTDECL(int) RTCondVarRWReadWaitNoResume(RTCONDVAR hCondVar, RTSEMRW hRWSem, RTMSINTERVAL cMillies);
[31154]226
227/**
228 * Wait for the condition variable to be signaled, resume on interruption.
229 *
230 * This function will resume if the wait is interrupted by an async system event
231 * (like a unix signal) or similar.
232 *
233 * @returns iprt status code.
234 * Will not return VERR_INTERRUPTED.
[57926]235 * @param hCondVar The condition variable to wait on.
[31154]236 * @param pCritSect The critical section to leave during the wait
237 * and which will be re-enter before returning.
238 * @param cMillies Number of milliseconds to wait. Use
239 * RT_INDEFINITE_WAIT to wait forever.
240 */
[57926]241RTDECL(int) RTCondVarCritSectWait(RTCONDVAR hCondVar, PRTCRITSECT pCritSect, RTMSINTERVAL cMillies);
[31154]242
243/**
244 * Wait for the condition variable to be signaled, return on interruption.
245 *
246 * This function will not resume the wait if interrupted.
247 *
248 * @returns iprt status code.
[57926]249 * @param hCondVar The condition variable to wait on.
[31154]250 * @param pCritSect The critical section to leave during the wait
251 * and which will be re-enter before returning.
252 * @param cMillies Number of milliseconds to wait. Use
253 * RT_INDEFINITE_WAIT to wait forever.
254 */
[57926]255RTDECL(int) RTCondVarCritSectWaitNoResume(RTCONDVAR hCondVar, PRTCRITSECT pCritSect, RTMSINTERVAL cMillies);
[31154]256
257/**
258 * Sets the signaller thread to one specific thread.
259 *
260 * This is only used for validating usage and deadlock detection. When used
[57926]261 * after calls to RTCondVarAddSignaller, the specified thread will be the only
[31154]262 * signalling thread.
263 *
[57926]264 * @param hCondVar The condition variable.
[31154]265 * @param hThread The thread that will signal it. Pass
266 * NIL_RTTHREAD to indicate that there is no
267 * special signalling thread.
268 */
[57926]269RTDECL(void) RTCondVarSetSignaller(RTCONDVAR hCondVar, RTTHREAD hThread);
[31154]270
271/**
272 * To add more signalling threads.
273 *
274 * First call RTCondVarSetSignaller then add further threads with this.
275 *
[57926]276 * @param hCondVar The condition variable.
[31154]277 * @param hThread The thread that will signal it. NIL_RTTHREAD is
278 * not accepted.
279 */
[57926]280RTDECL(void) RTCondVarAddSignaller(RTCONDVAR hCondVar, RTTHREAD hThread);
[31154]281
282/**
283 * To remove a signalling thread.
284 *
285 * Reverts work done by RTCondVarAddSignaller and RTCondVarSetSignaller.
286 *
[57926]287 * @param hCondVar The condition variable.
[31154]288 * @param hThread A previously added thread.
289 */
[57926]290RTDECL(void) RTCondVarRemoveSignaller(RTCONDVAR hCondVar, RTTHREAD hThread);
[31154]291
292/** @} */
293
294RT_C_DECLS_END
295
[76585]296#endif /* !IPRT_INCLUDED_condvar_h */
[31154]297
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use