2014-07-06 23:54:47 +00:00
|
|
|
#pragma once
|
|
|
|
#include "stdafx.h"
|
2016-01-26 22:21:33 +00:00
|
|
|
#include <thread>
|
2014-07-06 23:54:47 +00:00
|
|
|
|
2016-01-09 18:15:43 +00:00
|
|
|
class SimpleLock;
|
|
|
|
|
|
|
|
class LockHandler
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
SimpleLock *_lock;
|
|
|
|
public:
|
|
|
|
LockHandler(SimpleLock *lock);
|
|
|
|
~LockHandler();
|
|
|
|
};
|
|
|
|
|
2014-07-06 23:54:47 +00:00
|
|
|
class SimpleLock
|
|
|
|
{
|
|
|
|
private:
|
2016-01-26 22:21:33 +00:00
|
|
|
thread_local static std::thread::id _threadID;
|
|
|
|
|
|
|
|
std::thread::id _holderThreadID;
|
2014-07-09 22:29:07 +00:00
|
|
|
uint32_t _lockCount;
|
2014-07-06 23:54:47 +00:00
|
|
|
atomic_flag _lock;
|
|
|
|
|
|
|
|
public:
|
2015-07-02 03:17:14 +00:00
|
|
|
SimpleLock();
|
|
|
|
~SimpleLock();
|
2016-01-09 18:15:43 +00:00
|
|
|
|
|
|
|
LockHandler AcquireSafe();
|
|
|
|
|
2015-07-02 03:17:14 +00:00
|
|
|
void Acquire();
|
|
|
|
bool IsFree();
|
|
|
|
void WaitForRelease();
|
|
|
|
void Release();
|
2014-07-09 22:29:07 +00:00
|
|
|
};
|
|
|
|
|