92 lines
3.6 KiB
C++
92 lines
3.6 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 : virtual ILoopSource
|
|
{
|
|
virtual bool AddOne() = 0;
|
|
};
|
|
|
|
struct ILSEvent : virtual ILoopSource
|
|
{
|
|
virtual bool Set() = 0;
|
|
virtual bool Reset() = 0;
|
|
};
|
|
|
|
struct ILSMutex : virtual ILoopSource
|
|
{
|
|
virtual bool Unlock() = 0;
|
|
};
|
|
|
|
struct IConditionVar : virtual ILoopSource
|
|
{
|
|
virtual bool Signal() = 0;
|
|
virtual bool Broadcast() = 0;
|
|
};
|
|
|
|
struct ITimer : virtual ILoopSource
|
|
{
|
|
virtual void UpdateTime(AuUInt64 absTimeMs) = 0;
|
|
virtual void UpdateTimeNs(AuUInt64 absTimeNs) = 0;
|
|
virtual void UpdateTickRateIfAny(AuUInt32 reschedStepMsOrZero = 0, AuUInt32 maxIterationsOrZero = 0) = 0;
|
|
virtual void UpdateTickRateIfAnyNs(AuUInt64 reschedStepNsOrZero = 0, AuUInt32 maxIterationsOrZero = 0) = 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 absStartTimeMs /*CurrentClockMS()*/, AuUInt32 reschedStepMsOrZero = 0, AuUInt32 maxIterationsOrZero = 0, bool bSingleshot = false /*cannot be changed*/);
|
|
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::IAsyncTransaction> &fileTransaction);
|
|
AUKN_SYM AuSPtr<ILoopSource> NewStdIn();
|
|
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
|
|
} |