|
VLink
2.0.0
A high-performance communication middleware
|
Cache-line aligned atomic deadline counter with millisecond / microsecond / nanosecond precision. 更多...
#include <deadline_timer.h>
Public 类型 | |
| using | Accuracy = ElapsedTimer::Accuracy |
Precision unit alias inherited from ElapsedTimer::Accuracy. 更多... | |
Public 成员函数 | |
| DeadlineTimer () noexcept | |
| Constructs an invalid timer with no deadline set. 更多... | |
| DeadlineTimer (int64_t interval, Accuracy accuracy=ElapsedTimer::kMilli) noexcept | |
Constructs a timer that expires interval units in the future. 更多... | |
| DeadlineTimer (const DeadlineTimer &other) noexcept | |
| Copy constructor; copies the stored deadline and accuracy. 更多... | |
| DeadlineTimer (DeadlineTimer &&other) noexcept | |
| Move constructor; equivalent to copy because the timer holds only POD state. 更多... | |
| ~DeadlineTimer () noexcept | |
| Destructor. 更多... | |
| DeadlineTimer & | operator= (const DeadlineTimer &other) noexcept |
| Copy assignment; replaces the stored deadline and accuracy. 更多... | |
| DeadlineTimer & | operator= (DeadlineTimer &&other) noexcept |
| Move assignment; equivalent to copy assignment for this POD-state type. 更多... | |
| void | set_deadline (int64_t interval) noexcept |
Sets the deadline interval units after the current monotonic timestamp. 更多... | |
| void | set_deadline_abs (uint64_t abs_deadline) noexcept |
| Sets an absolute deadline timestamp directly. 更多... | |
| void | reset () noexcept |
| Resets the timer to the invalid state. 更多... | |
| 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 |
| Reports whether the current time has passed the stored deadline. 更多... | |
| bool | is_valid () const noexcept |
| Reports whether a deadline has been set. 更多... | |
| Accuracy | get_accuracy () const noexcept |
| Returns the precision configured for this timer. 更多... | |
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.
Precision unit alias inherited from ElapsedTimer::Accuracy.
|
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.
|
explicitnoexcept |
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.
| interval | Duration until expiry in accuracy units. |
| accuracy | Precision of stored timestamps. Default: ElapsedTimer::kMilli. |
|
noexcept |
Copy constructor; copies the stored deadline and accuracy.
| other | Source timer. |
|
noexcept |
Move constructor; equivalent to copy because the timer holds only POD state.
| other | Source timer. |
|
noexcept |
Destructor.
|
noexcept |
Returns the stored absolute deadline timestamp.
0 indicates an invalid timer.
|
noexcept |
Returns the precision configured for this timer.
|
noexcept |
Reports whether the current time has passed the stored deadline.
true when expired; always false for invalid timers.
|
noexcept |
Reports whether a deadline has been set.
true when deadline() is non-zero.
|
noexcept |
Copy assignment; replaces the stored deadline and accuracy.
| other | Source timer. |
*this.
|
noexcept |
Move assignment; equivalent to copy assignment for this POD-state type.
| other | Source timer. |
*this.
|
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.
0 when invalid or expired.
|
noexcept |
Resets the timer to the invalid state.
After reset, is_valid returns false and has_expired returns false.
|
noexcept |
Sets the deadline interval units after the current monotonic timestamp.
A non-positive interval clears the timer (equivalent to reset).
| interval | Duration until expiry in the configured accuracy unit. |
|
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).
| abs_deadline | Absolute monotonic deadline. |