-
Notifications
You must be signed in to change notification settings - Fork 434
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[REFACT] Moved custom Mutex class to a separate file
- Loading branch information
1 parent
f54b294
commit 2898fdd
Showing
2 changed files
with
55 additions
and
46 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#pragma once | ||
#include <peconv.h> | ||
|
||
namespace pesieve | ||
{ | ||
namespace util { | ||
|
||
struct Mutex { | ||
public: | ||
Mutex() | ||
{ | ||
InitializeCriticalSection(&cs); | ||
} | ||
|
||
void Lock() | ||
{ | ||
EnterCriticalSection(&cs); | ||
} | ||
|
||
void Unlock() | ||
{ | ||
LeaveCriticalSection(&cs); | ||
} | ||
|
||
~Mutex() | ||
{ | ||
DeleteCriticalSection(&cs); | ||
} | ||
|
||
private: | ||
CRITICAL_SECTION cs; | ||
}; | ||
|
||
struct MutexLocker | ||
{ | ||
public: | ||
MutexLocker(Mutex& _mutex) | ||
: mutex(_mutex) | ||
{ | ||
mutex.Lock(); | ||
} | ||
|
||
~MutexLocker() | ||
{ | ||
mutex.Unlock(); | ||
} | ||
|
||
private: | ||
Mutex& mutex; | ||
}; | ||
|
||
}; //namespace util | ||
|
||
}; //namespace pesieve |