Jamie Reece Wilson
ceb67798f1
[+] IThreadPool::IncrementAbortFenceOnWorker [+] IThreadPool::QueryAbortFence [+] IThreadPool::QueryShouldAbort
81 lines
1.9 KiB
C++
81 lines
1.9 KiB
C++
/***
|
|
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
File: AsyncRunnable.hpp
|
|
Date: 2021-11-2
|
|
Author: Reece
|
|
***/
|
|
#pragma once
|
|
|
|
namespace Aurora::Async
|
|
{
|
|
struct IAsyncRunnable
|
|
{
|
|
inline virtual EWorkPrio GetPrio()
|
|
{
|
|
return EWorkPrio::eNormalPrio;
|
|
};
|
|
|
|
virtual void RunAsync() = 0;
|
|
|
|
virtual void CancelAsync() {}
|
|
|
|
inline virtual AuOptional<AuPair<AuUInt32, AuUInt32>> QueryFences()
|
|
{
|
|
return {};
|
|
}
|
|
};
|
|
|
|
struct AsyncFuncRunnable : IAsyncRunnable
|
|
{
|
|
AuFunction<void()> callback;
|
|
AuFunction<void()> fail;
|
|
AuThreadPrimitives::Mutex lock;
|
|
|
|
AsyncFuncRunnable(AuFunction<void()> &&callback) : callback(AuMove(callback))
|
|
{}
|
|
|
|
AsyncFuncRunnable(AuFunction<void()> &&callback, AuFunction<void()> &&fail) : callback(AuMove(callback)), fail(AuMove(fail))
|
|
{}
|
|
|
|
AsyncFuncRunnable(const AuFunction<void()> &callback) : callback(callback)
|
|
{}
|
|
|
|
AsyncFuncRunnable(const AuFunction<void()> &callback, const AuFunction<void()> &fail) : callback(callback), fail(fail)
|
|
{}
|
|
|
|
void RunAsync() override
|
|
{
|
|
AU_LOCK_GUARD(lock);
|
|
SysAssertDbgExp(callback, "Missing callback function");
|
|
try
|
|
{
|
|
callback();
|
|
}
|
|
catch (...)
|
|
{
|
|
Debug::PrintError();
|
|
}
|
|
fail = {};
|
|
callback = {};
|
|
}
|
|
|
|
void CancelAsync() override
|
|
{
|
|
AU_LOCK_GUARD(lock);
|
|
if (fail)
|
|
{
|
|
try
|
|
{
|
|
fail();
|
|
}
|
|
catch (...)
|
|
{
|
|
Debug::PrintError();
|
|
}
|
|
}
|
|
fail = {};
|
|
callback = {};
|
|
}
|
|
};
|
|
} |