Skip to content

Instantly share code, notes, and snippets.

@markwaterman
Last active October 19, 2016 17:43
Show Gist options
  • Select an option

  • Save markwaterman/1e385dab141e92f5cc121f659af3496e to your computer and use it in GitHub Desktop.

Select an option

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.
#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