Skip to content

Truly independent web browser

Everywhere: Remove manual round-up from timer intervals

Shannon Booth41026f47e6f9
diff --git a/Libraries/LibMedia/PlaybackStates/PlayingStateHandler.cpp b/Libraries/LibMedia/PlaybackStates/PlayingStateHandler.cpp
index 01577d32db6..af9d572f59d 100644
--- a/Libraries/LibMedia/PlaybackStates/PlayingStateHandler.cpp
+++ b/Libraries/LibMedia/PlaybackStates/PlayingStateHandler.cpp
@@ -80,7 +80,7 @@ void PlayingStateHandler::update_unticked_end_of_stream_timer()
}
auto delay_seconds = (latest_verified_end_time - now).to_seconds_f64() / playback_rate;
- m_unticked_end_of_stream_timer->restart(AK::Duration::from_milliseconds(max(1, AK::clamp_to<int>(AK::ceil(delay_seconds * 1'000.0)))));
+ m_unticked_end_of_stream_timer->restart(AK::Duration::from_seconds_f64(delay_seconds));
}
}
diff --git a/Libraries/LibMedia/Sinks/AudioPlaybackSink.cpp b/Libraries/LibMedia/Sinks/AudioPlaybackSink.cpp
index 27adf6f02ca..4e134e03f65 100644
--- a/Libraries/LibMedia/Sinks/AudioPlaybackSink.cpp
+++ b/Libraries/LibMedia/Sinks/AudioPlaybackSink.cpp
@@ -526,7 +526,7 @@ void AudioPlaybackSink::dispatch_waiting_status_once_played_out()
// Timers are imprecise, so this may fire early, in which case it waits for the remainder.
if (m_stream_state == StreamState::Playing) {
auto delay = AK::Duration::from_time_units(frames_until_played_out, 1, sample_specification.sample_rate());
- m_played_out_timer->start(AK::Duration::from_milliseconds(max(1, AK::clamp_to<int>(delay.to_milliseconds()))));
+ m_played_out_timer->start(delay);
}
return;
}
diff --git a/Services/AudioServer/PlaybackStreamMixer.cpp b/Services/AudioServer/PlaybackStreamMixer.cpp
index 9b5901eb720..e02cb01e1d0 100644
--- a/Services/AudioServer/PlaybackStreamMixer.cpp
+++ b/Services/AudioServer/PlaybackStreamMixer.cpp
@@ -214,7 +214,7 @@ void PlaybackStreamMixer::finish_drain_once_played(MixerClientId id, i64 played_
finish_drain(id);
return;
}
- auto timer = Core::Timer::create_single_shot(AK::Duration::from_milliseconds(max(1, AK::clamp_to<int>(remaining.to_milliseconds() + 1))), [this, id] {
+ auto timer = Core::Timer::create_single_shot(remaining, [this, id] {
m_drain_timers.remove(id);
finish_drain(id);
});
diff --git a/Services/Compositor/CaretBlinkTimer.cpp b/Services/Compositor/CaretBlinkTimer.cpp
index 0201ba8c97d..5ab742aeb59 100644
--- a/Services/Compositor/CaretBlinkTimer.cpp
+++ b/Services/Compositor/CaretBlinkTimer.cpp
@@ -62,8 +62,7 @@ void CaretBlinkTimer::schedule_next_blink()
? now_ns - *m_blink_cycle_start_time_ns
: 0;
auto delay_ns = Compositing::caret_blink_interval_ns - elapsed_ns % Compositing::caret_blink_interval_ns;
- auto delay_ms = max(static_cast<int>((delay_ns + 999'999) / 1'000'000), 1);
- m_timer->restart(AK::Duration::from_milliseconds(delay_ms));
+ m_timer->restart(AK::Duration::from_nanoseconds(delay_ns));
}
}
diff --git a/Services/Compositor/ContextState.cpp b/Services/Compositor/ContextState.cpp
index d550e8bdaf6..c25fa344e96 100644
--- a/Services/Compositor/ContextState.cpp
+++ b/Services/Compositor/ContextState.cpp
@@ -1593,9 +1593,7 @@ void ContextState::schedule_end_of_scroll_step_gestures(MonotonicTime now)
end_scroll_step_gestures_whose_input_ran_out(MonotonicTime::now());
});
}
- // The gesture has run out of input once the clock reads past the deadline.
- auto delay = max(*deadline - now, AK::Duration::zero()).to_milliseconds() + 1;
- m_scroll_step_gesture_input_timer->restart(AK::Duration::from_milliseconds(static_cast<int>(delay)));
+ m_scroll_step_gesture_input_timer->restart(max(*deadline - now, AK::Duration::zero()));
}
void ContextState::end_scroll_step_gestures_whose_input_ran_out(MonotonicTime now)
diff --git a/Services/Compositor/VSyncScheduler.cpp b/Services/Compositor/VSyncScheduler.cpp
index 51df7c36a76..1787ebe5d20 100644
--- a/Services/Compositor/VSyncScheduler.cpp
+++ b/Services/Compositor/VSyncScheduler.cpp
@@ -100,11 +100,9 @@ private:
advance_next_tick_time_past(now);
VERIFY(*m_next_tick_time > now);
- // NB: The timer is armed against a fixed display grid. Rounding the delay up avoids firing before the grid
- // point, and advancing by whole intervals keeps request and update latency from shifting later ticks.
- auto delay_nanoseconds = (*m_next_tick_time - now).to_nanoseconds();
- auto delay_milliseconds = (delay_nanoseconds + 999'999) / 1'000'000;
- m_timer->restart(AK::Duration::from_milliseconds(static_cast<int>(max<i64>(delay_milliseconds, 1))));
+ // NB: The timer is armed against a fixed display grid. Advancing by whole intervals keeps request and update
+ // latency from shifting later ticks.
+ m_timer->restart(*m_next_tick_time - now);
}
Function<void(MonotonicTime)> m_tick_callback;
diff --git a/Services/RequestServer/ConnectionFromClient.cpp b/Services/RequestServer/ConnectionFromClient.cpp
index 4bf65e0f95a..6a2c9987353 100644
--- a/Services/RequestServer/ConnectionFromClient.cpp
+++ b/Services/RequestServer/ConnectionFromClient.cpp
@@ -123,8 +123,7 @@ ConnectionFromClient::ConnectionFromClient(NonnullOwnPtr<IPC::Transport> transpo
m_timer = Core::Timer::create_single_shot(AK::Duration::from_milliseconds(0), [this] {
auto now = MonotonicTime::now();
if (m_curl_timer_due_at.has_value() && now < *m_curl_timer_due_at) {
- auto remaining_ms = (*m_curl_timer_due_at - now).to_milliseconds();
- m_timer->restart(AK::Duration::from_milliseconds(AK::clamp_to<int>(remaining_ms)));
+ m_timer->restart(*m_curl_timer_due_at - now);
return;
}
@@ -510,10 +509,7 @@ int ConnectionFromClient::on_timeout_callback(void*, long timeout_ms, void* user
// WARNING: do not call libcurl directly from within the callback itself when the timeout_ms value is zero, since
// it risks triggering an unpleasant recursive behavior that immediately calls another call to the callback with
// a zero timeout...
- //
- // Core::Timer intervals are ints, so wait for longer valid timeouts in chunks without calling libcurl before its
- // requested expire time.
- client->m_timer->restart(AK::Duration::from_milliseconds(AK::clamp_to<int>(timeout_ms)));
+ client->m_timer->restart(AK::Duration::from_milliseconds(timeout_ms));
}
// The timer callback should return 0 on success, and -1 on error.
diff --git a/Services/RequestServer/Request.cpp b/Services/RequestServer/Request.cpp
index 1ba20ac42b6..c8d0ad7cd75 100644
--- a/Services/RequestServer/Request.cpp
+++ b/Services/RequestServer/Request.cpp
@@ -1116,7 +1116,7 @@ void Request::wait_for_cache_timed_out()
auto idle_time = MonotonicTime::now() - *last_activity_time;
if (idle_time < s_wait_for_cache_timeout) {
auto time_until_stalled = min(s_wait_for_cache_timeout - idle_time, s_maximum_wait_for_cache - time_waited);
- m_wait_for_cache_timer->start(AK::Duration::from_milliseconds(max(static_cast<int>(time_until_stalled.to_milliseconds()), 1)));
+ m_wait_for_cache_timer->start(time_until_stalled);
return;
}
}
diff --git a/Services/WebContent/PageClient.cpp b/Services/WebContent/PageClient.cpp
index 29d7d9d2f63..d9bfdfd5ec1 100644
--- a/Services/WebContent/PageClient.cpp
+++ b/Services/WebContent/PageClient.cpp
@@ -693,7 +693,7 @@ void PageClient::schedule_local_rendering_opportunity()
}
m_frame_timer_purpose = FrameTimerPurpose::LocalFallback;
- m_frame_timer->restart(AK::Duration::from_milliseconds(static_cast<int>(AK::ceil(delay))));
+ m_frame_timer->restart(AK::Duration::from_seconds_f64(delay / 1000));
}
void PageClient::schedule_compositor_watchdog()
@@ -702,7 +702,7 @@ void PageClient::schedule_compositor_watchdog()
auto delay = 4.0 * m_last_rendering_opportunity_frame_interval;
m_compositor_watchdog_deadline = Web::HighResolutionTime::unsafe_shared_current_time() + delay;
m_frame_timer_purpose = FrameTimerPurpose::CompositorWatchdog;
- m_frame_timer->restart(AK::Duration::from_milliseconds(static_cast<int>(AK::ceil(delay))));
+ m_frame_timer->restart(AK::Duration::from_seconds_f64(delay / 1000));
}
void PageClient::frame_timer_fired()
@@ -728,7 +728,7 @@ void PageClient::frame_timer_fired()
// an earlier request satisfy the current request before its own watchdog deadline.
if (now < m_compositor_watchdog_deadline) {
m_frame_timer_purpose = FrameTimerPurpose::CompositorWatchdog;
- m_frame_timer->restart(AK::Duration::from_milliseconds(static_cast<int>(AK::ceil(m_compositor_watchdog_deadline - now))));
+ m_frame_timer->restart(AK::Duration::from_seconds_f64((m_compositor_watchdog_deadline - now) / 1000));
return;
}
// An opportunity IPC may already be waiting behind a long main-thread task when this timer becomes runnable.