AuroraRuntime/Source/Threading/Primitives/AuCriticalSection.hpp

51 lines
1.3 KiB
C++
Raw Normal View History

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