AuroraRuntime/Source/IO/AuIOProcessorItems.cpp

71 lines
1.8 KiB
C++
Raw Permalink Normal View History

/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: IOProcessorItems.cpp
Date: 2022-6-6
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include <Aurora/IO/IOExperimental.hpp>
#include "AuIOProcessorItem.hpp"
#include "AuIOProcessorItems.hpp"
#include "AuIOProcessor.hpp"
namespace Aurora::IO
{
bool IOProcessorItems::Init()
{
2022-06-14 01:14:51 +00:00
this->cvEvent = AuLoop::NewLSEvent(false, true, true);
return bool(this->cvEvent);
}
void IOProcessorItems::Deinit()
{
AU_LOCK_GUARD(this->mutex);
for (const auto &pItem : this->allItems)
{
pItem->pParent = nullptr;
}
}
bool IOProcessorItems::AddFrameTemp(const AuSPtr<IOProcessorItem> &item)
{
AU_TRY_LOCK_GUARD_RET_DEF(this->mutex);
return AuTryInsert(this->workSignaled, item);
}
bool IOProcessorItems::AddFrameOrFallback(const AuSPtr<IOProcessorItem> &item)
{
if (!AddFrameTemp(item))
{
AU_LOCK_GUARD(this->mutex2);
bool bInsert = AuTryInsert(this->workSignaled2, item);
if (this->cvEvent)
{
this->cvEvent->Set();
}
return bInsert;
}
return true;
}
bool IOProcessorItems::ScheduleFinish(const AuSPtr<IOProcessorItem> &item, bool unsafe)
{
AU_TRY_LOCK_GUARD_RET_DEF(this->mutex);
auto bRet = AuTryInsert(this->crossThreadAbort, AuMakePair(item, unsafe));
if (this->cvEvent)
{
this->cvEvent->Set();
}
return bRet;
}
AuList<AuSPtr<IOProcessorItem>> IOProcessorItems::GetBlockedSignals()
{
AU_LOCK_GUARD(this->mutex2);
return AuExchange(this->workSignaled2, {});
}
}