AuroraRuntime/Source/Threading/Primitives/AuCriticalSection.hpp
Jamie Reece Wilson 62b6fa20f8 [*] Update the copyright header of most of the primitives
[*] Fix generic mutex abs yield always returning true
2024-01-29 14:48:04 +00:00

51 lines
1.3 KiB
C++

/***
Copyright (C) 2021-2024 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: AuCriticalSection.hpp
Date: 2021-6-12
Author: Reece
***/
#pragma once
#include "AuMutex.Generic.hpp"
#include "AuConditionMutex.Generic.hpp"
#include "ThreadCookie.hpp"
namespace Aurora::Threading::Primitives
{
#if (defined(AURORA_ARCH_X64) || defined(AURORA_ARCH_X86))
#pragma pack(push)
#pragma pack(4)
#endif
struct CriticalSectionImpl final : IWaitable
{
CriticalSectionImpl();
~CriticalSectionImpl();
bool HasOSHandle(AuMach &mach) override;
bool HasLockImplementation() override;
bool TryLock() override;
void Lock() override;
bool LockMS(AuUInt64 timeout) override;
bool LockNS(AuUInt64 timeout) override;
bool LockAbsMS(AuUInt64 timeout) override;
bool LockAbsNS(AuUInt64 timeout) override;
void Unlock() override;
private:
#if defined(_AURUNTIME_GENERICCM)
GenericConditionMutex mutex_;
#elif defined(AURORA_IS_LINUX_DERIVED)
LinuxConditionMutex mutex_; // shave a few bytes
#else
MutexImpl mutex_;
#endif
ThreadCookie_t owner_;
AuUInt32 count_;
};
#if (defined(AURORA_ARCH_X64) || defined(AURORA_ARCH_X86))
#pragma pack(pop)
#endif
}