VLink 2.0.0
A high-performance communication middleware
载入中...
搜索中...
未找到
vlink::DeadlineTimer类 参考final

Atomic absolute-deadline timer for lock-free timeout detection. 更多...

#include <deadline_timer.h>

vlink::DeadlineTimer 的协作图:

Public 类型

using Accuracy = ElapsedTimer::Accuracy
 Time precision. Aliases ElapsedTimer::Accuracy for convenience.

Public 成员函数

 DeadlineTimer () noexcept
 Default constructor. Creates an invalid (unset) deadline.
 DeadlineTimer (int64_t interval, Accuracy accuracy=ElapsedTimer::kMilli) noexcept
 Constructs a DeadlineTimer that expires interval time units from now.
 DeadlineTimer (const DeadlineTimer &other) noexcept
 Copy constructor.
 DeadlineTimer (DeadlineTimer &&other) noexcept
 Move constructor.
 ~DeadlineTimer () noexcept
 Destructor.
DeadlineTimeroperator= (const DeadlineTimer &other) noexcept
 Copy-assignment operator.
DeadlineTimeroperator= (DeadlineTimer &&other) noexcept
 Move-assignment operator.
void set_deadline (int64_t interval) noexcept
 Sets the deadline to interval time units from now.
void set_deadline_abs (uint64_t abs_deadline) noexcept
 Sets an explicit absolute deadline timestamp.
void reset () noexcept
 Resets the deadline to 0, making the timer invalid again.
uint64_t deadline () const noexcept
 Returns the stored absolute deadline timestamp.
int64_t remaining_time () const noexcept
 Returns the time remaining until the deadline.
bool has_expired () const noexcept
 Returns true if the current time is past the stored deadline.
bool is_valid () const noexcept
 Returns true if the deadline has been explicitly set (non-zero).
Accuracy get_accuracy () const noexcept
 Returns the time precision configured for this timer.

详细描述

Atomic absolute-deadline timer for lock-free timeout detection.

Stores an absolute expiry time (monotonic CPU timestamp) in a 64-bit atomic. Concurrent has_expired() / remaining_time() reads from multiple threads are safe without external locking.

成员类型定义说明

◆ Accuracy

Time precision. Aliases ElapsedTimer::Accuracy for convenience.

构造及析构函数说明

◆ DeadlineTimer() [1/4]

vlink::DeadlineTimer::DeadlineTimer ( )
noexcept

Default constructor. Creates an invalid (unset) deadline.

is_valid() returns false and has_expired() returns false until set_deadline() or set_deadline_abs() is called.

这是这个函数的调用关系图:

◆ DeadlineTimer() [2/4]

vlink::DeadlineTimer::DeadlineTimer ( int64_t interval,
Accuracy accuracy = ElapsedTimer::kMilli )
explicitnoexcept

Constructs a DeadlineTimer that expires interval time units from now.

The absolute deadline is computed as the current monotonic timestamp plus interval. If interval <= 0 the timer is reset to the invalid state (equivalent to reset()).

参数
intervalDuration until expiry, in accuracy units.
accuracyTime precision (default: ElapsedTimer::kMilli).
函数调用图:

◆ DeadlineTimer() [3/4]

vlink::DeadlineTimer::DeadlineTimer ( const DeadlineTimer & other)
noexcept

Copy constructor.

参数
otherThe source timer.
函数调用图:

◆ DeadlineTimer() [4/4]

vlink::DeadlineTimer::DeadlineTimer ( DeadlineTimer && other)
noexcept

Move constructor.

参数
otherThe source timer (moved from).
函数调用图:

◆ ~DeadlineTimer()

vlink::DeadlineTimer::~DeadlineTimer ( )
noexcept

Destructor.

函数调用图:

成员函数说明

◆ deadline()

uint64_t vlink::DeadlineTimer::deadline ( ) const
nodiscardnoexcept

Returns the stored absolute deadline timestamp.

A value of 0 means the timer has not been set (see is_valid()).

返回
Absolute deadline in the configured accuracy units.
函数调用图:
这是这个函数的调用关系图:

◆ get_accuracy()

Accuracy vlink::DeadlineTimer::get_accuracy ( ) const
nodiscardnoexcept

Returns the time precision configured for this timer.

返回
The Accuracy value set at construction.
函数调用图:
这是这个函数的调用关系图:

◆ has_expired()

bool vlink::DeadlineTimer::has_expired ( ) const
nodiscardnoexcept

Returns true if the current time is past the stored deadline.

Equivalent to remaining_time() <= 0 when is_valid() is true. Always returns false for an unset (invalid) timer.

返回
true if expired, false otherwise.
函数调用图:
这是这个函数的调用关系图:

◆ is_valid()

bool vlink::DeadlineTimer::is_valid ( ) const
nodiscardnoexcept

Returns true if the deadline has been explicitly set (non-zero).

返回
true if the timer is valid (deadline != 0).
函数调用图:
这是这个函数的调用关系图:

◆ operator=() [1/2]

DeadlineTimer & vlink::DeadlineTimer::operator= ( const DeadlineTimer & other)
noexcept

Copy-assignment operator.

参数
otherThe source timer.
返回
A reference to *this.
函数调用图:

◆ operator=() [2/2]

DeadlineTimer & vlink::DeadlineTimer::operator= ( DeadlineTimer && other)
noexcept

Move-assignment operator.

参数
otherThe source timer.
返回
A reference to *this.
函数调用图:

◆ remaining_time()

int64_t vlink::DeadlineTimer::remaining_time ( ) const
nodiscardnoexcept

Returns the time remaining until the deadline.

Computed as (deadline - current_cpu_timestamp). Returns 0 when the timer is invalid or already expired.

返回
Remaining time in the configured accuracy units. A return value of 0 means invalid or expired.
函数调用图:
这是这个函数的调用关系图:

◆ reset()

void vlink::DeadlineTimer::reset ( )
noexcept

Resets the deadline to 0, making the timer invalid again.

After reset(), is_valid() returns false.

函数调用图:
这是这个函数的调用关系图:

◆ set_deadline()

void vlink::DeadlineTimer::set_deadline ( int64_t interval)
noexcept

Sets the deadline to interval time units from now.

Reads the current monotonic timestamp and adds interval to produce the absolute deadline. A value of 0 or less clears the timer and makes it invalid.

参数
intervalDuration until expiry in the configured accuracy units.
函数调用图:
这是这个函数的调用关系图:

◆ set_deadline_abs()

void vlink::DeadlineTimer::set_deadline_abs ( uint64_t abs_deadline)
noexcept

Sets an explicit absolute deadline timestamp.

The value must be in the same unit and time base as the Accuracy configured for this timer. Typically obtain it via ElapsedTimer::get_cpu_timestamp(accuracy).

参数
abs_deadlineAbsolute monotonic timestamp of the deadline.
函数调用图:
这是这个函数的调用关系图:

该类的文档由以下文件生成: