nsprpub/pr/include/prolock.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #ifndef prolock_h___
michael@0 7 #define prolock_h___
michael@0 8
michael@0 9 #include "prtypes.h"
michael@0 10
michael@0 11 PR_BEGIN_EXTERN_C
michael@0 12
michael@0 13 /*
michael@0 14 ** A locking mechanism, built on the existing PRLock definiion,
michael@0 15 ** is provided that will permit applications to define a Lock
michael@0 16 ** Hierarchy (or Lock Ordering) schema. An application designed
michael@0 17 ** using the Ordered Lock functions will terminate with a
michael@0 18 ** diagnostic message when a lock inversion condition is
michael@0 19 ** detected.
michael@0 20 **
michael@0 21 ** The lock ordering detection is complile-time enabled only. in
michael@0 22 ** optimized builds of NSPR, the Ordered Lock functions map
michael@0 23 ** directly to PRLock functions, providing no lock order
michael@0 24 ** detection.
michael@0 25 **
michael@0 26 ** The Ordered Lock Facility is compiled in when DEBUG is defined at
michael@0 27 ** compile time. Ordered Lock can be forced on in optimized builds by
michael@0 28 ** defining FORCE_NSPR_ORDERED_LOCK at compile time. Both the
michael@0 29 ** application using Ordered Lock and NSPR must be compiled with the
michael@0 30 ** facility enabled to achieve the desired results.
michael@0 31 **
michael@0 32 ** Application designers should use the macro interfaces to the Ordered
michael@0 33 ** Lock facility to ensure that it is compiled out in optimized builds.
michael@0 34 **
michael@0 35 ** Application designers are responsible for defining their own
michael@0 36 ** lock hierarchy.
michael@0 37 **
michael@0 38 ** Ordered Lock is thread-safe and SMP safe.
michael@0 39 **
michael@0 40 ** See Also: prlock.h
michael@0 41 **
michael@0 42 ** /lth. 10-Jun-1998.
michael@0 43 **
michael@0 44 */
michael@0 45
michael@0 46 /*
michael@0 47 ** Opaque type for ordered lock.
michael@0 48 ** ... Don't even think of looking in here.
michael@0 49 **
michael@0 50 */
michael@0 51
michael@0 52 #if defined(DEBUG) || defined(FORCE_NSPR_ORDERED_LOCKS)
michael@0 53 typedef void * PROrderedLock;
michael@0 54 #else
michael@0 55 /*
michael@0 56 ** Map PROrderedLock and methods onto PRLock when ordered locking
michael@0 57 ** is not compiled in.
michael@0 58 **
michael@0 59 */
michael@0 60 #include "prlock.h"
michael@0 61
michael@0 62 typedef PRLock PROrderedLock;
michael@0 63 #endif
michael@0 64
michael@0 65 /* -----------------------------------------------------------------------
michael@0 66 ** FUNCTION: PR_CreateOrderedLock() -- Create an Ordered Lock
michael@0 67 **
michael@0 68 ** DESCRIPTION: PR_CreateOrderedLock() creates an ordered lock.
michael@0 69 **
michael@0 70 ** INPUTS:
michael@0 71 ** order: user defined order of this lock.
michael@0 72 ** name: name of the lock. For debugging purposes.
michael@0 73 **
michael@0 74 ** OUTPUTS: returned
michael@0 75 **
michael@0 76 ** RETURNS: PR_OrderedLock pointer
michael@0 77 **
michael@0 78 ** RESTRICTIONS:
michael@0 79 **
michael@0 80 */
michael@0 81 #if defined(DEBUG) || defined(FORCE_NSPR_ORDERED_LOCKS)
michael@0 82 #define PR_CREATE_ORDERED_LOCK(order,name)\
michael@0 83 PR_CreateOrderedLock((order),(name))
michael@0 84 #else
michael@0 85 #define PR_CREATE_ORDERED_LOCK(order) PR_NewLock()
michael@0 86 #endif
michael@0 87
michael@0 88 NSPR_API(PROrderedLock *)
michael@0 89 PR_CreateOrderedLock(
michael@0 90 PRInt32 order,
michael@0 91 const char *name
michael@0 92 );
michael@0 93
michael@0 94 /* -----------------------------------------------------------------------
michael@0 95 ** FUNCTION: PR_DestroyOrderedLock() -- Destroy an Ordered Lock
michael@0 96 **
michael@0 97 ** DESCRIPTION: PR_DestroyOrderedLock() destroys the ordered lock
michael@0 98 ** referenced by lock.
michael@0 99 **
michael@0 100 ** INPUTS: lock: pointer to a PROrderedLock
michael@0 101 **
michael@0 102 ** OUTPUTS: the lock is destroyed
michael@0 103 **
michael@0 104 ** RETURNS: void
michael@0 105 **
michael@0 106 ** RESTRICTIONS:
michael@0 107 **
michael@0 108 */
michael@0 109 #if defined(DEBUG) || defined(FORCE_NSPR_ORDERED_LOCKS)
michael@0 110 #define PR_DESTROY_ORDERED_LOCK(lock) PR_DestroyOrderedLock((lock))
michael@0 111 #else
michael@0 112 #define PR_DESTROY_ORDERED_LOCK(lock) PR_DestroyLock((lock))
michael@0 113 #endif
michael@0 114
michael@0 115 NSPR_API(void)
michael@0 116 PR_DestroyOrderedLock(
michael@0 117 PROrderedLock *lock
michael@0 118 );
michael@0 119
michael@0 120 /* -----------------------------------------------------------------------
michael@0 121 ** FUNCTION: PR_LockOrderedLock() -- Lock an ordered lock
michael@0 122 **
michael@0 123 ** DESCRIPTION: PR_LockOrderedLock() locks the ordered lock
michael@0 124 ** referenced by lock. If the order of lock is less than or equal
michael@0 125 ** to the order of the highest lock held by the locking thread,
michael@0 126 ** the function asserts.
michael@0 127 **
michael@0 128 ** INPUTS: lock: a pointer to a PROrderedLock
michael@0 129 **
michael@0 130 ** OUTPUTS: The lock is held or the function asserts.
michael@0 131 **
michael@0 132 ** RETURNS: void
michael@0 133 **
michael@0 134 ** RESTRICTIONS:
michael@0 135 **
michael@0 136 */
michael@0 137 #if defined(DEBUG) || defined(FORCE_NSPR_ORDERED_LOCKS)
michael@0 138 #define PR_LOCK_ORDERED_LOCK(lock) PR_LockOrderedLock((lock))
michael@0 139 #else
michael@0 140 #define PR_LOCK_ORDERED_LOCK(lock) PR_Lock((lock))
michael@0 141 #endif
michael@0 142
michael@0 143 NSPR_API(void)
michael@0 144 PR_LockOrderedLock(
michael@0 145 PROrderedLock *lock
michael@0 146 );
michael@0 147
michael@0 148 /* -----------------------------------------------------------------------
michael@0 149 ** FUNCTION: PR_UnlockOrderedLock() -- unlock and Ordered Lock
michael@0 150 **
michael@0 151 ** DESCRIPTION: PR_UnlockOrderedLock() unlocks the lock referenced
michael@0 152 ** by lock.
michael@0 153 **
michael@0 154 ** INPUTS: lock: a pointer to a PROrderedLock
michael@0 155 **
michael@0 156 ** OUTPUTS: the lock is unlocked
michael@0 157 **
michael@0 158 ** RETURNS:
michael@0 159 ** PR_SUCCESS
michael@0 160 ** PR_FAILURE
michael@0 161 **
michael@0 162 ** RESTRICTIONS:
michael@0 163 **
michael@0 164 */
michael@0 165 #if defined(DEBUG) || defined(FORCE_NSPR_ORDERED_LOCKS)
michael@0 166 #define PR_UNLOCK_ORDERED_LOCK(lock) PR_UnlockOrderedLock((lock))
michael@0 167 #else
michael@0 168 #define PR_UNLOCK_ORDERED_LOCK(lock) PR_Unlock((lock))
michael@0 169 #endif
michael@0 170
michael@0 171 NSPR_API(PRStatus)
michael@0 172 PR_UnlockOrderedLock(
michael@0 173 PROrderedLock *lock
michael@0 174 );
michael@0 175
michael@0 176 PR_END_EXTERN_C
michael@0 177
michael@0 178 #endif /* prolock_h___ */

mercurial