|
Time Shield Library
C++ library for working with time
|
Background runner that periodically measures NTP offsets using a pool. More...
#include <ntp_client_pool_runner.hpp>
Public Member Functions | |
| BasicPoolRunner (PoolT pool=PoolT{}) | |
| Construct runner with a pool instance. | |
| ~BasicPoolRunner () | |
| Stop background thread on destruction. | |
| bool | start (std::chrono::milliseconds interval=std::chrono::seconds(30), bool measure_immediately=true) |
| Start periodic measurements on a background thread. | |
| bool | start (int interval_ms, bool measure_immediately=true) |
| Start periodic measurements using milliseconds. | |
| void | stop () |
| Stop background measurements. | |
| bool | running () const noexcept |
| Return true when background thread is running. | |
| bool | force_measure () |
| Wake the worker thread and request a measurement. | |
| bool | measure_now () |
| Perform one measurement immediately. | |
| int64_t | offset_us () const noexcept |
| Return last estimated offset in microseconds. | |
| int64_t | utc_time_us () const noexcept |
| Return current UTC time in microseconds using pool offset. | |
| int64_t | utc_time_ms () const noexcept |
| Return current UTC time in milliseconds using pool offset. | |
| int64_t | utc_time_sec () const noexcept |
| Return current UTC time in seconds using pool offset. | |
| bool | last_measure_ok () const noexcept |
| Return whether last measurement updated the offset. | |
| uint64_t | measure_count () const noexcept |
| Return total number of measurement attempts. | |
| uint64_t | fail_count () const noexcept |
| Return number of failed measurement attempts. | |
| int64_t | last_update_realtime_us () const noexcept |
| Return realtime timestamp of last measurement attempt. | |
| int64_t | last_success_realtime_us () const noexcept |
| Return realtime timestamp of last successful measurement. | |
| std::vector< NtpSample > | last_samples () const |
| Return copy of the most recent samples. | |
Private Member Functions | |
| void | run_loop (std::chrono::milliseconds interval, bool measure_immediately) |
| bool | do_measure () |
Private Attributes | |
| PoolT | m_pool |
| std::mutex | m_pool_mtx |
| std::thread | m_thread |
| std::condition_variable | m_cv |
| std::mutex | m_cv_mtx |
| std::atomic< bool > | m_is_running {false} |
| std::atomic< bool > | m_is_stop_requested {false} |
| std::atomic< bool > | m_is_force_requested {false} |
| std::atomic< bool > | m_last_measure_ok {false} |
| std::atomic< uint64_t > | m_measure_count {0} |
| std::atomic< uint64_t > | m_fail_count {0} |
| std::atomic< int64_t > | m_last_update_realtime_us {0} |
| std::atomic< int64_t > | m_last_success_realtime_us {0} |
Background runner that periodically measures NTP offsets using a pool.
Definition at line 40 of file ntp_client_pool_runner.hpp.
|
inlineexplicit |
Construct runner with a pool instance.
| pool | Pool instance to use. |
Definition at line 44 of file ntp_client_pool_runner.hpp.
|
inline |
Stop background thread on destruction.
Definition at line 48 of file ntp_client_pool_runner.hpp.
|
inlineprivate |
Definition at line 173 of file ntp_client_pool_runner.hpp.
|
inlinenoexcept |
Return number of failed measurement attempts.
Definition at line 139 of file ntp_client_pool_runner.hpp.
|
inline |
Wake the worker thread and request a measurement.
Definition at line 103 of file ntp_client_pool_runner.hpp.
|
inlinenoexcept |
Return whether last measurement updated the offset.
Definition at line 133 of file ntp_client_pool_runner.hpp.
|
inline |
Return copy of the most recent samples.
Definition at line 149 of file ntp_client_pool_runner.hpp.
|
inlinenoexcept |
Return realtime timestamp of last successful measurement.
Definition at line 145 of file ntp_client_pool_runner.hpp.
|
inlinenoexcept |
Return realtime timestamp of last measurement attempt.
Definition at line 142 of file ntp_client_pool_runner.hpp.
|
inlinenoexcept |
Return total number of measurement attempts.
Definition at line 136 of file ntp_client_pool_runner.hpp.
|
inline |
Perform one measurement immediately.
Definition at line 114 of file ntp_client_pool_runner.hpp.
|
inlinenoexcept |
Return last estimated offset in microseconds.
Definition at line 120 of file ntp_client_pool_runner.hpp.
|
inlineprivate |
Definition at line 152 of file ntp_client_pool_runner.hpp.
|
inlinenoexcept |
Return true when background thread is running.
Definition at line 99 of file ntp_client_pool_runner.hpp.
|
inline |
Start periodic measurements using milliseconds.
| interval_ms | Measurement interval in milliseconds. |
| measure_immediately | Measure before first sleep if true. |
Definition at line 83 of file ntp_client_pool_runner.hpp.
|
inline |
Start periodic measurements on a background thread.
| interval | Measurement interval. |
| measure_immediately | Measure before first sleep if true. |
Definition at line 56 of file ntp_client_pool_runner.hpp.
|
inline |
Stop background measurements.
Definition at line 88 of file ntp_client_pool_runner.hpp.
|
inlinenoexcept |
Return current UTC time in milliseconds using pool offset.
Definition at line 126 of file ntp_client_pool_runner.hpp.
|
inlinenoexcept |
Return current UTC time in seconds using pool offset.
Definition at line 129 of file ntp_client_pool_runner.hpp.
|
inlinenoexcept |
Return current UTC time in microseconds using pool offset.
Definition at line 123 of file ntp_client_pool_runner.hpp.
|
private |
Definition at line 203 of file ntp_client_pool_runner.hpp.
|
private |
Definition at line 204 of file ntp_client_pool_runner.hpp.
|
private |
Definition at line 212 of file ntp_client_pool_runner.hpp.
|
private |
Definition at line 208 of file ntp_client_pool_runner.hpp.
|
private |
Definition at line 206 of file ntp_client_pool_runner.hpp.
|
private |
Definition at line 207 of file ntp_client_pool_runner.hpp.
|
private |
Definition at line 210 of file ntp_client_pool_runner.hpp.
|
private |
Definition at line 214 of file ntp_client_pool_runner.hpp.
|
private |
Definition at line 213 of file ntp_client_pool_runner.hpp.
|
private |
Definition at line 211 of file ntp_client_pool_runner.hpp.
|
private |
Definition at line 199 of file ntp_client_pool_runner.hpp.
|
mutableprivate |
Definition at line 200 of file ntp_client_pool_runner.hpp.
|
private |
Definition at line 202 of file ntp_client_pool_runner.hpp.