15 #include <type_traits>
23 template<
typename T>
class Promise;
25 template<
typename T>
class WorkAwaitable;
27 template<
typename T>
class PostAwaitable;
82 class SLLooper :
public std::enable_shared_from_this<SLLooper>
159 template<
typename F,
typename... Args>
160 auto post_internal(F&& func, Args&&... args,
const char* file,
int line,
const char* funcname)
161 -> std::future<
decltype(func(args...))>;
180 template<
typename F,
typename... Args>
181 auto postDelayed_internal(int64_t delayMs, F&& func, Args&&... args,
const char* file,
int line,
const char* funcname)
182 -> std::future<
decltype(func(args...))>;
215 template<
typename F,
typename... Args>
216 auto post(F&& func, Args&&... args) -> std::future<
decltype(func(args...))>;
245 template<
typename F,
typename... Args>
246 auto postDelayed(int64_t delayMs, F&& func, Args&&... args) -> std::future<
decltype(func(args...))>;
308 template<
typename Func>
337 template<
typename Func>
338 auto postWork(Func&& func, std::chrono::milliseconds timeout)
374 template<
typename Func>
442 template<
typename Func>
499 Timer addTimer(std::function<
void()> callback, uint64_t delay_ms);
525 template<
typename Rep,
typename Period>
527 const std::chrono::duration<Rep, Period>& delay);
576 template<
typename Rep,
typename Period>
578 const std::chrono::duration<Rep, Period>& interval);
607 template<
typename Function>
609 -> std::enable_if_t<std::is_void_v<std::invoke_result_t<Function>>,
Timer>;
628 bool periodic, std::atomic<bool>* cancelled);
695 std::shared_ptr<EventQueue> mEventQueue;
696 std::atomic<bool> mStarted;
698 std::unique_ptr<TimerManager> mTimerManager;
Direct awaitable types for coroutine integration with SLLooper.
Unified event queue supporting messages and functions with timed execution.
Coroutine-based Task implementation for asynchronous execution.
High-performance timer management using Linux timerfd+epoll or sigev_thread.
RAII timer wrapper with move semantics for safe timer management.
Awaitable for delay operations.
Awaitable for executing function on main thread.
Type-safe promise for asynchronous result handling with continuation chaining.
Central event loop coordinator providing asynchronous task execution and timer management.
void updateTimerCancelledPtr(TimerId id, std::atomic< bool > *newPtr)
Update timer cancellation pointer for moved Timer objects.
bool restartTimerInternal(TimerId id, uint64_t delay_ms)
Restart existing timer with new delay.
Timer addTimer(std::function< void()> callback, uint64_t delay_ms)
Add one-shot timer with millisecond precision.
swt::Promise< T > createPromise()
Create a new promise object for manual result setting.
std::shared_ptr< EventQueue > getEventQueue()
Get access to the underlying event queue.
auto awaitPost(Func &&func) -> PostAwaitable< decltype(func())>
Execute function on main thread (co_await version)
DelayAwaitable awaitDelay(int delayMs)
Delay execution (co_await version)
auto postDelayed(int64_t delayMs, F &&func, Args &&... args) -> std::future< decltype(func(args...))>
Post function for delayed asynchronous execution.
static const char * getTimerBackend()
Get timer backend name.
auto postWork(Func &&func, std::chrono::milliseconds timeout) -> swt::Promise< decltype(func())>
Execute CPU-intensive task with timeout.
auto post(F &&func, Args &&... args) -> std::future< decltype(func(args...))>
Post function for immediate asynchronous execution.
~SLLooper()
Destructor - stops event loop and cleanup resources.
auto postDelayed_internal(int64_t delayMs, F &&func, Args &&... args, const char *file, int line, const char *funcname) -> std::future< decltype(func(args...))>
Internal postDelayed function with debug info for CPU-bound detection.
bool cancelTimerInternal(TimerId id)
Internal timer cancellation method.
Timer addPeriodicTimer(std::function< void()> callback, uint64_t interval_ms)
Add periodic timer with millisecond interval.
bool loop()
Run one iteration of the event loop.
Timer addPeriodicTimer(std::function< void()> callback, const std::chrono::duration< Rep, Period > &interval)
Add periodic timer with chrono interval.
auto awaitWork(Func &&func) -> WorkAwaitable< decltype(func())>
Execute function on background thread (co_await version)
void exit()
Request event loop to exit.
void initializeTimerManager()
Initialize TimerManager lazily.
auto post_internal(F &&func, Args &&... args, const char *file, int line, const char *funcname) -> std::future< decltype(func(args...))>
Internal post function with debug info for CPU-bound detection.
TimerId createTimerInternal(std::function< void()> callback, uint64_t delay_ms, bool periodic, std::atomic< bool > *cancelled)
Internal timer creation method.
size_t getActiveTimerCount()
Get count of active timers.
SLLooper()
Constructor - initializes message queue and starts event loop.
Timer addTimer(std::function< void()> callback, const std::chrono::duration< Rep, Period > &delay)
Add one-shot timer with chrono duration.
auto postWork(Func &&func) -> swt::Promise< decltype(func())>
Execute CPU-intensive task asynchronously.
bool hasTimerInternal(TimerId id)
Check if timer exists in internal management.
auto postWithTimeout(Function &&func, uint64_t timeout_ms) -> std::enable_if_t< std::is_void_v< std::invoke_result_t< Function > >, Timer >
Post function with timeout, returns Timer for cancellation.
static const char * getBackendName()
Get the name of the currently compiled timer backend.
RAII timer wrapper with boost-style API and move semantics.
Awaitable for executing work on background thread.
Software Timer namespace containing all timer-related classes.
uint64_t TimerId
Unique identifier type for timer instances.