AuroraRuntime/Include/Aurora/Async/Async.hpp
2023-12-08 13:03:14 +00:00

69 lines
2.2 KiB
C++

/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: Async.hpp
Date: 2021-7-14
Author: Reece
***/
#pragma once
#include "EWorkPriority.hpp"
#include "ETickType.hpp"
#include "AsyncTypes.hpp"
#include "IWorkItem.hpp"
#include "IWorkItemHandler.hpp"
#include "IAsyncTimer.hpp"
#include "IAsyncTimerCallback.hpp"
#include "IThreadPool.hpp"
#include "IAsyncApp.hpp"
namespace Aurora::Async
{
AUKN_SYM IAsyncApp * GetAsyncApp();
AUKN_SYM AuSPtr<IAsyncApp> GetSharedAsyncApp();
///
AUKN_SYM WorkerPId_t GetCurrentWorkerPId();
AUKN_SYM AuSPtr<IWorkItem> NewWorkItem(const WorkerId_t &worker, const AuSPtr<IWorkItemHandler> &task);
/**
* @brief Creates an asynchronous job object to be executed on an async runner
* @param worker A worker id pair. Supports AuAsync::kThreadIdAny to run on any runner within the group.
* @param task An interface to run the job/work/task in question
* @return
*/
AUKN_SYM AuSPtr<IWorkItem> NewWorkItem(const WorkerPId_t &worker, const AuSPtr<IWorkItemHandler> &task);
AUKN_SYM AuSPtr<IWorkItem> NewWorkFunction(const WorkerPId_t &worker, AuVoidFunc func);
AUKN_SYM AuSPtr<IAsyncTimer> NewTimer(AuUInt64 uPeriodNS,
const AuSPtr<IAsyncTimerCallback> &pCallback,
AuOptional<WorkerPId_t> workerPid = {},
AuOptional<AuUInt64> uStartTime = {});
AUKN_SYM AuSPtr<IAsyncTimer> NewTimer(AuUInt64 uPeriodNS,
const AuSupplierConsumer<bool, AuUInt64, AuUInt64, AuUInt64> &callback,
AuOptional<WorkerPId_t> workerPid = {},
AuOptional<AuUInt64> uStartTime = {});
static inline AuSPtr<IWorkItem> DispatchOn(const WorkerPId_t &worker, AuVoidFunc func)
{
auto pThat = NewWorkFunction(worker, func);
SysAssert(pThat);
return pThat->Dispatch();
}
AUKN_SYM AuSPtr<IWorkItem> NewFence();
AUKN_SYM AuSPtr<IThreadPool> NewThreadPool();
AUKN_SYM void SetMainThreadForSysPumpScheduling(WorkerPId_t pid);
}
#if !defined(_CPPSHARP)
#include "IPCPromises.hpp"
#endif