VLink  2.0.0
A high-performance communication middleware
timer.h 文件参考

MessageLoop-driven periodic or one-shot timer with priority support. 更多...

#include <atomic>
#include <cstdint>
#include <memory>
#include "./functional.h"
#include "./macros.h"
timer.h 的引用(Include)关系图:
此图展示该文件直接或间接的被哪些文件引用了:

浏览源代码.

class  vlink::Timer
 Periodic or one-shot timer that fires on an associated MessageLoop thread. 更多...
 

命名空间

 

详细描述

MessageLoop-driven periodic or one-shot timer with priority support.

vlink::Timer dispatches its callback on a MessageLoop thread, so the callback runs serially with every other task posted to the same loop and no additional synchronisation is required inside the callback body.

Timer modes determined by loop_count:

Mode loop_count value Behaviour
One-shot 1 Fires exactly once after one full interval
Counted 2 ... INT_MAX Fires the configured number of times
Repeating kInfinite (-1) Fires forever until stop() is called

Key features:

  • Strict mode: when the loop falls behind, missed ticks are dispatched immediately on the next iteration so the long-term cadence is preserved.
  • Configurable dispatch priority for use with kPriorityType message loops.
  • When interval_ms is 0 the internal interval clamps to kMinInterval (10000 ns = 10 us) to avoid pathological busy-spinning.
  • The static call_once() helper posts a fire-and-forget one-shot without managing a Timer object.
Lifecycle
Construct -> attach() (if not done at construction) -> start() -> repeated ticks -> stop() / restart() / destruction.
Example
vlink::Timer timer(&loop, 500, vlink::Timer::kInfinite, [] {
handle_tick();
});
timer.start();
loop.run();