diff options
| author | Nicolas James <Eele1Ephe7uZahRie@tutanota.com> | 2026-02-21 16:11:13 +1100 |
|---|---|---|
| committer | Nicolas James <Eele1Ephe7uZahRie@tutanota.com> | 2026-02-21 16:11:13 +1100 |
| commit | 32a04a3554c583900d1c8452b958b71cc765eacf (patch) | |
| tree | a94673ba1ff67dc51db75948f1b3e089ae6fa33c | |
| parent | b7f8df7ba5a08fdf60f2966f0fdcdb06de99c575 (diff) | |
Don't wait inside spinlock
| -rw-r--r-- | src/layer_context.hh | 2 | ||||
| -rw-r--r-- | src/timestamp_pool.cc | 17 | ||||
| -rw-r--r-- | src/timestamp_pool.hh | 5 |
3 files changed, 4 insertions, 20 deletions
diff --git a/src/layer_context.hh b/src/layer_context.hh index 59861a7..44857d4 100644 --- a/src/layer_context.hh +++ b/src/layer_context.hh @@ -71,7 +71,7 @@ struct LayerContext final : public Context { assert(it != std::end(this->contexts)); using context_t = dispatch_context_t<DT>; - auto ptr = std::dynamic_pointer_cast<context_t>(it->second); + const auto ptr = std::dynamic_pointer_cast<context_t>(it->second); assert(ptr); return ptr; } 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<DeviceContext::Clock::time_point_t> 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; } diff --git a/src/timestamp_pool.hh b/src/timestamp_pool.hh index bfdad2e..8e336d5 100644 --- a/src/timestamp_pool.hh +++ b/src/timestamp_pool.hh @@ -60,11 +60,6 @@ class TimestampPool final { friend class TimestampPool; private: - // For our spinlock functions this is the period in which we sleep - // between attempts. - static constexpr auto SPINLOCK_MAX_DELAY = std::chrono::microseconds(1); - - private: const TimestampPool& timestamp_pool; const std::weak_ptr<QueryChunk> origin_chunk; |
