AuroraRuntime/Source/Threading/Primitives/CriticalSection.hpp

31 lines
696 B
C++

/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: CriticalSection.hpp
Date: 2021-6-12
Author: Reece
***/
#pragma once
#include "Mutex.Generic.hpp"
namespace Aurora::Threading::Primitives
{
struct CriticalSection : IWaitable
{
CriticalSection();
~CriticalSection();
bool HasOSHandle(AuMach &mach) override;
bool HasLockImplementation() override;
bool TryLock() override;
void Lock() override;
bool Lock(AuUInt64 timeout) override;
void Unlock() override;
private:
Mutex mutex_;
Threads::IAuroraThread *owner_;
std::atomic<int> count_;
};
}