home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / nspr30-e.zip / nspr30-e / include / prolock.h < prev    next >
C/C++ Source or Header  |  1998-09-25  |  5KB  |  197 lines

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