Last active
October 19, 2016 17:43
-
-
Save markwaterman/1e385dab141e92f5cc121f659af3496e to your computer and use it in GitHub Desktop.
C++ mutex class for exclusive ownership based on Windows SRWLOCK. Can be used in conjunction with unique_lock.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #pragma once | |
| #include <Windows.h> | |
| class srw_mutex | |
| { | |
| public: | |
| srw_mutex() | |
| { | |
| ::InitializeSRWLock(&srw_); | |
| } | |
| ~srw_mutex() | |
| { | |
| } | |
| srw_mutex(const srw_mutex&) = delete; | |
| srw_mutex& operator=(const srw_mutex&) = delete; | |
| void lock() | |
| { | |
| ::AcquireSRWLockExclusive(&srw_); | |
| } | |
| void unlock() | |
| { | |
| ::ReleaseSRWLockExclusive(&srw_); | |
| } | |
| private: | |
| SRWLOCK srw_; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment