Expand description
The core AtomicTime
for real-time and static clocks.
This module provides an atomic time abstraction that supports both real-time and static clocks. It ensures thread-safe operations and monotonic time retrieval with nanosecond precision.
§Modes
-
Real-time mode: The clock continuously syncs with system wall-clock time (via
SystemTime::now()
). To ensure strict monotonic increments across multiple threads, the internal updates use an atomic compare-and-exchange loop (time_since_epoch
). While this guarantees that every new timestamp is at least one nanosecond greater than the last, it may introduce higher contention if many threads call it heavily. -
Static mode: The clock is manually controlled via
AtomicTime::set_time
orAtomicTime::increment_time
, which can be useful for simulations or backtesting. You can switch modes at runtime usingAtomicTime::make_realtime
orAtomicTime::make_static
. In static mode, we use acquire/release semantics so that updates from one thread can be observed by another; however, we do not enforce strict global ordering for manual updates. If you need strong, multi-threaded ordering in static mode, you must coordinate higher-level synchronization yourself.
Structs§
- Atomic
Time - Represents an atomic timekeeping structure.
Statics§
- ATOMIC_
CLOCK_ REALTIME - Global atomic time in real-time mode for use across the system.
- ATOMIC_
CLOCK_ STATIC - Global atomic time in static mode for use across the system.
Functions§
- duration_
since_ unix_ epoch - Returns the duration since the UNIX epoch based on
SystemTime::now()
. - get_
atomic_ clock_ realtime - Returns a static reference to the global atomic clock in real-time mode.
- get_
atomic_ clock_ static - Returns a static reference to the global atomic clock in static mode.
- nanos_
since_ unix_ epoch - Returns the current UNIX time in nanoseconds, based on
SystemTime::now()
.