59 lines
1.5 KiB
C++
59 lines
1.5 KiB
C++
/***
|
|
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
File: ConditionVariable.Win32.cpp
|
|
Date: 2021-6-12
|
|
Author: Reece
|
|
***/
|
|
#include <Source/RuntimeInternal.hpp>
|
|
#include "ConditionVariable.Generic.hpp"
|
|
|
|
#if !defined(_AURUNTIME_GENERICCV)
|
|
|
|
namespace Aurora::Threading::Primitives
|
|
{
|
|
ConditionVariableImpl::ConditionVariableImpl(const AuSPtr<IConditionMutex> &mutex) : mutex_(AuDynamicCast<IConditionMutexEx>(mutex))
|
|
{
|
|
InitializeConditionVariable(&winCond_);
|
|
}
|
|
|
|
AuSPtr<IConditionMutex> ConditionVariableImpl::GetMutex()
|
|
{
|
|
return mutex_;
|
|
}
|
|
|
|
bool ConditionVariableImpl::WaitForSignal(AuUInt32 timeout)
|
|
{
|
|
auto ok = SleepConditionVariableSRW(&winCond_, reinterpret_cast<PSRWLOCK>(mutex_->GetOSHandle()), timeout ? timeout : INFINITE, 0);
|
|
|
|
if (!ok)
|
|
{
|
|
SysAssert(GetLastError() == ERROR_TIMEOUT, "SleepConditionVariable failure");
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
void ConditionVariableImpl::Signal()
|
|
{
|
|
WakeConditionVariable(&winCond_);
|
|
}
|
|
|
|
void ConditionVariableImpl::Broadcast()
|
|
{
|
|
WakeAllConditionVariable(&winCond_);
|
|
}
|
|
|
|
AUKN_SYM IConditionVariable *ConditionVariableNew(const AuSPtr<IConditionMutex> &mutex)
|
|
{
|
|
return _new ConditionVariableImpl(mutex);
|
|
}
|
|
|
|
AUKN_SYM void ConditionVariableRelease(IConditionVariable *mutex)
|
|
{
|
|
AuSafeDelete<ConditionVariableImpl *>(mutex);
|
|
}
|
|
}
|
|
|
|
#endif |