1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
14 ** A locking mechanism, built on the existing PRLock definiion,
15 ** is provided that will permit applications to define a Lock
16 ** Hierarchy (or Lock Ordering) schema. An application designed
17 ** using the Ordered Lock functions will terminate with a
18 ** diagnostic message when a lock inversion condition is
21 ** The lock ordering detection is complile-time enabled only. in
22 ** optimized builds of NSPR, the Ordered Lock functions map
23 ** directly to PRLock functions, providing no lock order
26 ** The Ordered Lock Facility is compiled in when DEBUG is defined at
27 ** compile time. Ordered Lock can be forced on in optimized builds by
28 ** defining FORCE_NSPR_ORDERED_LOCK at compile time. Both the
29 ** application using Ordered Lock and NSPR must be compiled with the
30 ** facility enabled to achieve the desired results.
32 ** Application designers should use the macro interfaces to the Ordered
33 ** Lock facility to ensure that it is compiled out in optimized builds.
35 ** Application designers are responsible for defining their own
38 ** Ordered Lock is thread-safe and SMP safe.
47 ** Opaque type for ordered lock.
48 ** ... Don't even think of looking in here.
52 #if defined(DEBUG) || defined(FORCE_NSPR_ORDERED_LOCKS)
53 typedef void * PROrderedLock
;
56 ** Map PROrderedLock and methods onto PRLock when ordered locking
57 ** is not compiled in.
62 typedef PRLock PROrderedLock
;
65 /* -----------------------------------------------------------------------
66 ** FUNCTION: PR_CreateOrderedLock() -- Create an Ordered Lock
68 ** DESCRIPTION: PR_CreateOrderedLock() creates an ordered lock.
71 ** order: user defined order of this lock.
72 ** name: name of the lock. For debugging purposes.
76 ** RETURNS: PR_OrderedLock pointer
81 #if defined(DEBUG) || defined(FORCE_NSPR_ORDERED_LOCKS)
82 #define PR_CREATE_ORDERED_LOCK(order,name)\
83 PR_CreateOrderedLock((order),(name))
85 #define PR_CREATE_ORDERED_LOCK(order) PR_NewLock()
88 NSPR_API(PROrderedLock
*)
94 /* -----------------------------------------------------------------------
95 ** FUNCTION: PR_DestroyOrderedLock() -- Destroy an Ordered Lock
97 ** DESCRIPTION: PR_DestroyOrderedLock() destroys the ordered lock
98 ** referenced by lock.
100 ** INPUTS: lock: pointer to a PROrderedLock
102 ** OUTPUTS: the lock is destroyed
109 #if defined(DEBUG) || defined(FORCE_NSPR_ORDERED_LOCKS)
110 #define PR_DESTROY_ORDERED_LOCK(lock) PR_DestroyOrderedLock((lock))
112 #define PR_DESTROY_ORDERED_LOCK(lock) PR_DestroyLock((lock))
116 PR_DestroyOrderedLock(
120 /* -----------------------------------------------------------------------
121 ** FUNCTION: PR_LockOrderedLock() -- Lock an ordered lock
123 ** DESCRIPTION: PR_LockOrderedLock() locks the ordered lock
124 ** referenced by lock. If the order of lock is less than or equal
125 ** to the order of the highest lock held by the locking thread,
126 ** the function asserts.
128 ** INPUTS: lock: a pointer to a PROrderedLock
130 ** OUTPUTS: The lock is held or the function asserts.
137 #if defined(DEBUG) || defined(FORCE_NSPR_ORDERED_LOCKS)
138 #define PR_LOCK_ORDERED_LOCK(lock) PR_LockOrderedLock((lock))
140 #define PR_LOCK_ORDERED_LOCK(lock) PR_Lock((lock))
148 /* -----------------------------------------------------------------------
149 ** FUNCTION: PR_UnlockOrderedLock() -- unlock and Ordered Lock
151 ** DESCRIPTION: PR_UnlockOrderedLock() unlocks the lock referenced
154 ** INPUTS: lock: a pointer to a PROrderedLock
156 ** OUTPUTS: the lock is unlocked
165 #if defined(DEBUG) || defined(FORCE_NSPR_ORDERED_LOCKS)
166 #define PR_UNLOCK_ORDERED_LOCK(lock) PR_UnlockOrderedLock((lock))
168 #define PR_UNLOCK_ORDERED_LOCK(lock) PR_Unlock((lock))
172 PR_UnlockOrderedLock(
178 #endif /* prolock_h___ */