AuroraRuntime/Source/Threading/Primitives/AuConditionMutex.Linux.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

69 lines
1.6 KiB
C++

/***
Copyright (C) 2023-2024 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: AuConditionMutex.Linux.hpp
Date: 2023-8-11
Author: Reece
***/
#pragma once
#include "AuIConditionMutexEx.hpp"
namespace Aurora::Threading::Primitives
{
#pragma pack(push)
#pragma pack(4)
// We're being recycled as a tiny mutex for AuCriticalSection
// The thread cookie of sizeof(void *) under linux/x86_64 is too large
// We can be in parity with other platforms by switching to whichever mutex type is most convenient
struct LinuxConditionMutex final
{
LinuxConditionMutex();
~LinuxConditionMutex();
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 = LinuxConditionMutex;
struct ConditionMutexImpl 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;
};
}