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