/*** Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved. File: ThreadWorkerQueueShim.cpp Date: 2022-3-9 Author: Reece ***/ #include #include "Async.hpp" #include "ThreadWorkerQueueShim.hpp" namespace Aurora::Async { void AsyncLoop::OnFrame() { if (this->commitPending_) { if (LoopQueue::Commit()) { AuAtomicSub(&this->commitPending_, 1u); } } } bool AsyncLoop::AddCallback(const AuSPtr &source, const AuSPtr &subscriber) { auto ret = LoopQueue::AddCallback(source, subscriber); if (ret) { Schedule(); } return ret; } bool AsyncLoop::AddCallbackEx(const AuSPtr &source, const AuSPtr &subscriber) { auto ret = LoopQueue::AddCallbackEx(source, subscriber); if (ret) { Schedule(); } return ret; } bool AsyncLoop::AddCallback(const AuSPtr &subscriber) { auto ret = LoopQueue::AddCallback(subscriber); if (ret) { Schedule(); } return ret; } void AsyncLoop::Schedule() { if (AuThreads::GetThread() != this->pParent->thread.pThread.get()) { AuAtomicAdd(&this->commitPending_, 1u); this->pParent->sync.SetEvent(); } else { this->commitPending_ = 1; } } bool AsyncLoop::CommitPending() { return this->commitPending_; } bool AsyncLoop::Commit() { Schedule(); return true; } }