diff --git a/server/driver/wivrn_session.cpp b/server/driver/wivrn_session.cpp index 703111e2..f146ae20 100644 --- a/server/driver/wivrn_session.cpp +++ b/server/driver/wivrn_session.cpp @@ -173,15 +173,13 @@ static auto lerp(std::chrono::duration a, std::chrono::duration weak_self) auto self = weak_self.lock(); if (self and not self->quit) { + if (std::chrono::steady_clock::now() > self->offset_expiration) { - std::lock_guard lock(self->mutex); - if (std::chrono::steady_clock::now() - self->offset_age > - std::chrono::seconds(5)) - { - to_headset::timesync_query timesync{}; - timesync.query = std::chrono::nanoseconds(os_monotonic_get_ns()); - self->connection.send_stream(timesync); - } + self->offset_expiration = std::chrono::steady_clock::now() + std::chrono::seconds(1); + to_headset::timesync_query timesync{}; + timesync.query = std::chrono::nanoseconds(os_monotonic_get_ns()); + self->connection.send_stream(timesync); } self->connection.poll(*self, 20); } diff --git a/server/driver/wivrn_session.h b/server/driver/wivrn_session.h index 137c2be0..9a66910d 100644 --- a/server/driver/wivrn_session.h +++ b/server/driver/wivrn_session.h @@ -55,7 +55,7 @@ class wivrn_session : public std::enable_shared_from_this std::unique_ptr right_hand; clock_offset offset; - std::chrono::steady_clock::time_point offset_age{}; + std::chrono::steady_clock::time_point offset_expiration{}; std::mutex csv_mutex; std::ofstream feedback_csv;