VLink 2.0.0
A high-performance communication middleware
Loading...
Searching...
No Matches
vlink::DeadlineTimer Class Referencefinal

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

#include <deadline_timer.h>

Collaboration diagram for vlink::DeadlineTimer:

Public Types

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

Public Member Functions

 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.

Detailed Description

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.

Member Typedef Documentation

◆ Accuracy

Time precision. Aliases ElapsedTimer::Accuracy for convenience.

Constructor & Destructor Documentation

◆ 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.

Here is the caller graph for this function:

◆ 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()).

Parameters
intervalDuration until expiry, in accuracy units.
accuracyTime precision (default: ElapsedTimer::kMilli).
Here is the call graph for this function:

◆ DeadlineTimer() [3/4]

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

Copy constructor.

Parameters
otherThe source timer.
Here is the call graph for this function:

◆ DeadlineTimer() [4/4]

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

Move constructor.

Parameters
otherThe source timer (moved from).
Here is the call graph for this function:

◆ ~DeadlineTimer()

vlink::DeadlineTimer::~DeadlineTimer ( )
noexcept

Destructor.

Here is the call graph for this function:

Member Function Documentation

◆ 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()).

Returns
Absolute deadline in the configured accuracy units.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_accuracy()

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

Returns the time precision configured for this timer.

Returns
The Accuracy value set at construction.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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.

Returns
true if expired, false otherwise.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_valid()

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

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

Returns
true if the timer is valid (deadline != 0).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator=() [1/2]

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

Copy-assignment operator.

Parameters
otherThe source timer.
Returns
A reference to *this.
Here is the call graph for this function:

◆ operator=() [2/2]

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

Move-assignment operator.

Parameters
otherThe source timer.
Returns
A reference to *this.
Here is the call graph for this function:

◆ 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.

Returns
Remaining time in the configured accuracy units. A return value of 0 means invalid or expired.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ reset()

void vlink::DeadlineTimer::reset ( )
noexcept

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

After reset(), is_valid() returns false.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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.

Parameters
intervalDuration until expiry in the configured accuracy units.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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).

Parameters
abs_deadlineAbsolute monotonic timestamp of the deadline.
Here is the call graph for this function:
Here is the caller graph for this function:

The documentation for this class was generated from the following file: