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.

82 lines
2.3 KiB

  1. // Guard.h -- Guard class declaration
  2. // (c) Copyright Schlumberger Technology Corp., unpublished work, created
  3. // 1999. This computer program includes Confidential, Proprietary
  4. // Information and is a Trade Secret of Schlumberger Technology Corp. All
  5. // use, disclosure, and/or reproduction is prohibited unless authorized
  6. // in writing. All Rights Reserved.
  7. #if !defined(SLBCSP_GUARD_H)
  8. #define SLBCSP_GUARD_H
  9. #include "Lockable.h"
  10. // Guard (manage) the locking and unlocking of a lockable object.
  11. template<class T>
  12. class Guard
  13. {
  14. public:
  15. // Types
  16. // C'tors/D'tors
  17. explicit
  18. Guard(T &rLock)
  19. : m_rLock(rLock)
  20. {
  21. m_rLock.Lock();
  22. }
  23. ~Guard()
  24. {
  25. try
  26. {
  27. m_rLock.Unlock();
  28. }
  29. catch (...)
  30. {
  31. // do nothing, exceptions should not propagate out of
  32. // destructors
  33. }
  34. }
  35. // Operators
  36. // Operations
  37. // Access
  38. // Predicates
  39. protected:
  40. // Types
  41. // C'tors/D'tors
  42. // Operators
  43. // Operations
  44. // Access
  45. // Predicates
  46. // Variables
  47. T &m_rLock;
  48. private:
  49. // Types
  50. // C'tors/D'tors
  51. // Operators
  52. // Operations
  53. // Access
  54. // Predicates
  55. // Variables
  56. };
  57. template<>
  58. class Guard<Lockable *>
  59. : public Guard<Lockable>
  60. {
  61. Guard(Lockable *pLock)
  62. : Guard<Lockable>(*pLock)
  63. {};
  64. ~Guard()
  65. {};
  66. };
  67. #endif // SLBCSP_GUARD_H