AuroraRuntime/Source/Threading/Primitives/AuConditionVariable.Linux.hpp

80 lines
2.0 KiB
C++
Raw Normal View History

/***
Copyright (C) 2023 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: AuConditionVariable.Linux.hpp
Date: 2023-8-11
Author: Reece
***/
#pragma once
#if !defined(_AURUNTIME_GENERICCV)
#include "AuConditionMutex.Linux.hpp"
namespace Aurora::Threading::Primitives
{
2023-08-21 18:17:05 +00:00
#pragma pack(push)
#pragma pack(4)
struct ConditionVariableLinux final
{
2023-08-21 18:17:05 +00:00
ConditionVariableLinux();
~ConditionVariableLinux();
2023-08-21 18:17:05 +00:00
bool WaitForSignalNsEx(LinuxConditionMutex *pMutex, AuUInt64 timeout);
void Signal();
void Broadcast();
bool WaitOne(AuUInt64 qwTimeout);
private:
AuUInt32 uState_ {};
AuUInt32 uSleeping_ {};
};
2023-08-21 18:17:05 +00:00
#pragma pack(pop)
2023-08-21 18:17:05 +00:00
using ConditionVariableInternal = ConditionVariableLinux;
struct ConditionVariableImpl final : IConditionVariable
{
2023-08-21 18:17:05 +00:00
inline ConditionVariableImpl(const AuSPtr<IConditionMutex> &mutex) :
mutex(mutex)
{
}
auline AuSPtr<IConditionMutex> GetMutex() override
{
return mutex;
}
auline bool WaitForSignal(AuUInt32 timeout) override
{
return cond.WaitForSignalNsEx(&std::static_pointer_cast<ConditionMutexImpl>(this->mutex)->mutex, AuMSToNS<AuUInt64>(timeout));
}
auline bool WaitForSignalNS(AuUInt64 qwTimeout) override
{
return cond.WaitForSignalNsEx(&std::static_pointer_cast<ConditionMutexImpl>(this->mutex)->mutex, qwTimeout);
}
inline bool WaitForSignalNsEx(const std::shared_ptr<LinuxConditionMutex> &pMutex, AuUInt64 timeout)
{
return cond.WaitForSignalNsEx(pMutex.get(), timeout);
}
auline void Signal() override
{
cond.Signal();
}
auline void Broadcast() override
{
cond.Broadcast();
}
ConditionVariableInternal cond;
std::shared_ptr<IConditionMutex> mutex;
};
2023-08-21 18:17:05 +00:00
static const auto kSizeOfDummyCondVar = sizeof(ConditionVariableInternal);
}
#endif