77 lines
1.7 KiB
C++
77 lines
1.7 KiB
C++
/***
|
|
Copyright (C) 2021-2024 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.Lock();
|
|
}
|
|
|
|
auline void Unlock()
|
|
{
|
|
mutex.Unlock();
|
|
}
|
|
|
|
inline AuUInt GetOSHandle()
|
|
{
|
|
return mutex.GetOSHandle();
|
|
}
|
|
|
|
ConditionMutexInternal mutex;
|
|
};
|
|
}
|
|
#endif
|