Source code of Windows XP (NT5)
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.

358 lines
7.1 KiB

  1. /*++
  2. Copyright (c) 1999-2000 Microsoft Corporation
  3. Module Name:
  4. dbglocks.cxx
  5. Abstract:
  6. Locks support
  7. Author:
  8. George V. Reilly (GeorgeRe) 01-Mar-1999
  9. Revision History:
  10. --*/
  11. #include "precomp.hxx"
  12. #ifdef LOCK_INSTRUMENTATION
  13. # define LOCK_DEFAULT_NAME ("lkrdbg")
  14. LONG CSmallSpinLock::sm_cTotalLocks = 0;
  15. LONG CSpinLock::sm_cTotalLocks = 0;
  16. LONG CReaderWriterLock::sm_cTotalLocks = 0;
  17. LONG CReaderWriterLock2::sm_cTotalLocks = 0;
  18. LONG CReaderWriterLock3::sm_cTotalLocks = 0;
  19. #else // !LOCK_INSTRUMENTATION
  20. # define LOCK_DEFAULT_NAME
  21. #endif // !LOCK_INSTRUMENTATION
  22. const char*
  23. LockName(
  24. LOCK_LOCKTYPE lt)
  25. {
  26. const char* pszName = NULL;
  27. switch (lt)
  28. {
  29. case LOCK_FAKELOCK:
  30. pszName = "CFakeLock";
  31. break;
  32. case LOCK_SMALLSPINLOCK:
  33. pszName = "CSmallSpinLock";
  34. break;
  35. case LOCK_SPINLOCK:
  36. pszName = "CSpinLock";
  37. break;
  38. case LOCK_CRITSEC:
  39. pszName = "CCritSec";
  40. break;
  41. case LOCK_READERWRITERLOCK:
  42. pszName = "CReaderWriterLock";
  43. break;
  44. case LOCK_READERWRITERLOCK2:
  45. pszName = "CReaderWriterLock2";
  46. break;
  47. case LOCK_READERWRITERLOCK3:
  48. pszName = "CReaderWriterLock3";
  49. break;
  50. #ifdef LOCKS_KERNEL_MODE
  51. case LOCK_KSPINLOCK:
  52. pszName = "CKSpinLock";
  53. break;
  54. case LOCK_FASTMUTEX:
  55. pszName = "CFastMutex";
  56. break;
  57. case LOCK_ERESOURCE:
  58. pszName = "CEResource";
  59. break;
  60. #endif // LOCKS_KERNEL_MODE
  61. default:
  62. pszName = "UnknownLockType";
  63. break;
  64. }
  65. return pszName;
  66. };
  67. int
  68. LockSize(
  69. LOCK_LOCKTYPE lt)
  70. {
  71. int cb = 0;
  72. switch (lt)
  73. {
  74. case LOCK_FAKELOCK:
  75. cb = sizeof(CFakeLock);
  76. break;
  77. case LOCK_SMALLSPINLOCK:
  78. cb = sizeof(CSmallSpinLock);
  79. break;
  80. case LOCK_SPINLOCK:
  81. cb = sizeof(CSpinLock);
  82. break;
  83. case LOCK_CRITSEC:
  84. cb = sizeof(CCritSec);
  85. break;
  86. case LOCK_READERWRITERLOCK:
  87. cb = sizeof(CReaderWriterLock);
  88. break;
  89. case LOCK_READERWRITERLOCK2:
  90. cb = sizeof(CReaderWriterLock2);
  91. break;
  92. case LOCK_READERWRITERLOCK3:
  93. cb = sizeof(CReaderWriterLock3);
  94. break;
  95. #ifdef LOCKS_KERNEL_MODE
  96. case LOCK_KSPINLOCK:
  97. cb = sizeof(CKSpinLock);
  98. break;
  99. case LOCK_FASTMUTEX:
  100. cb = sizeof(CFastMutex);
  101. break;
  102. case LOCK_ERESOURCE:
  103. cb = sizeof(CEResource);
  104. break;
  105. #endif // LOCKS_KERNEL_MODE
  106. default:
  107. cb = 0;
  108. break;
  109. }
  110. return cb;
  111. };
  112. BOOL
  113. Print_FakeLock(
  114. IN PVOID pvLock,
  115. IN INT nVerbose)
  116. {
  117. return TRUE;
  118. }
  119. BOOL
  120. Print_SmallSpinLock(
  121. IN PVOID pvLock,
  122. IN INT nVerbose)
  123. {
  124. CSmallSpinLock sl LOCK_DEFAULT_NAME;
  125. ReadMemory(pvLock, &sl, sizeof(sl), NULL);
  126. dprintf("CSmallSpinLock (%p): Thread = %x\n",
  127. pvLock, sl.m_lTid);
  128. memset(&sl, 0, sizeof(sl));
  129. return TRUE;
  130. }
  131. BOOL
  132. Print_SpinLock(
  133. IN PVOID pvLock,
  134. IN INT nVerbose)
  135. {
  136. CSpinLock sl LOCK_DEFAULT_NAME;
  137. ReadMemory(pvLock, &sl, sizeof(sl), NULL);
  138. dprintf("CSpinLock (%p): Thread = %d, Count = %d\n",
  139. pvLock,
  140. (sl.m_lTid & CSpinLock::SL_THREAD_MASK)
  141. >> CSpinLock::SL_THREAD_SHIFT,
  142. (sl.m_lTid & CSpinLock::SL_OWNER_MASK)
  143. >> CSpinLock::SL_OWNER_SHIFT);
  144. memset(&sl, 0, sizeof(sl));
  145. return TRUE;
  146. }
  147. BOOL
  148. Print_CritSec(
  149. IN PVOID pvLock,
  150. IN INT nVerbose)
  151. {
  152. return TRUE;
  153. }
  154. BOOL
  155. Print_ReaderWriterLock(
  156. IN PVOID pvLock,
  157. IN INT nVerbose)
  158. {
  159. CReaderWriterLock sl LOCK_DEFAULT_NAME;
  160. ReadMemory(pvLock, &sl, sizeof(sl), NULL);
  161. dprintf("CReaderWriterLock (%p): State = %x, Waiters = %d\n",
  162. pvLock, sl.m_nState, sl.m_cWaiting);
  163. memset(&sl, 0, sizeof(sl));
  164. return TRUE;
  165. }
  166. BOOL
  167. Print_ReaderWriterLock2(
  168. IN PVOID pvLock,
  169. IN INT nVerbose)
  170. {
  171. CReaderWriterLock2 sl LOCK_DEFAULT_NAME;
  172. ReadMemory(pvLock, &sl, sizeof(sl), NULL);
  173. dprintf("CReaderWriterLock2 (%p): State = %x, Waiters = %d\n",
  174. pvLock,
  175. (sl.m_lRW & CReaderWriterLock2::SL_STATE_MASK)
  176. >> CReaderWriterLock2::SL_STATE_SHIFT,
  177. (sl.m_lRW & CReaderWriterLock2::SL_WAITING_MASK)
  178. >> CReaderWriterLock2::SL_WAITING_SHIFT
  179. );
  180. memset(&sl, 0, sizeof(sl));
  181. return TRUE;
  182. }
  183. BOOL
  184. Print_ReaderWriterLock3(
  185. IN PVOID pvLock,
  186. IN INT nVerbose)
  187. {
  188. CReaderWriterLock3 sl LOCK_DEFAULT_NAME;
  189. ReadMemory(pvLock, &sl, sizeof(sl), NULL);
  190. dprintf("CReaderWriterLock3 (%p): State = %x, Waiters = %d, "
  191. "Thrd = %x, Cnt = %d\n",
  192. pvLock,
  193. (sl.m_lRW & CReaderWriterLock3::SL_STATE_MASK)
  194. >> CReaderWriterLock3::SL_STATE_SHIFT,
  195. (sl.m_lRW & CReaderWriterLock3::SL_WAITING_MASK)
  196. >> CReaderWriterLock3::SL_WAITING_SHIFT,
  197. (sl.m_lTid & CReaderWriterLock3::SL_THREAD_MASK)
  198. >> CReaderWriterLock3::SL_THREAD_SHIFT,
  199. (sl.m_lTid & CReaderWriterLock3::SL_OWNER_MASK)
  200. >> CReaderWriterLock3::SL_OWNER_SHIFT
  201. );
  202. memset(&sl, 0, sizeof(sl));
  203. return TRUE;
  204. }
  205. #ifdef LOCKS_KERNEL_MODE
  206. BOOL
  207. Print_KSpinLock(
  208. IN PVOID pvLock,
  209. IN INT nVerbose)
  210. {
  211. CKSpinLock sl LOCK_DEFAULT_NAME;
  212. ReadMemory(pvLock, &sl, sizeof(sl), NULL);
  213. dprintf("CKSpinLock (%p): \n",
  214. pvLock);
  215. memset(&sl, 0, sizeof(sl));
  216. return TRUE;
  217. }
  218. BOOL
  219. Print_FastMutex(
  220. IN PVOID pvLock,
  221. IN INT nVerbose)
  222. {
  223. CFastMutex sl LOCK_DEFAULT_NAME;
  224. ReadMemory(pvLock, &sl, sizeof(sl), NULL);
  225. dprintf("CFastMutex (%p): \n",
  226. pvLock);
  227. memset(&sl, 0, sizeof(sl));
  228. return TRUE;
  229. }
  230. BOOL
  231. Print_EResource(
  232. IN PVOID pvLock,
  233. IN INT nVerbose)
  234. {
  235. CEResource sl LOCK_DEFAULT_NAME;
  236. ReadMemory(pvLock, &sl, sizeof(sl), NULL);
  237. dprintf("CEResource (%p): \n",
  238. pvLock);
  239. memset(&sl, 0, sizeof(sl));
  240. return TRUE;
  241. }
  242. #endif // LOCKS_KERNEL_MODE
  243. BOOL
  244. PrintLock(
  245. LOCK_LOCKTYPE lt,
  246. IN PVOID pvLock,
  247. IN INT nVerbose)
  248. {
  249. BOOL f = FALSE;
  250. switch (lt)
  251. {
  252. case LOCK_FAKELOCK:
  253. f = Print_FakeLock(pvLock, nVerbose);
  254. break;
  255. case LOCK_SMALLSPINLOCK:
  256. f = Print_SmallSpinLock(pvLock, nVerbose);
  257. break;
  258. case LOCK_SPINLOCK:
  259. f = Print_SpinLock(pvLock, nVerbose);
  260. break;
  261. case LOCK_CRITSEC:
  262. f = Print_CritSec(pvLock, nVerbose);
  263. break;
  264. case LOCK_READERWRITERLOCK:
  265. f = Print_ReaderWriterLock(pvLock, nVerbose);
  266. break;
  267. case LOCK_READERWRITERLOCK2:
  268. f = Print_ReaderWriterLock2(pvLock, nVerbose);
  269. break;
  270. case LOCK_READERWRITERLOCK3:
  271. f = Print_ReaderWriterLock3(pvLock, nVerbose);
  272. break;
  273. #ifdef LOCKS_KERNEL_MODE
  274. case LOCK_KSPINLOCK:
  275. f = Print_KSpinLock(pvLock, nVerbose);
  276. break;
  277. case LOCK_FASTMUTEX:
  278. f = Print_FastMutex(pvLock, nVerbose);
  279. break;
  280. case LOCK_ERESOURCE:
  281. f = Print_EResource(pvLock, nVerbose);
  282. break;
  283. #endif // LOCKS_KERNEL_MODE
  284. default:
  285. f = FALSE;
  286. break;
  287. }
  288. return f;
  289. }