2022-03-10 15:35:01 +00:00
|
|
|
/***
|
|
|
|
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())
|
|
|
|
{
|
2023-11-05 03:31:54 +00:00
|
|
|
AuAtomicSub(&this->commitPending_, 1u);
|
2022-03-10 15:35:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-11 23:52:46 +00:00
|
|
|
bool AsyncLoop::AddCallback(const AuSPtr<AuLoop::ILoopSource> &source, const AuSPtr<AuLoop::ILoopSourceSubscriber> &subscriber)
|
2022-03-10 15:35:01 +00:00
|
|
|
{
|
|
|
|
auto ret = LoopQueue::AddCallback(source, subscriber);
|
|
|
|
if (ret)
|
|
|
|
{
|
2022-11-17 20:56:41 +00:00
|
|
|
Schedule();
|
2022-03-10 15:35:01 +00:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2022-06-11 23:52:46 +00:00
|
|
|
bool AsyncLoop::AddCallbackEx(const AuSPtr<AuLoop::ILoopSource> &source, const AuSPtr<AuLoop::ILoopSourceSubscriberEx> &subscriber)
|
2022-03-10 15:35:01 +00:00
|
|
|
{
|
|
|
|
auto ret = LoopQueue::AddCallbackEx(source, subscriber);
|
|
|
|
if (ret)
|
|
|
|
{
|
2022-11-17 20:56:41 +00:00
|
|
|
Schedule();
|
2022-03-10 15:35:01 +00:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2022-06-11 23:52:46 +00:00
|
|
|
bool AsyncLoop::AddCallback(const AuSPtr<AuLoop::ILoopSourceSubscriber> &subscriber)
|
2022-03-10 15:35:01 +00:00
|
|
|
{
|
|
|
|
auto ret = LoopQueue::AddCallback(subscriber);
|
|
|
|
if (ret)
|
|
|
|
{
|
2022-11-17 20:56:41 +00:00
|
|
|
Schedule();
|
2022-03-10 15:35:01 +00:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2022-11-17 20:56:41 +00:00
|
|
|
void AsyncLoop::Schedule()
|
2022-03-10 15:35:01 +00:00
|
|
|
{
|
2023-11-11 10:11:09 +00:00
|
|
|
if (AuThreads::GetThread() != this->pParent->thread.pThread.get())
|
2022-11-17 20:56:41 +00:00
|
|
|
{
|
2023-11-05 03:31:54 +00:00
|
|
|
AuAtomicAdd(&this->commitPending_, 1u);
|
2023-11-11 10:11:09 +00:00
|
|
|
this->pParent->sync.SetEvent();
|
2023-11-05 03:31:54 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->commitPending_ = 1;
|
2022-11-17 20:56:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AsyncLoop::CommitPending()
|
|
|
|
{
|
|
|
|
return this->commitPending_;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AsyncLoop::Commit()
|
|
|
|
{
|
|
|
|
Schedule();
|
2022-03-10 15:35:01 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|