AuroraRuntime/Source/Threading/Primitives/AuConditionMutex.Generic.hpp
Jamie Reece Wilson 5862dbeacc [+] New generic primitives
[-] AuSemaphore.Unix.hpp
[*] Moved the old pthread based primitives to _removed/*.bak
[+] AuWoASemaphore.Unix.cpp
[+] AuWoASemaphore.Unix.hpp
2023-12-29 16:12:14 +00:00

77 lines
1.7 KiB
C++

/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: AuConditionMutex.Generic.hpp
Date: 2021-6-14
Author: Reece
***/
#pragma once
#include "AuIConditionMutexEx.hpp"
#if defined(AURORA_IS_MODERNNT_DERIVED)
#include "AuConditionMutex.NT.hpp"
#elif defined(AURORA_IS_LINUX_DERIVED)
#include "AuConditionMutex.Linux.hpp"
#else
#define _AURUNTIME_GENERICCM
#include "AuMutex.Generic.hpp"
namespace Aurora::Threading::Primitives
{
#pragma pack(push)
#pragma pack(4)
struct GenericConditionMutex final
{
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();
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.Unlock();
}
auline void Unlock()
{
mutex.Unlock();
}
inline AuUInt GetOSHandle()
{
return mutex.GetOSHandle();
}
ConditionMutexInternal mutex;
};
}
#endif