lock.h 567 B

12345678910111213141516171819202122232425262728
  1. #pragma once
  2. /*#ifndef _HAS_CXX17*/
  3. namespace std
  4. {
  5. class scoped_lock
  6. {
  7. public:
  8. using mutex_type = std::mutex;
  9. using _Mutex = std::mutex;
  10. explicit scoped_lock(_Mutex& _Mtx) : _MyMutex(_Mtx) { // construct and lock
  11. _MyMutex.lock();
  12. }
  13. explicit scoped_lock(adopt_lock_t, _Mutex& _Mtx) : _MyMutex(_Mtx) {} // construct but don't lock
  14. ~scoped_lock() {
  15. _MyMutex.unlock();
  16. }
  17. scoped_lock(const scoped_lock&) = delete;
  18. scoped_lock& operator=(const scoped_lock&) = delete;
  19. private:
  20. _Mutex& _MyMutex;
  21. };
  22. }
  23. //#endif