75 lines
1.7 KiB
C++
75 lines
1.7 KiB
C++
/***
|
|
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
File: ThreadWorkerQueueShim.cpp
|
|
Date: 2022-3-9
|
|
Author: Reece
|
|
***/
|
|
#include <Source/RuntimeInternal.hpp>
|
|
#include "Async.hpp"
|
|
#include "ThreadWorkerQueueShim.hpp"
|
|
|
|
namespace Aurora::Async
|
|
{
|
|
void AsyncLoop::OnFrame()
|
|
{
|
|
if (this->commitPending_)
|
|
{
|
|
if (LoopQueue::Commit())
|
|
{
|
|
this->commitPending_ = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
bool AsyncLoop::AddCallback(const AuSPtr<AuLoop::ILoopSource> &source, const AuSPtr<AuLoop::ILoopSourceSubscriber> &subscriber)
|
|
{
|
|
auto ret = LoopQueue::AddCallback(source, subscriber);
|
|
if (ret)
|
|
{
|
|
Schedule();
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
bool AsyncLoop::AddCallbackEx(const AuSPtr<AuLoop::ILoopSource> &source, const AuSPtr<AuLoop::ILoopSourceSubscriberEx> &subscriber)
|
|
{
|
|
auto ret = LoopQueue::AddCallbackEx(source, subscriber);
|
|
if (ret)
|
|
{
|
|
Schedule();
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
bool AsyncLoop::AddCallback(const AuSPtr<AuLoop::ILoopSourceSubscriber> &subscriber)
|
|
{
|
|
auto ret = LoopQueue::AddCallback(subscriber);
|
|
if (ret)
|
|
{
|
|
Schedule();
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
void AsyncLoop::Schedule()
|
|
{
|
|
this->commitPending_ = true;
|
|
|
|
if (AuThreads::GetThread() != this->pParent->threadObject.get())
|
|
{
|
|
this->pParent->parent.lock()->cvVariable->Broadcast();
|
|
}
|
|
}
|
|
|
|
bool AsyncLoop::CommitPending()
|
|
{
|
|
return this->commitPending_;
|
|
}
|
|
|
|
bool AsyncLoop::Commit()
|
|
{
|
|
Schedule();
|
|
return true;
|
|
}
|
|
} |