VirtualBox

source: vbox/trunk/src/libs/xpcom18a4/nsprpub/pr/include/prolock.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: 6.4 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 prolock_h___
39#define prolock_h___
40
41#include "prtypes.h"
42
43#ifdef VBOX_WITH_XPCOM_NAMESPACE_CLEANUP
44#define PR_CreateOrderedLock VBoxNsprPR_CreateOrderedLock
45#define PR_DestroyOrderedLock VBoxNsprPR_DestroyOrderedLock
46#define PR_LockOrderedLock VBoxNsprPR_LockOrderedLock
47#define PR_UnlockOrderedLock VBoxNsprPR_UnlockOrderedLock
48#endif /* VBOX_WITH_XPCOM_NAMESPACE_CLEANUP */
49
50PR_BEGIN_EXTERN_C
51
52/*
53** A locking mechanism, built on the existing PRLock definiion,
54** is provided that will permit applications to define a Lock
55** Hierarchy (or Lock Ordering) schema. An application designed
56** using the Ordered Lock functions will terminate with a
57** diagnostic message when a lock inversion condition is
58** detected.
59**
60** The lock ordering detection is complile-time enabled only. in
61** optimized builds of NSPR, the Ordered Lock functions map
62** directly to PRLock functions, providing no lock order
63** detection.
64**
65** The Ordered Lock Facility is compiled in when DEBUG is defined at
66** compile time. Ordered Lock can be forced on in optimized builds by
67** defining FORCE_NSPR_ORDERED_LOCK at compile time. Both the
68** application using Ordered Lock and NSPR must be compiled with the
69** facility enabled to achieve the desired results.
70**
71** Application designers should use the macro interfaces to the Ordered
72** Lock facility to ensure that it is compiled out in optimized builds.
73**
74** Application designers are responsible for defining their own
75** lock hierarchy.
76**
77** Ordered Lock is thread-safe and SMP safe.
78**
79** See Also: prlock.h
80**
81** /lth. 10-Jun-1998.
82**
83*/
84
85/*
86** Opaque type for ordered lock.
87** ... Don't even think of looking in here.
88**
89*/
90
91#if defined(DEBUG) || defined(FORCE_NSPR_ORDERED_LOCKS)
92typedef void * PROrderedLock;
93#else
94/*
95** Map PROrderedLock and methods onto PRLock when ordered locking
96** is not compiled in.
97**
98*/
99#include "prlock.h"
100
101typedef PRLock PROrderedLock;
102#endif
103
104/* -----------------------------------------------------------------------
105** FUNCTION: PR_CreateOrderedLock() -- Create an Ordered Lock
106**
107** DESCRIPTION: PR_CreateOrderedLock() creates an ordered lock.
108**
109** INPUTS:
110** order: user defined order of this lock.
111** name: name of the lock. For debugging purposes.
112**
113** OUTPUTS: returned
114**
115** RETURNS: PR_OrderedLock pointer
116**
117** RESTRICTIONS:
118**
119*/
120#if defined(DEBUG) || defined(FORCE_NSPR_ORDERED_LOCKS)
121#define PR_CREATE_ORDERED_LOCK(order,name)\
122 PR_CreateOrderedLock((order),(name))
123#else
124#define PR_CREATE_ORDERED_LOCK(order) PR_NewLock()
125#endif
126
127NSPR_API(PROrderedLock *)
128 PR_CreateOrderedLock(
129 PRInt32 order,
130 const char *name
131);
132
133/* -----------------------------------------------------------------------
134** FUNCTION: PR_DestroyOrderedLock() -- Destroy an Ordered Lock
135**
136** DESCRIPTION: PR_DestroyOrderedLock() destroys the ordered lock
137** referenced by lock.
138**
139** INPUTS: lock: pointer to a PROrderedLock
140**
141** OUTPUTS: the lock is destroyed
142**
143** RETURNS: void
144**
145** RESTRICTIONS:
146**
147*/
148#if defined(DEBUG) || defined(FORCE_NSPR_ORDERED_LOCKS)
149#define PR_DESTROY_ORDERED_LOCK(lock) PR_DestroyOrderedLock((lock))
150#else
151#define PR_DESTROY_ORDERED_LOCK(lock) PR_DestroyLock((lock))
152#endif
153
154NSPR_API(void)
155 PR_DestroyOrderedLock(
156 PROrderedLock *lock
157);
158
159/* -----------------------------------------------------------------------
160** FUNCTION: PR_LockOrderedLock() -- Lock an ordered lock
161**
162** DESCRIPTION: PR_LockOrderedLock() locks the ordered lock
163** referenced by lock. If the order of lock is less than or equal
164** to the order of the highest lock held by the locking thread,
165** the function asserts.
166**
167** INPUTS: lock: a pointer to a PROrderedLock
168**
169** OUTPUTS: The lock is held or the fucntion asserts.
170**
171** RETURNS: void
172**
173** RESTRICTIONS:
174**
175*/
176#if defined(DEBUG) || defined(FORCE_NSPR_ORDERED_LOCKS)
177#define PR_LOCK_ORDERED_LOCK(lock) PR_LockOrderedLock((lock))
178#else
179#define PR_LOCK_ORDERED_LOCK(lock) PR_Lock((lock))
180#endif
181
182NSPR_API(void)
183 PR_LockOrderedLock(
184 PROrderedLock *lock
185);
186
187/* -----------------------------------------------------------------------
188** FUNCTION: PR_UnlockOrderedLock() -- unlock and Ordered Lock
189**
190** DESCRIPTION: PR_UnlockOrderedLock() unlocks the lock referenced
191** by lock.
192**
193** INPUTS: lock: a pointer to a PROrderedLock
194**
195** OUTPUTS: the lock is unlocked
196**
197** RETURNS:
198** PR_SUCCESS
199** PR_FAILURE
200**
201** RESTRICTIONS:
202**
203*/
204#if defined(DEBUG) || defined(FORCE_NSPR_ORDERED_LOCKS)
205#define PR_UNLOCK_ORDERED_LOCK(lock) PR_UnlockOrderedLock((lock))
206#else
207#define PR_UNLOCK_ORDERED_LOCK(lock) PR_Unlock((lock))
208#endif
209
210NSPR_API(PRStatus)
211 PR_UnlockOrderedLock(
212 PROrderedLock *lock
213);
214
215PR_END_EXTERN_C
216
217#endif /* prolock_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