|
VLink 2.0.0
A high-performance communication middleware
|
POSIX monotonic-clock condition variable replacing std::condition_variable. 更多...
#include <condition_variable>#include <memory>#include <utility>命名空间 | |
| namespace | vlink |
类型定义 | |
| using | vlink::ConditionVariable = std::condition_variable |
| using | vlink::ConditionVariableAny = std::condition_variable_any |
| using | vlink::condition_variable = ConditionVariable |
| using | vlink::condition_variable_any = ConditionVariableAny |
POSIX monotonic-clock condition variable replacing std::condition_variable.
On older versions of GCC (and some libc implementations) std::condition_variable internally uses CLOCK_REALTIME for timed waits, which means that NTP adjustments or system-clock changes can cause spurious wakeups or missed timeouts. This header provides vlink::ConditionVariable and vlink::ConditionVariableAny as drop-in replacements that explicitly configure the underlying pthread_cond_t to use CLOCK_MONOTONIC via pthread_condattr_setclock.
On non-POSIX platforms (Windows) the types are aliased to their std:: counterparts because that bug does not apply there.
Type aliases for convenience:
The public API is identical to std::condition_variable and std::condition_variable_any respectively, so existing code can substitute the types without further changes.
ConditionVariable is backed by a raw pthread_cond_t initialised with CLOCK_MONOTONIC. It is not copyable or movable.ConditionVariableAny uses a shared internal ConditionVariable plus a std::mutex, making it compatible with any BasicLockable type.ceil() / ceil_impl() helper functions ensure that duration conversions always round up, preventing premature timeouts.