Cache-line aligned atomic deadline counter with millisecond / microsecond / nanosecond precision.
More...
#include <deadline_timer.h>
Cache-line aligned atomic deadline counter with millisecond / microsecond / nanosecond precision.
Reuses ElapsedTimer::Accuracy for time precision. Reads and writes go through a single std::atomic<uint64_t> aligned to 64 bytes to avoid false sharing when several timers share a structure. An invalid (unset) timer stores 0 and never reports expiry.
◆ Accuracy
◆ DeadlineTimer() [1/4]
| vlink::DeadlineTimer::DeadlineTimer |
( |
| ) |
|
|
noexcept |
Constructs an invalid timer with no deadline set.
is_valid returns false and has_expired returns false until set_deadline or set_deadline_abs is called.
◆ DeadlineTimer() [2/4]
Constructs a timer that expires interval units in the future.
The absolute deadline is computed as the current monotonic timestamp plus interval. A non-positive interval leaves the timer invalid.
- Parameters
-
| interval | Duration until expiry in accuracy units. |
| accuracy | Precision of stored timestamps. Default: ElapsedTimer::kMilli. |
◆ DeadlineTimer() [3/4]
| vlink::DeadlineTimer::DeadlineTimer |
( |
const DeadlineTimer & |
other | ) |
|
|
noexcept |
Copy constructor; copies the stored deadline and accuracy.
- Parameters
-
◆ DeadlineTimer() [4/4]
Move constructor; equivalent to copy because the timer holds only POD state.
- Parameters
-
◆ ~DeadlineTimer()
| vlink::DeadlineTimer::~DeadlineTimer |
( |
| ) |
|
|
noexcept |
◆ deadline()
| uint64_t vlink::DeadlineTimer::deadline |
( |
| ) |
const |
|
noexcept |
Returns the stored absolute deadline timestamp.
- Returns
- Deadline value in the configured accuracy unit.
0 indicates an invalid timer.
◆ get_accuracy()
| Accuracy vlink::DeadlineTimer::get_accuracy |
( |
| ) |
const |
|
noexcept |
Returns the precision configured for this timer.
- Returns
- Accuracy unit chosen at construction.
◆ has_expired()
| bool vlink::DeadlineTimer::has_expired |
( |
| ) |
const |
|
noexcept |
Reports whether the current time has passed the stored deadline.
- Returns
true when expired; always false for invalid timers.
◆ is_valid()
| bool vlink::DeadlineTimer::is_valid |
( |
| ) |
const |
|
noexcept |
Reports whether a deadline has been set.
- Returns
true when deadline() is non-zero.
◆ operator=() [1/2]
Copy assignment; replaces the stored deadline and accuracy.
- Parameters
-
- Returns
- Reference to
*this.
◆ operator=() [2/2]
Move assignment; equivalent to copy assignment for this POD-state type.
- Parameters
-
- Returns
- Reference to
*this.
◆ remaining_time()
| int64_t vlink::DeadlineTimer::remaining_time |
( |
| ) |
const |
|
noexcept |
Returns the time remaining until the deadline.
Computed as (deadline - current_cpu_timestamp); clamped to 0 once the deadline has been reached or when the timer is invalid.
- Returns
- Remaining time in the configured accuracy unit;
0 when invalid or expired.
◆ reset()
| void vlink::DeadlineTimer::reset |
( |
| ) |
|
|
noexcept |
Resets the timer to the invalid state.
After reset, is_valid returns false and has_expired returns false.
◆ set_deadline()
| void vlink::DeadlineTimer::set_deadline |
( |
int64_t |
interval | ) |
|
|
noexcept |
Sets the deadline interval units after the current monotonic timestamp.
A non-positive interval clears the timer (equivalent to reset).
- Parameters
-
| interval | Duration until expiry in the configured accuracy unit. |
◆ set_deadline_abs()
| void vlink::DeadlineTimer::set_deadline_abs |
( |
uint64_t |
abs_deadline | ) |
|
|
noexcept |
Sets an absolute deadline timestamp directly.
abs_deadline must be expressed in the same unit and time base as the configured accuracy; obtain it via ElapsedTimer::get_cpu_timestamp(accuracy).
- Parameters
-
| abs_deadline | Absolute monotonic deadline. |
The documentation for this class was generated from the following file: