2023-08-12 10:11:12 +00:00
|
|
|
/***
|
2024-01-29 14:09:59 +00:00
|
|
|
Copyright (C) 2023-2024 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
2023-08-12 10:11:12 +00:00
|
|
|
|
|
|
|
File: AuConditionMutex.Linux.hpp
|
|
|
|
Date: 2023-8-11
|
|
|
|
Author: Reece
|
|
|
|
***/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "AuIConditionMutexEx.hpp"
|
|
|
|
|
|
|
|
namespace Aurora::Threading::Primitives
|
|
|
|
{
|
2023-08-21 18:17:05 +00:00
|
|
|
#pragma pack(push)
|
|
|
|
#pragma pack(4)
|
|
|
|
|
2023-08-27 11:41:51 +00:00
|
|
|
// 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
|
2023-08-21 18:17:05 +00:00
|
|
|
struct LinuxConditionMutex final
|
2023-08-12 10:11:12 +00:00
|
|
|
{
|
|
|
|
LinuxConditionMutex();
|
|
|
|
~LinuxConditionMutex();
|
|
|
|
|
2023-08-21 18:17:05 +00:00
|
|
|
bool TryLock();
|
|
|
|
void Lock();
|
|
|
|
void Unlock();
|
|
|
|
AuUInt GetOSHandle();
|
|
|
|
bool LockMS(AuUInt64 timeout);
|
|
|
|
bool LockNS(AuUInt64 timeout);
|
|
|
|
bool LockAbsMS(AuUInt64 timeout);
|
|
|
|
bool LockAbsNS(AuUInt64 timeout);
|
2023-08-12 10:11:12 +00:00
|
|
|
|
2023-08-19 17:33:54 +00:00
|
|
|
auline bool TryLockNoSpin();
|
|
|
|
auline bool TryLockHeavy();
|
2023-08-21 18:17:05 +00:00
|
|
|
|
2023-08-12 10:11:12 +00:00
|
|
|
private:
|
|
|
|
AuUInt32 uState_ {};
|
|
|
|
AuUInt32 uSleeping_ {};
|
|
|
|
};
|
2023-08-21 18:17:05 +00:00
|
|
|
#pragma pack(pop)
|
2023-08-12 10:11:12 +00:00
|
|
|
|
2023-08-21 18:17:05 +00:00
|
|
|
using ConditionMutexInternal = LinuxConditionMutex;
|
|
|
|
|
|
|
|
struct ConditionMutexImpl final : IConditionMutexEx
|
|
|
|
{
|
|
|
|
auline bool TryLock()
|
|
|
|
{
|
|
|
|
return mutex.TryLock();
|
|
|
|
}
|
|
|
|
|
|
|
|
auline void Lock()
|
|
|
|
{
|
2024-01-27 09:15:11 +00:00
|
|
|
mutex.Lock();
|
2023-08-21 18:17:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
auline void Unlock()
|
|
|
|
{
|
|
|
|
mutex.Unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline AuUInt GetOSHandle()
|
|
|
|
{
|
|
|
|
return mutex.GetOSHandle();
|
|
|
|
}
|
|
|
|
|
|
|
|
ConditionMutexInternal mutex;
|
|
|
|
};
|
2023-08-12 10:11:12 +00:00
|
|
|
}
|