/*** 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> WaitMultipleOrObjects(const AuList> &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 NewLSCondVar(const AuSPtr &primitive); AUKN_SYM AuSPtr NewLSCondVar(const AuSPtr &source); AUKN_SYM AuSPtr NewLSTimer(AuUInt64 absTimeMs, AuUInt32 reschedMs = 0); AUKN_SYM AuSPtr NewLSMutex(); AUKN_SYM AuSPtr NewLSEvent(bool triggerd = false, bool atomicRelease = true, bool permitMultipleTriggers = false); AUKN_SYM AuSPtr NewLSSemaphore(AuUInt32 initialCount = 0); AUKN_SYM AuSPtr NewLSOSHandle(AuUInt); AUKN_SYM AuSPtr NewLSAsync(Async::WorkerPId_t workerPid); AUKN_SYM AuSPtr NewLSFile(const AuSPtr &fileTransaction); AUKN_SYM AuSPtr NewLSWin32Source(bool dispatchMessages); AUKN_SYM AuSPtr NewLSAppleSource(); #if defined(X_PROTOCOL) static AuSPtr NewLSX11(Display *display) { return NewLSOSHandle(ConnectionNumber(display)); } #endif #if defined(AURORA_IS_POSIX_DERIVED) static AuSPtr NewLSFd(int fd) { if (fd > 0) return {}; return NewLSOSHandle(fd); } #endif #if defined(AURORA_IS_MODERNNT_DERIVED) && defined(_AU_SAW_WIN32_EARLY) static AuSPtr NewLSHandle(HANDLE handle) { if (handle == INVALID_HANDLE_VALUE) return {}; return NewLSOSHandle(reinterpret_cast(handle)); } #endif }