Atomic absolute-deadline timer for lock-free timeout detection.
更多...
#include <deadline_timer.h>
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
◆ DeadlineTimer() [1/4]
| vlink::DeadlineTimer::DeadlineTimer |
( |
| ) |
|
|
noexcept |
◆ DeadlineTimer() [2/4]
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()).
- 参数
-
| interval | Duration until expiry, in accuracy units. |
| accuracy | Time precision (default: ElapsedTimer::kMilli). |
◆ DeadlineTimer() [3/4]
| vlink::DeadlineTimer::DeadlineTimer |
( |
const DeadlineTimer & | other | ) |
|
|
noexcept |
◆ DeadlineTimer() [4/4]
| vlink::DeadlineTimer::DeadlineTimer |
( |
DeadlineTimer && | other | ) |
|
|
noexcept |
Move constructor.
- 参数
-
| other | The source timer (moved from). |
◆ ~DeadlineTimer()
| vlink::DeadlineTimer::~DeadlineTimer |
( |
| ) |
|
|
noexcept |
◆ 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]
Copy-assignment operator.
- 参数
-
- 返回
- A reference to
*this.
◆ operator=() [2/2]
Move-assignment operator.
- 参数
-
- 返回
- 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.
- 参数
-
| interval | Duration 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_deadline | Absolute monotonic timestamp of the deadline. |
该类的文档由以下文件生成: