diff options
| author | Nicolas James <nj3ahxac@gmail.com> | 2026-04-08 14:04:03 +1000 |
|---|---|---|
| committer | Nicolas James <nj3ahxac@gmail.com> | 2026-04-08 14:04:03 +1000 |
| commit | 5566c5dff4d6430f704aeb66ca45615cb0df0176 (patch) | |
| tree | 523e784bd31d2908b5a7d3c13fdcf46b4ed3a4ab /src/atomic_time_point.cc | |
| parent | a67570bc468664627da48b4ebe22c7caad217732 (diff) | |
Reduce thread contention by introducing an atomic time point class - greatly reduces locking
Diffstat (limited to 'src/atomic_time_point.cc')
| -rw-r--r-- | src/atomic_time_point.cc | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/atomic_time_point.cc b/src/atomic_time_point.cc new file mode 100644 index 0000000..4aaef7f --- /dev/null +++ b/src/atomic_time_point.cc @@ -0,0 +1,27 @@ +#include "atomic_time_point.hh" + +#include <cassert> + +namespace low_latency { + +AtomicTimePoint::AtomicTimePoint() {} + +AtomicTimePoint::~AtomicTimePoint() {} + +bool AtomicTimePoint::has_value() const { + return this->count.load(std::memory_order_relaxed); +} + +std::chrono::steady_clock::time_point AtomicTimePoint::get() const { + const auto result = this->count.load(std::memory_order_relaxed); + assert(result); + using namespace std::chrono; + return steady_clock::time_point{steady_clock::duration{result}}; +} + +void AtomicTimePoint::set(const std::chrono::steady_clock::time_point target) { + this->count.store(target.time_since_epoch().count(), + std::memory_order_relaxed); +} + +} // namespace low_latency
\ No newline at end of file |
