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.

97 lines
2.2 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name :
  4. kLocks.cpp
  5. Abstract:
  6. A collection of kernel-mode locks for multithreaded access
  7. to data structures
  8. Author:
  9. George V. Reilly (GeorgeRe) 25-Oct-2000
  10. Environment:
  11. Win32 - Kernel Mode
  12. Project:
  13. Internet Information Server Http.sys
  14. Revision History:
  15. --*/
  16. #include "precomp.hxx"
  17. #define DLL_IMPLEMENTATION
  18. #define IMPLEMENTATION_EXPORT
  19. #include <kLKRhash.h>
  20. #include "../src/Locks.cpp"
  21. //------------------------------------------------------------------------
  22. // CKSpinLock static member variables
  23. LOCK_DEFAULT_SPIN_DATA(CKSpinLock);
  24. LOCK_STATISTICS_DATA(CKSpinLock);
  25. LOCK_STATISTICS_DUMMY_IMPLEMENTATION(CKSpinLock);
  26. //------------------------------------------------------------------------
  27. // CFastMutex static member variables
  28. LOCK_DEFAULT_SPIN_DATA(CFastMutex);
  29. LOCK_STATISTICS_DATA(CFastMutex);
  30. LOCK_STATISTICS_DUMMY_IMPLEMENTATION(CFastMutex);
  31. //------------------------------------------------------------------------
  32. // CEResource static member variables
  33. LOCK_DEFAULT_SPIN_DATA(CEResource);
  34. LOCK_STATISTICS_DATA(CEResource);
  35. LOCK_STATISTICS_DUMMY_IMPLEMENTATION(CEResource);
  36. //------------------------------------------------------------------------
  37. // Function: CEResource::ReadOrWriteLock
  38. // Synopsis: If already locked, recursively acquires another lock of the
  39. // same kind (read or write). Otherwise, just acquires a read lock.
  40. //------------------------------------------------------------------------
  41. bool
  42. CEResource::ReadOrWriteLock()
  43. {
  44. if (IsWriteLocked())
  45. {
  46. WriteLock();
  47. return false; // => not read locked
  48. }
  49. else
  50. {
  51. ReadLock();
  52. return true; // => is read locked
  53. }
  54. }
  55. //------------------------------------------------------------------------
  56. // Function: CEResource::ReadOrWriteUnlock
  57. // Synopsis: release a lock acquired with ReadOrWriteLock
  58. //------------------------------------------------------------------------
  59. void
  60. CEResource::ReadOrWriteUnlock(
  61. bool fIsReadLocked)
  62. {
  63. if (fIsReadLocked)
  64. ReadUnlock();
  65. else
  66. WriteUnlock();
  67. }