94 static constexpr
int kInfinite{-1};
119 explicit Timer(
class MessageLoop* message_loop, uint32_t interval_ms, int32_t loop_count = kInfinite,
129 explicit Timer(uint32_t interval_ms, int32_t loop_count = kInfinite,
Callback&& callback =
nullptr);
151 uint16_t priority = 0);
299 void begin_in_flight();
301 void end_in_flight();
303 void wait_for_idle();
307 void force_to_start();
309 void set_remain_loop_count(int32_t loop_count)
const;
311 void sub_remain_loop_count()
const;
313 void set_invoke_count(uint64_t invoke_count)
const;
315 uint64_t get_start_time()
const;
317 bool is_once_type()
const;
319 bool has_callback()
const;
323 std::shared_ptr<std::atomic_bool> get_alive_flag()
const;
327 std::unique_ptr<Impl> impl_;
328 static constexpr uint32_t kMinInterval{10'000U};
Serial task dispatcher with selectable queue backend and bounded timer registry.
Definition: message_loop.h:126
Periodic or one-shot timer that fires on an associated MessageLoop thread.
Definition: timer.h:84
~Timer()
Destructor. Calls stop() and detaches the timer.
static bool call_once(class MessageLoop *message_loop, uint32_t interval_ms, Callback &&callback, uint16_t priority=0)
Posts a fire-and-forget one-shot timer to a loop.
int32_t get_loop_count() const
Returns the configured total tick count.
Timer()
Constructs a detached timer with a 1000 ms interval and no callback.
uint64_t get_invoke_count() const
Returns the number of ticks dispatched since the last start() or restart().
void set_interval(uint32_t interval_ms)
Updates the tick interval.
Timer(uint32_t interval_ms, int32_t loop_count=kInfinite, Callback &&callback=nullptr)
Constructs a detached timer with explicit interval and loop count.
uint32_t get_interval() const
Returns the configured tick interval in milliseconds.
bool attach(class MessageLoop *message_loop)
Attaches the timer to message_loop.
bool detach()
Detaches the timer from its loop and stops it first.
uint16_t get_priority() const
Returns the dispatch priority used with kPriorityType loops.
bool is_strict() const
Reports whether strict catch-up mode is enabled.
void start(Callback &&callback=nullptr)
Arms the timer and starts dispatching ticks.
bool is_active() const
Reports whether the timer is currently armed.
Timer(class MessageLoop *message_loop, uint32_t interval_ms, int32_t loop_count=kInfinite, Callback &&callback=nullptr)
Constructs a fully configured timer attached to a loop.
void restart()
Resets the tick count and re-arms the timer as if newly started.
void set_priority(uint16_t priority)
Updates the dispatch priority.
void set_loop_count(int32_t loop_count)
Updates the total tick count.
class MessageLoop * get_message_loop() const
Returns the loop the timer is currently attached to.
Timer(class MessageLoop *message_loop)
Constructs a timer attached to message_loop with the default interval and no callback.
void stop()
Disarms the timer without destroying it.
void set_callback(Callback &&callback)
Replaces the callback dispatched on every tick.
int32_t get_remain_loop_count() const
Returns the number of ticks remaining before automatic stop.
void set_strict(bool strict)
Enables or disables strict catch-up firing.
Pool-backed type-erased callables: copyable vlink::Function and move-only vlink::MoveFunction.
Cross-platform macros for visibility, branch hints, copy prevention, singletons and string helpers.
#define VLINK_EXPORT
Definition: macros.h:81
#define VLINK_DISALLOW_COPY_AND_ASSIGN(classname)
Deletes the copy constructor and copy-assignment operator of classname.
Definition: macros.h:174