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.

60 lines
996 B

  1. /*
  2. *
  3. * REVISIONS:
  4. * cad09Jul93: Initial Revision
  5. * pcy08Apr94: Trim size, use static iterators, dead code removal
  6. */
  7. #ifndef __MUTEXLCK_H
  8. #define __MUTEXLCK_H
  9. #include "apcobj.h"
  10. _CLASSDEF( MutexLock )
  11. class MutexLock : public Obj {
  12. protected:
  13. public:
  14. MutexLock() {};
  15. virtual INT Request() {return TimedRequest(-1L);};
  16. virtual INT TimedRequest(LONG aMillisecondTimeOut) = 0;
  17. virtual INT IsHeld() = 0;
  18. virtual INT Release() = 0;
  19. };
  20. class AutoMutexLocker
  21. {
  22. public:
  23. AutoMutexLocker(MutexLock * aLock)
  24. : theLock(aLock)
  25. {
  26. if (theLock) {
  27. theLock->Request();
  28. }
  29. };
  30. //
  31. // the destructor is not declared virtual because this
  32. // class is not intended to be derived from - so there
  33. // is no need to add a Vtable when it isn't needed
  34. //
  35. ~AutoMutexLocker()
  36. {
  37. if (theLock) {
  38. theLock->Release();
  39. }
  40. };
  41. protected:
  42. private:
  43. MutexLock * theLock;
  44. };
  45. #endif