WrappedMutex.h 663 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #ifndef WIN32_WRAPPED_MUTEX_H
  2. #define WIN32_WRAPPED_MUTEX_H
  3. #include <Windows.h>
  4. /**
  5. * Wraps a windows mutex.
  6. * Header only since all the methods call one function, we want them to be inlined
  7. **/
  8. class WrappedMutex
  9. {
  10. public:
  11. WrappedMutex()
  12. {
  13. this->_mutex = CreateMutex(
  14. NULL, // default security attributes
  15. FALSE, // initially not owned
  16. NULL); // unnamed mutex
  17. }
  18. ~WrappedMutex()
  19. {
  20. CloseHandle(_mutex);
  21. }
  22. void lock()
  23. {
  24. WaitForSingleObject(_mutex, INFINITE);
  25. }
  26. void unlock()
  27. {
  28. ReleaseMutex(_mutex);
  29. }
  30. private:
  31. HANDLE _mutex;
  32. };
  33. #endif