Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

162 lines
4.0 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. lock.h
  5. Abstract:
  6. This module defines the data structures and function prototypes used
  7. for spin lock debugging.
  8. Author:
  9. Manny Weiser (mannyw) 18-Jan-1992
  10. Revision History:
  11. --*/
  12. #ifndef _LOCK_
  13. #define _LOCK_
  14. #if MUPDBG
  15. #define MUP_TEB_LOCK_LIST 0
  16. #define INITIALIZE_LOCK( lock, level, name ) \
  17. MupInitializeLock( (lock), (level), (name) )
  18. #define DELETE_LOCK( lock ) MupDeleteLock( lock )
  19. #define ACQUIRE_LOCK(lock) MupAcquireLock( lock )
  20. #define RELEASE_LOCK(lock) MupReleaseLock( lock )
  21. #define LOCK_NAME( lock ) ((lock)->Header.LockName)
  22. #define LOCK_LEVEL( lock ) ((lock)->Header.LockLevel)
  23. #define LOCK_THREAD_LIST( lock ) (&((lock)->Header.ThreadListEntry))
  24. #define LOCK_NUMBER_OF_ACTIVE( lock ) ((lock)->Resource.ActiveCount)
  25. #define LOCK_EXCLUSIVE_OWNER( lock ) ((ULONG)(lock)->Resource.OwnerThreads[0].OwnerThread)
  26. //
  27. // MUP_LOCK_HEADER is a structure that contains debugging information
  28. // used by the server lock package. Mup spin locks contain a
  29. // MUP_LOCK_HEADER.
  30. //
  31. typedef struct _MUP_LOCK_HEADER {
  32. //
  33. // To prevent deadlocks, locks are assigned level numbers. If a
  34. // thread holds a lock with level N, it may only acquire new locks
  35. // with a level greater then N. Level numbers are assigned during
  36. // lock initialization.
  37. //
  38. ULONG LockLevel;
  39. //
  40. // A doubly-linked list of all the locks owned by a thread is stored
  41. // in a thread's TEB. The list is in order of lock level (from
  42. // highest to lowest), which is also, by definition of lock levels,
  43. // the order in which the thread acquired the locks. This allows
  44. // the thread to release the locks in any order while maintaining
  45. // easy access to the highest-level lock that the thread owns,
  46. // thereby providing a mechanism for ensuring that locks are
  47. // acquired in increasing order.
  48. //
  49. LIST_ENTRY ThreadListEntry;
  50. //
  51. // The symbolic name of the lock is used in DbgPrint calls.
  52. //
  53. PSZ LockName;
  54. } MUP_LOCK_HEADER, *PMUP_LOCK_HEADER;
  55. //
  56. // When debugging is enabled, a server lock is a wrapper around an
  57. // executive resource.
  58. //
  59. typedef struct _MUP_LOCK {
  60. //
  61. // The MUP_LOCK_HEADER must appear first!
  62. //
  63. MUP_LOCK_HEADER Header;
  64. //
  65. // The actual "lock" is maintained by the resource package.
  66. //
  67. ERESOURCE Resource;
  68. } MUP_LOCK, *PMUP_LOCK;
  69. VOID
  70. MupInitializeLock(
  71. IN PMUP_LOCK Lock,
  72. IN ULONG Locklevel,
  73. IN PSZ LockName
  74. );
  75. VOID
  76. MupDeleteLock (
  77. IN PMUP_LOCK Lock
  78. );
  79. VOID
  80. MupAcquireLock(
  81. IN PMUP_LOCK Lock
  82. );
  83. VOID
  84. MupReleaseLock(
  85. IN PMUP_LOCK Lock
  86. );
  87. ULONG
  88. MupCheckListIntegrity (
  89. IN PLIST_ENTRY ListHead,
  90. IN ULONG MaxEntries
  91. );
  92. //
  93. // Macros that define locations in the UserReserved field of the TEB
  94. // where lock level information is stored.
  95. //
  96. #define MUP_TEB_LOCK_LIST 0
  97. #define MUP_TEB_LOCK_INIT 2
  98. #define MUP_TEB_USER_SIZE (3 * sizeof(ULONG))
  99. //
  100. // Levels used for spin locks used in the MUP. Locks can be acquired
  101. // only in increasing lock level order. Be careful when adding a new
  102. // lock or when changing the order of lock levels.
  103. //
  104. #define GLOBAL_LOCK_LEVEL (ULONG)0x80000100
  105. #define PREFIX_TABLE_LOCK_LEVEL (ULONG)0x80000200
  106. #define CCB_LIST_LOCK_LEVEL (ULONG)0x80000300
  107. #define QUERY_CONTEXT_LOCK_LEVEL (ULONG)0x80000400
  108. #define DEBUG_LOCK_LEVEL (ULONG)0x80000500
  109. #else
  110. #define INITIALIZE_LOCK( lock, level, name ) ExInitializeResourceLite( (lock) )
  111. #define DELETE_LOCK( lock ) ExDeleteResourceLite( (lock) )
  112. #define ACQUIRE_LOCK( lock ) \
  113. ExAcquireResourceExclusiveLite( (lock), TRUE )
  114. #define RELEASE_LOCK(lock) ExReleaseResourceLite( (lock) )
  115. typedef ERESOURCE MUP_LOCK, *PMUP_LOCK;
  116. #endif // MUPDBG
  117. #endif // _LOCK_