|
Time Shield Library 2.0.0
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 39 of file ntp_client_pool_runner.hpp.
|
inlineexplicit |
Construct runner with a pool instance.
| pool | Pool instance to use. |
Definition at line 43 of file ntp_client_pool_runner.hpp.
|
inline |
Stop background thread on destruction.
Definition at line 47 of file ntp_client_pool_runner.hpp.
|
inlineprivate |
Definition at line 172 of file ntp_client_pool_runner.hpp.
|
inlinenoexcept |
Return number of failed measurement attempts.
Definition at line 138 of file ntp_client_pool_runner.hpp.
|
inline |
Wake the worker thread and request a measurement.
Definition at line 102 of file ntp_client_pool_runner.hpp.
|
inlinenoexcept |
Return whether last measurement updated the offset.
Definition at line 132 of file ntp_client_pool_runner.hpp.
|
inline |
Return copy of the most recent samples.
Definition at line 148 of file ntp_client_pool_runner.hpp.
|
inlinenoexcept |
Return realtime timestamp of last successful measurement.
Definition at line 144 of file ntp_client_pool_runner.hpp.
|
inlinenoexcept |
Return realtime timestamp of last measurement attempt.
Definition at line 141 of file ntp_client_pool_runner.hpp.
|
inlinenoexcept |
Return total number of measurement attempts.
Definition at line 135 of file ntp_client_pool_runner.hpp.
|
inline |
Perform one measurement immediately.
Definition at line 113 of file ntp_client_pool_runner.hpp.
|
inlinenoexcept |
Return last estimated offset in microseconds.
Definition at line 119 of file ntp_client_pool_runner.hpp.
|
inlineprivate |
Definition at line 151 of file ntp_client_pool_runner.hpp.
|
inlinenoexcept |
Return true when background thread is running.
Definition at line 98 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 82 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 55 of file ntp_client_pool_runner.hpp.
|
inline |
Stop background measurements.
Definition at line 87 of file ntp_client_pool_runner.hpp.
|
inlinenoexcept |
Return current UTC time in milliseconds using pool offset.
Definition at line 125 of file ntp_client_pool_runner.hpp.
|
inlinenoexcept |
Return current UTC time in seconds using pool offset.
Definition at line 128 of file ntp_client_pool_runner.hpp.
|
inlinenoexcept |
Return current UTC time in microseconds using pool offset.
Definition at line 122 of file ntp_client_pool_runner.hpp.
|
private |
Definition at line 202 of file ntp_client_pool_runner.hpp.
|
private |
Definition at line 203 of file ntp_client_pool_runner.hpp.
|
private |
Definition at line 211 of file ntp_client_pool_runner.hpp.
|
private |
Definition at line 207 of file ntp_client_pool_runner.hpp.
|
private |
Definition at line 205 of file ntp_client_pool_runner.hpp.
|
private |
Definition at line 206 of file ntp_client_pool_runner.hpp.
|
private |
Definition at line 209 of file ntp_client_pool_runner.hpp.
|
private |
Definition at line 213 of file ntp_client_pool_runner.hpp.
|
private |
Definition at line 212 of file ntp_client_pool_runner.hpp.
|
private |
Definition at line 210 of file ntp_client_pool_runner.hpp.
|
private |
Definition at line 198 of file ntp_client_pool_runner.hpp.
|
mutableprivate |
Definition at line 199 of file ntp_client_pool_runner.hpp.
|
private |
Definition at line 201 of file ntp_client_pool_runner.hpp.