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.

74 lines
1.8 KiB

  1. #include <precomp.h>
  2. #include <locks.h>
  3. #ifdef _WIN32_WINNT
  4. #if _WIN32_WINNT > 0x0400
  5. DWORD POLARITY BreakOnDbgAndRenterLoop(void)
  6. {
  7. __try
  8. {
  9. DebugBreak();
  10. }
  11. _except (EXCEPTION_EXECUTE_HANDLER) {};
  12. return EXCEPTION_CONTINUE_EXECUTION;
  13. };
  14. ReaderWriter::ReaderWriter(bool can_throw) : initialized_(false), can_throw_(can_throw)
  15. {
  16. C_ASSERT(sizeof(::RTL_RESOURCE)==sizeof(ReaderWriter::RTL_RESOURCE));
  17. __try
  18. {
  19. RtlInitializeResource((::RTL_RESOURCE*)&lock_);
  20. initialized_ = true;
  21. }
  22. __except(GetExceptionCode() == STATUS_NO_MEMORY)
  23. {
  24. }
  25. if (initialized_ != true)
  26. raise_exception();
  27. }
  28. ReaderWriter::~ReaderWriter (void)
  29. { if (initialized_) RtlDeleteResource((::RTL_RESOURCE*)&lock_);}
  30. bool
  31. ReaderWriter::acquire (void)
  32. { return (RtlAcquireResourceExclusive((::RTL_RESOURCE*)&lock_,TRUE)==TRUE);}
  33. bool
  34. ReaderWriter::tryacquire (void)
  35. { return (RtlAcquireResourceExclusive((::RTL_RESOURCE*)&lock_,FALSE)==TRUE);}
  36. bool
  37. ReaderWriter::release (void)
  38. { RtlReleaseResource((::RTL_RESOURCE*)&lock_); return 0;}
  39. bool
  40. ReaderWriter::acquire_read (void)
  41. { return (RtlAcquireResourceShared((::RTL_RESOURCE*)&lock_,TRUE)==TRUE);}
  42. bool
  43. ReaderWriter::acquire_write (void)
  44. { return (RtlAcquireResourceExclusive((::RTL_RESOURCE*)&lock_,TRUE)==TRUE);}
  45. bool
  46. ReaderWriter::tryacquire_read (void)
  47. { return (RtlAcquireResourceShared((::RTL_RESOURCE*)&lock_,FALSE)==TRUE);}
  48. bool
  49. ReaderWriter::tryacquire_write (void)
  50. { return (RtlAcquireResourceExclusive((::RTL_RESOURCE*)&lock_,FALSE)==TRUE);}
  51. void
  52. ReaderWriter::downgrade()
  53. { RtlConvertExclusiveToShared((::RTL_RESOURCE*)&lock_);}
  54. void
  55. ReaderWriter::upgrade()
  56. { RtlConvertSharedToExclusive((::RTL_RESOURCE*)&lock_);}
  57. #endif
  58. #endif