AuroraRuntime/Source/Threading/Primitives/AuConditionMutex.Generic.hpp

77 lines
1.7 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: AuConditionMutex.Generic.hpp
2021-06-27 21:25:29 +00:00
Date: 2021-6-14
Author: Reece
***/
#pragma once
2022-11-17 07:46:07 +00:00
#include "AuIConditionMutexEx.hpp"
2021-06-27 21:25:29 +00:00
2021-09-06 10:58:08 +00:00
#if defined(AURORA_IS_MODERNNT_DERIVED)
2022-11-17 07:46:07 +00:00
#include "AuConditionMutex.NT.hpp"
#elif defined(AURORA_IS_LINUX_DERIVED)
#include "AuConditionMutex.Linux.hpp"
2021-06-27 21:25:29 +00:00
#else
#define _AURUNTIME_GENERICCM
2022-11-17 07:46:07 +00:00
#include "AuMutex.Generic.hpp"
2021-06-27 21:25:29 +00:00
namespace Aurora::Threading::Primitives
{
#pragma pack(push)
#pragma pack(4)
struct GenericConditionMutex final
2021-06-27 21:25:29 +00:00
{
GenericConditionMutex();
~GenericConditionMutex();
bool TryLock();
void Lock();
void Unlock();
AuUInt GetOSHandle();
bool LockMS(AuUInt64 timeout);
bool LockNS(AuUInt64 timeout);
bool LockAbsMS(AuUInt64 timeout);
bool LockAbsNS(AuUInt64 timeout);
auline bool TryLockNoSpin();
auline bool TryLockHeavy();
2021-06-27 21:25:29 +00:00
private:
AuUInt32 uState_ {};
AuUInt32 uSleeping_ {};
};
#pragma pack(pop)
using ConditionMutexInternal = GenericConditionMutex;
struct ConditionMutexGenericImpl final : IConditionMutexEx
{
auline bool TryLock()
{
return mutex.TryLock();
}
auline void Lock()
{
mutex.Lock();
}
auline void Unlock()
{
mutex.Unlock();
}
inline AuUInt GetOSHandle()
{
return mutex.GetOSHandle();
}
ConditionMutexInternal mutex;
2021-06-27 21:25:29 +00:00
};
}
#endif