From 32a04a3554c583900d1c8452b958b71cc765eacf Mon Sep 17 00:00:00 2001 From: Nicolas James Date: Sat, 21 Feb 2026 16:11:13 +1100 Subject: Don't wait inside spinlock --- src/timestamp_pool.cc | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) (limited to 'src/timestamp_pool.cc') diff --git a/src/timestamp_pool.cc b/src/timestamp_pool.cc index a66bb2a..f6a572f 100644 --- a/src/timestamp_pool.cc +++ b/src/timestamp_pool.cc @@ -153,30 +153,19 @@ TimestampPool::Handle::get_time() { std::optional TimestampPool::Handle::get_time_spinlock( const DeviceContext::Clock::time_point_t& until) { - + auto time = this->get_time(); - if (time.has_value()) { // fast path, avoid now(). - return time; - } - - auto last = std::chrono::steady_clock::now(); for (; !time.has_value(); time = this->get_time()) { - if (const auto now = std::chrono::steady_clock::now(); now >= until) { break; } - - // Afaik no-op if it's too far behind, which is ideal. - std::this_thread::sleep_until(std::min(last + this->SPINLOCK_MAX_DELAY, until)); - - last = std::chrono::steady_clock::now(); } - return time; } DeviceContext::Clock::time_point_t TimestampPool::Handle::get_time_spinlock() { - const auto time = this->get_time_spinlock(DeviceContext::Clock::time_point_t::max()); + constexpr auto max = DeviceContext::Clock::time_point_t::max(); + const auto time = this->get_time_spinlock(max); assert(time.has_value()); return *time; } -- cgit v1.2.3