AuroraRuntime/Include/Aurora/Loop/Loop.hpp
2022-04-05 14:46:19 +01:00

88 lines
3.2 KiB
C++

/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: Loop.hpp
Date: 2021-8-21
Author: Reece
Notes: This API class is specifically for kernel objects or similar userland schedular handles, this is not comparable to the async subsystem.
While you may drive low perf user facing apps and small services from this, other services should divide and conquer
* Allow the network subsystem to load balance sockets across a predefined amount of workers,
* Use semaphores instead of massive lengthy arrays of mutexes
* Use grouped long-polling LoopSources to convert kernel or waitable objects to a single time-polled loop source (freq based thread runners, alt to eEfficient)
***/
#pragma once
#include "ELoopSource.hpp"
#include "ILoopSource.hpp"
#include "ILoopSourceSubscriber.hpp"
#include "ILoopQueue.hpp"
namespace Aurora::Loop
{
/// @deprecated
AUKN_SYM AuList<AuSPtr<ILoopSource>> WaitMultipleOrObjects(const AuList<AuSPtr<ILoopSource>> &objects, AuUInt32 timeout);
struct ILSSemaphore : public ILoopSource
{
virtual bool AddOne() = 0;
};
struct ILSEvent : public ILoopSource
{
virtual bool Set() = 0;
virtual bool Reset() = 0;
};
struct ILSMutex : public ILoopSource
{
virtual bool Unlock() = 0;
};
struct IConditionVar : public ILoopSource
{
virtual bool Signal() = 0;
virtual bool Broadcast() = 0;
};
struct ITimer : public ILoopSource
{
virtual void UpdateTime(AuUInt64 absTimeMs) = 0;
virtual void Stop() = 0;
};
AUKN_SYM AuSPtr<IConditionVar> NewLSCondVar(const AuSPtr<Threading::IWaitable> &primitive);
AUKN_SYM AuSPtr<IConditionVar> NewLSCondVar(const AuSPtr<ILSMutex> &source);
AUKN_SYM AuSPtr<ITimer> NewLSTimer(AuUInt64 absTimeMs, AuUInt32 reschedMs = 0);
AUKN_SYM AuSPtr<ILSMutex> NewLSMutex();
AUKN_SYM AuSPtr<ILSEvent> NewLSEvent(bool triggerd = false, bool atomicRelease = true, bool permitMultipleTriggers = false);
AUKN_SYM AuSPtr<ILSSemaphore> NewLSSemaphore(AuUInt32 initialCount = 0);
AUKN_SYM AuSPtr<ILoopSource> NewLSOSHandle(AuUInt);
AUKN_SYM AuSPtr<ILoopSource> NewLSAsync(Async::WorkerPId_t workerPid);
AUKN_SYM AuSPtr<ILoopSource> NewLSFile(const AuSPtr<IO::FS::IAsyncTransaction> &fileTransaction);
AUKN_SYM AuSPtr<ILoopSource> NewLSWin32Source(bool dispatchMessages);
AUKN_SYM AuSPtr<ILoopSource> NewLSAppleSource();
#if defined(X_PROTOCOL)
static AuSPtr<ILoopSource> NewLSX11(Display *display)
{
return NewLSOSHandle(ConnectionNumber(display));
}
#endif
#if defined(AURORA_IS_POSIX_DERIVED)
static AuSPtr<ILoopSource> NewLSFd(int fd)
{
if (fd > 0) return {};
return NewLSOSHandle(fd);
}
#endif
#if defined(AURORA_IS_MODERNNT_DERIVED) && defined(_AU_SAW_WIN32_EARLY)
static AuSPtr<ILoopSource> NewLSHandle(HANDLE handle)
{
if (handle == INVALID_HANDLE_VALUE) return {};
return NewLSOSHandle(reinterpret_cast<AuUInt>(handle));
}
#endif
}