2021-06-27 21:25:29 +00:00
|
|
|
/***
|
2024-01-29 14:09:59 +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
|
|
|
|
2024-12-27 09:50:53 +00:00
|
|
|
#if defined(AURORA_IS_MODERNNT_DERIVED) && !defined(AURORA_FORCE_SPECIAL_WIN32_PRIMITIVES)
|
2022-11-17 07:46:07 +00:00
|
|
|
#include "AuConditionMutex.NT.hpp"
|
2024-12-27 09:50:53 +00:00
|
|
|
#elif defined(AURORA_IS_LINUX_DERIVED) && !defined(WOA_ALWAYS_DUMB_OS_TARGET)
|
2023-08-12 10:11:12 +00:00
|
|
|
#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
|
|
|
|
{
|
2023-12-29 15:35:25 +00:00
|
|
|
#pragma pack(push)
|
|
|
|
#pragma pack(4)
|
|
|
|
|
|
|
|
struct GenericConditionMutex final
|
2021-06-27 21:25:29 +00:00
|
|
|
{
|
2023-12-29 15:35:25 +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:
|
2023-12-29 15:35:25 +00:00
|
|
|
AuUInt32 uState_ {};
|
|
|
|
AuUInt32 uSleeping_ {};
|
|
|
|
};
|
|
|
|
#pragma pack(pop)
|
|
|
|
|
|
|
|
using ConditionMutexInternal = GenericConditionMutex;
|
|
|
|
|
|
|
|
struct ConditionMutexGenericImpl final : IConditionMutexEx
|
|
|
|
{
|
|
|
|
auline bool TryLock()
|
|
|
|
{
|
|
|
|
return mutex.TryLock();
|
|
|
|
}
|
|
|
|
|
|
|
|
auline void Lock()
|
|
|
|
{
|
2024-01-27 09:15:11 +00:00
|
|
|
mutex.Lock();
|
2023-12-29 15:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
auline void Unlock()
|
|
|
|
{
|
|
|
|
mutex.Unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline AuUInt GetOSHandle()
|
|
|
|
{
|
|
|
|
return mutex.GetOSHandle();
|
|
|
|
}
|
|
|
|
|
|
|
|
ConditionMutexInternal mutex;
|
2021-06-27 21:25:29 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|