VirtualBox

source: vbox/trunk/src/libs/xpcom18a4/nsprpub/pr/include/prcvar.h@ 26515

Last change on this file since 26515 was 11551, checked in by vboxsync, 16 years ago

API/xpcom: prefix any C symbols in VBoxXPCOM.so, to avoid namespace pollution. Enabled only on Linux at the moment.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.3 KB
Line 
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2/* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 *
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
9 *
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
14 *
15 * The Original Code is the Netscape Portable Runtime (NSPR).
16 *
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998-2000
20 * the Initial Developer. All Rights Reserved.
21 *
22 * Contributor(s):
23 *
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
35 *
36 * ***** END LICENSE BLOCK ***** */
37
38#ifndef prcvar_h___
39#define prcvar_h___
40
41#include "prlock.h"
42#include "prinrval.h"
43
44#ifdef VBOX_WITH_XPCOM_NAMESPACE_CLEANUP
45#define PR_NewCondVar VBoxNsprPR_NewCondVar
46#define PR_DestroyCondVar VBoxNsprPR_DestroyCondVar
47#define PR_WaitCondVar VBoxNsprPR_WaitCondVar
48#define PR_NotifyCondVar VBoxNsprPR_NotifyCondVar
49#define PR_NotifyAllCondVar VBoxNsprPR_NotifyAllCondVar
50#endif /* VBOX_WITH_XPCOM_NAMESPACE_CLEANUP */
51
52PR_BEGIN_EXTERN_C
53
54typedef struct PRCondVar PRCondVar;
55
56/*
57** Create a new condition variable.
58**
59** "lock" is the lock used to protect the condition variable.
60**
61** Condition variables are synchronization objects that threads can use
62** to wait for some condition to occur.
63**
64** This may fail if memory is tight or if some operating system resource
65** is low. In such cases, a NULL will be returned.
66*/
67NSPR_API(PRCondVar*) PR_NewCondVar(PRLock *lock);
68
69/*
70** Destroy a condition variable. There must be no thread
71** waiting on the condvar. The caller is responsible for guaranteeing
72** that the condvar is no longer in use.
73**
74*/
75NSPR_API(void) PR_DestroyCondVar(PRCondVar *cvar);
76
77/*
78** The thread that waits on a condition is blocked in a "waiting on
79** condition" state until another thread notifies the condition or a
80** caller specified amount of time expires. The lock associated with
81** the condition variable will be released, which must have be held
82** prior to the call to wait.
83**
84** Logically a notified thread is moved from the "waiting on condition"
85** state and made "ready." When scheduled, it will attempt to reacquire
86** the lock that it held when wait was called.
87**
88** The timeout has two well known values, PR_INTERVAL_NO_TIMEOUT and
89** PR_INTERVAL_NO_WAIT. The former value requires that a condition be
90** notified (or the thread interrupted) before it will resume from the
91** wait. If the timeout has a value of PR_INTERVAL_NO_WAIT, the effect
92** is to release the lock, possibly causing a rescheduling within the
93** runtime, then immediately attempting to reacquire the lock and resume.
94**
95** Any other value for timeout will cause the thread to be rescheduled
96** either due to explicit notification or an expired interval. The latter
97** must be determined by treating time as one part of the monitored data
98** being protected by the lock and tested explicitly for an expired
99** interval.
100**
101** Returns PR_FAILURE if the caller has not locked the lock associated
102** with the condition variable or the thread was interrupted (PR_Interrupt()).
103** The particular reason can be extracted with PR_GetError().
104*/
105NSPR_API(PRStatus) PR_WaitCondVar(PRCondVar *cvar, PRIntervalTime timeout);
106
107/*
108** Notify ONE thread that is currently waiting on 'cvar'. Which thread is
109** dependent on the implementation of the runtime. Common sense would dictate
110** that all threads waiting on a single condition have identical semantics,
111** therefore which one gets notified is not significant.
112**
113** The calling thead must hold the lock that protects the condition, as
114** well as the invariants that are tightly bound to the condition, when
115** notify is called.
116**
117** Returns PR_FAILURE if the caller has not locked the lock associated
118** with the condition variable.
119*/
120NSPR_API(PRStatus) PR_NotifyCondVar(PRCondVar *cvar);
121
122/*
123** Notify all of the threads waiting on the condition variable. The order
124** that the threads are notified is indeterminant. The lock that protects
125** the condition must be held.
126**
127** Returns PR_FAILURE if the caller has not locked the lock associated
128** with the condition variable.
129*/
130NSPR_API(PRStatus) PR_NotifyAllCondVar(PRCondVar *cvar);
131
132PR_END_EXTERN_C
133
134#endif /* prcvar_h___ */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette