aboutsummaryrefslogtreecommitdiff
path: root/src/timestamp_pool.cc
diff options
context:
space:
mode:
authorNicolas James <Eele1Ephe7uZahRie@tutanota.com>2026-02-21 16:11:13 +1100
committerNicolas James <Eele1Ephe7uZahRie@tutanota.com>2026-02-21 16:11:13 +1100
commit32a04a3554c583900d1c8452b958b71cc765eacf (patch)
treea94673ba1ff67dc51db75948f1b3e089ae6fa33c /src/timestamp_pool.cc
parentb7f8df7ba5a08fdf60f2966f0fdcdb06de99c575 (diff)
Don't wait inside spinlock
Diffstat (limited to 'src/timestamp_pool.cc')
-rw-r--r--src/timestamp_pool.cc17
1 files changed, 3 insertions, 14 deletions
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;
}