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.

373 lines
7.4 KiB

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