crst.cpp
Upload User: xhy777
Upload Date: 2007-02-14
Package Size: 24088k
Code Size: 1k
Category:

Windows Kernel

Development Platform:

Visual C++

  1. #include "proj.h"
  2. #include "dbutil.h"
  3. ///////
  4. // Critical section helper stuff
  5. //
  6. #ifdef DEBUG
  7. UINT g_CriticalSectionCount = 0;
  8. DWORD g_CriticalSectionOwner = 0;
  9. #ifdef STACKBACKTRACE
  10. DBstkback g_CriticalSectionLastCall[4] = { 0 };
  11. #endif
  12. void Dll_EnterCriticalSection(CRITICAL_SECTION * pcsDll)
  13. {
  14. #ifdef STACKBACKTRACE
  15.     int var0;       // *must* be 1st on frame
  16. #endif
  17.     EnterCriticalSection(pcsDll);
  18.     if (g_CriticalSectionCount++ == 0)
  19.     {
  20.         g_CriticalSectionOwner = GetCurrentThreadId();
  21. #ifdef STACKBACKTRACE
  22.         int fp = (int) (1 + (int *)&var0);
  23.         DBGetStackBack(&fp, g_CriticalSectionLastCall, ARRAYSIZE(g_CriticalSectionLastCall));
  24. #endif
  25.     }
  26. }
  27. void Dll_LeaveCriticalSection(CRITICAL_SECTION * pcsDll)
  28. {
  29.     if (--g_CriticalSectionCount == 0)
  30.         g_CriticalSectionOwner = 0;
  31.     LeaveCriticalSection(pcsDll);
  32. }
  33. #endif