mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
Everywhere: Use MonotonicTime instead of Duration
This is easily identifiable by anyone who uses Duration::now_monotonic, and any downstream users of that data.
This commit is contained in:
parent
b2e7b8cdff
commit
fc5cab5c21
Notes:
sideshowbarker
2024-07-17 20:22:04 +09:00
Author: https://github.com/kleinesfilmroellchen Commit: https://github.com/SerenityOS/serenity/commit/fc5cab5c21 Pull-request: https://github.com/SerenityOS/serenity/pull/17842 Reviewed-by: https://github.com/me-minus Reviewed-by: https://github.com/timschumi
29 changed files with 79 additions and 80 deletions
|
@ -916,14 +916,14 @@ void vdbg(StringView fmtstr, TypeErasedFormatParams& params, bool newline)
|
|||
#ifdef AK_OS_SERENITY
|
||||
# ifdef KERNEL
|
||||
if (Kernel::Processor::is_initialized() && TimeManagement::is_initialized()) {
|
||||
struct timespec ts = TimeManagement::the().monotonic_time(TimePrecision::Coarse).to_timespec();
|
||||
auto time = TimeManagement::the().monotonic_time(TimePrecision::Coarse);
|
||||
if (Kernel::Thread::current()) {
|
||||
auto& thread = *Kernel::Thread::current();
|
||||
thread.process().name().with([&](auto& process_name) {
|
||||
builder.appendff("{}.{:03} \033[34;1m[#{} {}({}:{})]\033[0m: ", ts.tv_sec, ts.tv_nsec / 1000000, Kernel::Processor::current_id(), process_name->view(), thread.pid().value(), thread.tid().value());
|
||||
builder.appendff("{}.{:03} \033[34;1m[#{} {}({}:{})]\033[0m: ", time.truncated_seconds(), time.nanoseconds_within_second() / 1000000, Kernel::Processor::current_id(), process_name->view(), thread.pid().value(), thread.tid().value());
|
||||
});
|
||||
} else {
|
||||
builder.appendff("{}.{:03} \033[34;1m[#{} Kernel]\033[0m: ", ts.tv_sec, ts.tv_nsec / 1000000, Kernel::Processor::current_id());
|
||||
builder.appendff("{}.{:03} \033[34;1m[#{} Kernel]\033[0m: ", time.truncated_seconds(), time.nanoseconds_within_second() / 1000000, Kernel::Processor::current_id());
|
||||
}
|
||||
} else {
|
||||
builder.appendff("\033[34;1m[Kernel]\033[0m: ");
|
||||
|
@ -968,18 +968,16 @@ void vdmesgln(StringView fmtstr, TypeErasedFormatParams& params)
|
|||
StringBuilder builder;
|
||||
|
||||
# ifdef AK_OS_SERENITY
|
||||
struct timespec ts = {};
|
||||
|
||||
if (TimeManagement::is_initialized()) {
|
||||
ts = TimeManagement::the().monotonic_time(TimePrecision::Coarse).to_timespec();
|
||||
auto time = TimeManagement::the().monotonic_time(TimePrecision::Coarse);
|
||||
|
||||
if (Kernel::Processor::is_initialized() && Kernel::Thread::current()) {
|
||||
auto& thread = *Kernel::Thread::current();
|
||||
thread.process().name().with([&](auto& process_name) {
|
||||
builder.appendff("{}.{:03} \033[34;1m[{}({}:{})]\033[0m: ", ts.tv_sec, ts.tv_nsec / 1000000, process_name->view(), thread.pid().value(), thread.tid().value());
|
||||
builder.appendff("{}.{:03} \033[34;1m[{}({}:{})]\033[0m: ", time.truncated_seconds(), time.nanoseconds_within_second() / 1000000, process_name->view(), thread.pid().value(), thread.tid().value());
|
||||
});
|
||||
} else {
|
||||
builder.appendff("{}.{:03} \033[34;1m[Kernel]\033[0m: ", ts.tv_sec, ts.tv_nsec / 1000000);
|
||||
builder.appendff("{}.{:03} \033[34;1m[Kernel]\033[0m: ", time.truncated_seconds(), time.nanoseconds_within_second() / 1000000);
|
||||
}
|
||||
} else {
|
||||
builder.appendff("\033[34;1m[Kernel]\033[0m: ");
|
||||
|
|
|
@ -328,12 +328,12 @@ ErrorOr<u32> Controller::get_pcm_output_sample_rate(size_t channel_index)
|
|||
|
||||
ErrorOr<void> wait_until(size_t delay_in_microseconds, size_t timeout_in_microseconds, Function<ErrorOr<bool>()> condition)
|
||||
{
|
||||
auto const timeout = Duration::from_microseconds(static_cast<i64>(timeout_in_microseconds));
|
||||
auto const& time_management = TimeManagement::the();
|
||||
// FIXME: Use monotonic time instead.
|
||||
u64 start_microseconds = time_management.now().offset_to_epoch().to_microseconds();
|
||||
auto start = time_management.monotonic_time(TimePrecision::Precise);
|
||||
while (!TRY(condition())) {
|
||||
microseconds_delay(delay_in_microseconds);
|
||||
if ((time_management.now().offset_to_epoch().to_microseconds() - start_microseconds) >= timeout_in_microseconds)
|
||||
if (time_management.monotonic_time(TimePrecision::Precise) - start >= timeout)
|
||||
return ETIMEDOUT;
|
||||
}
|
||||
return {};
|
||||
|
|
|
@ -25,9 +25,9 @@ namespace Kernel {
|
|||
|
||||
static void delay(i64 nanoseconds)
|
||||
{
|
||||
auto start = TimeManagement::the().monotonic_time().to_nanoseconds();
|
||||
auto end = start + nanoseconds;
|
||||
while (TimeManagement::the().monotonic_time().to_nanoseconds() < end)
|
||||
auto start = TimeManagement::the().monotonic_time();
|
||||
auto end = start + Duration::from_nanoseconds(nanoseconds);
|
||||
while (TimeManagement::the().monotonic_time() < end)
|
||||
Processor::pause();
|
||||
}
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ static u64 (*s_scheduler_current_time)();
|
|||
static u64 current_time_monotonic()
|
||||
{
|
||||
// We always need a precise timestamp here, we cannot rely on a coarse timestamp
|
||||
return (u64)TimeManagement::the().monotonic_time(TimePrecision::Precise).to_nanoseconds();
|
||||
return (u64)TimeManagement::the().monotonic_time(TimePrecision::Precise).nanoseconds();
|
||||
}
|
||||
|
||||
u64 TimeManagement::scheduler_current_time()
|
||||
|
@ -81,11 +81,11 @@ Duration TimeManagement::current_time(clockid_t clock_id) const
|
|||
{
|
||||
switch (clock_id) {
|
||||
case CLOCK_MONOTONIC:
|
||||
return monotonic_time(TimePrecision::Precise);
|
||||
return monotonic_time(TimePrecision::Precise).time_since_start({});
|
||||
case CLOCK_MONOTONIC_COARSE:
|
||||
return monotonic_time(TimePrecision::Coarse);
|
||||
return monotonic_time(TimePrecision::Coarse).time_since_start({});
|
||||
case CLOCK_MONOTONIC_RAW:
|
||||
return monotonic_time_raw();
|
||||
return monotonic_time_raw().time_since_start({});
|
||||
case CLOCK_REALTIME:
|
||||
return epoch_time(TimePrecision::Precise).offset_to_epoch();
|
||||
case CLOCK_REALTIME_COARSE:
|
||||
|
@ -110,7 +110,7 @@ void TimeManagement::set_epoch_time(UnixDateTime ts)
|
|||
m_remaining_epoch_time_adjustment = {};
|
||||
}
|
||||
|
||||
Duration TimeManagement::monotonic_time(TimePrecision precision) const
|
||||
MonotonicTime TimeManagement::monotonic_time(TimePrecision precision) const
|
||||
{
|
||||
// This is the time when last updated by an interrupt.
|
||||
u64 seconds;
|
||||
|
@ -145,7 +145,7 @@ Duration TimeManagement::monotonic_time(TimePrecision precision) const
|
|||
VERIFY(ticks < m_time_ticks_per_second);
|
||||
u64 ns = ((u64)ticks * 1000000000ull) / m_time_ticks_per_second;
|
||||
VERIFY(ns < 1000000000ull);
|
||||
return Duration::from_timespec({ (i64)seconds, (i32)ns });
|
||||
return MonotonicTime::from_hardware_time({}, seconds, ns);
|
||||
}
|
||||
|
||||
UnixDateTime TimeManagement::epoch_time(TimePrecision) const
|
||||
|
@ -162,7 +162,7 @@ UnixDateTime TimeManagement::epoch_time(TimePrecision) const
|
|||
|
||||
u64 TimeManagement::uptime_ms() const
|
||||
{
|
||||
auto mtime = monotonic_time().to_timespec();
|
||||
auto mtime = monotonic_time().time_since_start({}).to_timespec();
|
||||
// This overflows after 292 million years of uptime.
|
||||
// Since this is only used for performance timestamps and sys$times, that's probably enough.
|
||||
u64 ms = mtime.tv_sec * 1000ull;
|
||||
|
@ -539,7 +539,7 @@ void TimeManagement::update_time_page()
|
|||
auto& page = time_page();
|
||||
u32 update_iteration = AK::atomic_fetch_add(&page.update2, 1u, AK::MemoryOrder::memory_order_acquire);
|
||||
page.clocks[CLOCK_REALTIME_COARSE] = m_epoch_time.to_timespec();
|
||||
page.clocks[CLOCK_MONOTONIC_COARSE] = monotonic_time(TimePrecision::Coarse).to_timespec();
|
||||
page.clocks[CLOCK_MONOTONIC_COARSE] = monotonic_time(TimePrecision::Coarse).time_since_start({}).to_timespec();
|
||||
AK::atomic_store(&page.update1, update_iteration + 1u, AK::MemoryOrder::memory_order_release);
|
||||
}
|
||||
|
||||
|
|
|
@ -41,9 +41,10 @@ public:
|
|||
static u64 scheduler_current_time();
|
||||
|
||||
static ErrorOr<void> validate_clock_id(clockid_t);
|
||||
// This API cannot distinguish returned time types; prefer the clock-specific functions instead.
|
||||
Duration current_time(clockid_t) const;
|
||||
Duration monotonic_time(TimePrecision = TimePrecision::Coarse) const;
|
||||
Duration monotonic_time_raw() const
|
||||
MonotonicTime monotonic_time(TimePrecision = TimePrecision::Coarse) const;
|
||||
MonotonicTime monotonic_time_raw() const
|
||||
{
|
||||
// TODO: implement
|
||||
return monotonic_time(TimePrecision::Precise);
|
||||
|
|
|
@ -229,7 +229,7 @@ bool HexDocumentUndoCommand::merge_with(GUI::Command const& other)
|
|||
m_old[relative_start + i] = typed_other.m_old[i];
|
||||
}
|
||||
|
||||
m_timestamp = Duration::now_monotonic();
|
||||
m_timestamp = MonotonicTime::now();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -103,9 +103,9 @@ public:
|
|||
ErrorOr<void> try_add_changed_bytes(ByteBuffer old_values, ByteBuffer new_values);
|
||||
|
||||
private:
|
||||
bool commit_time_expired() const { return Duration::now_monotonic() - m_timestamp >= COMMAND_COMMIT_TIME; }
|
||||
bool commit_time_expired() const { return MonotonicTime::now() - m_timestamp >= COMMAND_COMMIT_TIME; }
|
||||
|
||||
Duration m_timestamp = Duration::now_monotonic();
|
||||
MonotonicTime m_timestamp = MonotonicTime::now();
|
||||
WeakPtr<HexDocument> m_document;
|
||||
size_t m_position;
|
||||
ByteBuffer m_old;
|
||||
|
|
|
@ -347,7 +347,7 @@ void MainWidget::save_to_file(String const& filename, NonnullOwnPtr<Core::File>
|
|||
if (sync_result.is_error()) {
|
||||
GUI::MessageBox::show_error(window(), DeprecatedString::formatted("Failed to save theme file: {}", sync_result.error()));
|
||||
} else {
|
||||
m_last_modified_time = Duration::now_monotonic();
|
||||
m_last_modified_time = MonotonicTime::now();
|
||||
set_path(filename.to_deprecated_string());
|
||||
window()->set_modified(false);
|
||||
}
|
||||
|
@ -643,7 +643,7 @@ ErrorOr<void> MainWidget::load_from_file(String const& filename, NonnullOwnPtr<C
|
|||
ENUMERATE_PATH_ROLES(__ENUMERATE_PATH_ROLE)
|
||||
#undef __ENUMERATE_PATH_ROLE
|
||||
|
||||
m_last_modified_time = Duration::now_monotonic();
|
||||
m_last_modified_time = MonotonicTime::now();
|
||||
window()->set_modified(false);
|
||||
return {};
|
||||
}
|
||||
|
|
|
@ -124,7 +124,7 @@ private:
|
|||
|
||||
Optional<DeprecatedString> m_path;
|
||||
Gfx::Palette m_current_palette;
|
||||
Duration m_last_modified_time { Duration::now_monotonic() };
|
||||
MonotonicTime m_last_modified_time { MonotonicTime::now() };
|
||||
|
||||
RefPtr<AlignmentModel> m_alignment_model;
|
||||
|
||||
|
|
|
@ -20,13 +20,12 @@ ElapsedTimer ElapsedTimer::start_new()
|
|||
void ElapsedTimer::start()
|
||||
{
|
||||
m_valid = true;
|
||||
m_origin_time = m_precise ? Duration::now_monotonic() : Duration::now_monotonic_coarse();
|
||||
m_origin_time = m_precise ? MonotonicTime::now() : MonotonicTime::now_coarse();
|
||||
}
|
||||
|
||||
void ElapsedTimer::reset()
|
||||
{
|
||||
m_valid = false;
|
||||
m_origin_time = {};
|
||||
}
|
||||
|
||||
i64 ElapsedTimer::elapsed_milliseconds() const
|
||||
|
@ -37,7 +36,7 @@ i64 ElapsedTimer::elapsed_milliseconds() const
|
|||
Duration ElapsedTimer::elapsed_time() const
|
||||
{
|
||||
VERIFY(is_valid());
|
||||
auto now = m_precise ? Duration::now_monotonic() : Duration::now_monotonic_coarse();
|
||||
auto now = m_precise ? MonotonicTime::now() : MonotonicTime::now_coarse();
|
||||
return now - m_origin_time;
|
||||
}
|
||||
|
||||
|
|
|
@ -32,10 +32,10 @@ public:
|
|||
return elapsed_milliseconds();
|
||||
}
|
||||
|
||||
Duration const& origin_time() const { return m_origin_time; }
|
||||
MonotonicTime const& origin_time() const { return m_origin_time; }
|
||||
|
||||
private:
|
||||
Duration m_origin_time {};
|
||||
MonotonicTime m_origin_time { MonotonicTime::now() };
|
||||
bool m_precise { false };
|
||||
bool m_valid { false };
|
||||
};
|
||||
|
|
|
@ -30,13 +30,13 @@ thread_local ThreadData* s_thread_data;
|
|||
struct EventLoopTimer {
|
||||
int timer_id { 0 };
|
||||
Duration interval;
|
||||
Duration fire_time;
|
||||
MonotonicTime fire_time { MonotonicTime::now_coarse() };
|
||||
bool should_reload { false };
|
||||
TimerShouldFireWhenNotVisible fire_when_not_visible { TimerShouldFireWhenNotVisible::No };
|
||||
WeakPtr<Object> owner;
|
||||
|
||||
void reload(Duration const& now) { fire_time = now + interval; }
|
||||
bool has_expired(Duration const& now) const { return now > fire_time; }
|
||||
void reload(MonotonicTime const& now) { fire_time = now + interval; }
|
||||
bool has_expired(MonotonicTime const& now) const { return now > fire_time; }
|
||||
};
|
||||
|
||||
struct ThreadData {
|
||||
|
@ -171,13 +171,13 @@ retry:
|
|||
|
||||
// Figure out how long to wait at maximum.
|
||||
// This mainly depends on the PumpMode and whether we have pending events, but also the next expiring timer.
|
||||
Duration now;
|
||||
MonotonicTime now = MonotonicTime::now_coarse();
|
||||
struct timeval timeout = { 0, 0 };
|
||||
bool should_wait_forever = false;
|
||||
if (mode == EventLoopImplementation::PumpMode::WaitForEvents && !has_pending_events) {
|
||||
auto next_timer_expiration = get_next_timer_expiration();
|
||||
if (next_timer_expiration.has_value()) {
|
||||
now = Duration::now_monotonic_coarse();
|
||||
now = MonotonicTime::now();
|
||||
auto computed_timeout = next_timer_expiration.value() - now;
|
||||
if (computed_timeout.is_negative())
|
||||
computed_timeout = Duration::zero();
|
||||
|
@ -231,7 +231,7 @@ try_select_again:
|
|||
}
|
||||
|
||||
if (!thread_data.timers.is_empty()) {
|
||||
now = Duration::now_monotonic_coarse();
|
||||
now = MonotonicTime::now_coarse();
|
||||
}
|
||||
|
||||
// Handle expired timers.
|
||||
|
@ -349,10 +349,10 @@ void EventLoopImplementationUnix::notify_forked_and_in_child()
|
|||
thread_data.pid = getpid();
|
||||
}
|
||||
|
||||
Optional<Duration> EventLoopManagerUnix::get_next_timer_expiration()
|
||||
Optional<MonotonicTime> EventLoopManagerUnix::get_next_timer_expiration()
|
||||
{
|
||||
auto now = Duration::now_monotonic_coarse();
|
||||
Optional<Duration> soonest {};
|
||||
auto now = MonotonicTime::now_coarse();
|
||||
Optional<MonotonicTime> soonest {};
|
||||
for (auto& it : ThreadData::the().timers) {
|
||||
auto& fire_time = it.value->fire_time;
|
||||
auto owner = it.value->owner.strong_ref();
|
||||
|
@ -490,7 +490,7 @@ int EventLoopManagerUnix::register_timer(Object& object, int milliseconds, bool
|
|||
auto timer = make<EventLoopTimer>();
|
||||
timer->owner = object;
|
||||
timer->interval = Duration::from_milliseconds(milliseconds);
|
||||
timer->reload(Duration::now_monotonic_coarse());
|
||||
timer->reload(MonotonicTime::now_coarse());
|
||||
timer->should_reload = should_reload;
|
||||
timer->fire_when_not_visible = fire_when_not_visible;
|
||||
int timer_id = thread_data.id_allocator.allocate();
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Time.h>
|
||||
#include <LibCore/EventLoopImplementation.h>
|
||||
|
||||
namespace Core {
|
||||
|
@ -28,7 +29,7 @@ public:
|
|||
virtual void unregister_signal(int handler_id) override;
|
||||
|
||||
void wait_for_events(EventLoopImplementation::PumpMode);
|
||||
static Optional<Duration> get_next_timer_expiration();
|
||||
static Optional<MonotonicTime> get_next_timer_expiration();
|
||||
|
||||
private:
|
||||
void dispatch_signal(int signal_number);
|
||||
|
|
|
@ -40,7 +40,7 @@ void Screensaver::mousedown_event(GUI::MouseEvent&)
|
|||
|
||||
void Screensaver::mousemove_event(GUI::MouseEvent& event)
|
||||
{
|
||||
auto now = AK::Duration::now_monotonic();
|
||||
auto now = MonotonicTime::now();
|
||||
if ((now - m_start_time).to_milliseconds() < mouse_tracking_delay_milliseconds)
|
||||
return;
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ public:
|
|||
|
||||
protected:
|
||||
Screensaver()
|
||||
: m_start_time(AK::Duration::now_monotonic())
|
||||
: m_start_time(MonotonicTime::now())
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,7 @@ private:
|
|||
void trigger_exit();
|
||||
|
||||
Optional<Gfx::IntPoint> m_mouse_origin;
|
||||
AK::Duration m_start_time;
|
||||
MonotonicTime m_start_time;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -63,12 +63,12 @@ ErrorOr<Dialog::ExecResult> MessageBox::try_show_error(Window* parent_window, St
|
|||
return TRY(try_show(parent_window, text, "Error"sv, GUI::MessageBox::Type::Error, GUI::MessageBox::InputType::OK));
|
||||
}
|
||||
|
||||
Dialog::ExecResult MessageBox::ask_about_unsaved_changes(Window* parent_window, StringView path, Optional<Duration> last_unmodified_timestamp)
|
||||
Dialog::ExecResult MessageBox::ask_about_unsaved_changes(Window* parent_window, StringView path, Optional<MonotonicTime> last_unmodified_timestamp)
|
||||
{
|
||||
return MUST(try_ask_about_unsaved_changes(parent_window, path, last_unmodified_timestamp));
|
||||
return MUST(try_ask_about_unsaved_changes(parent_window, path, move(last_unmodified_timestamp)));
|
||||
}
|
||||
|
||||
ErrorOr<Dialog::ExecResult> MessageBox::try_ask_about_unsaved_changes(Window* parent_window, StringView path, Optional<Duration> last_unmodified_timestamp)
|
||||
ErrorOr<Dialog::ExecResult> MessageBox::try_ask_about_unsaved_changes(Window* parent_window, StringView path, Optional<MonotonicTime> last_unmodified_timestamp)
|
||||
{
|
||||
StringBuilder builder;
|
||||
TRY(builder.try_append("Save changes to "sv));
|
||||
|
@ -79,7 +79,7 @@ ErrorOr<Dialog::ExecResult> MessageBox::try_ask_about_unsaved_changes(Window* pa
|
|||
TRY(builder.try_append(" before closing?"sv));
|
||||
|
||||
if (!path.is_empty() && last_unmodified_timestamp.has_value()) {
|
||||
auto age = (Duration::now_monotonic() - *last_unmodified_timestamp).to_seconds();
|
||||
auto age = (MonotonicTime::now() - *last_unmodified_timestamp).to_seconds();
|
||||
auto readable_time = human_readable_time(age);
|
||||
TRY(builder.try_appendff("\nLast saved {} ago.", readable_time));
|
||||
}
|
||||
|
|
|
@ -40,12 +40,12 @@ public:
|
|||
|
||||
static ExecResult show(Window* parent_window, StringView text, StringView title, Type type = Type::None, InputType input_type = InputType::OK);
|
||||
static ExecResult show_error(Window* parent_window, StringView text);
|
||||
static ExecResult ask_about_unsaved_changes(Window* parent_window, StringView path, Optional<Duration> last_unmodified_timestamp = {});
|
||||
static ExecResult ask_about_unsaved_changes(Window* parent_window, StringView path, Optional<MonotonicTime> last_unmodified_timestamp = {});
|
||||
|
||||
static ErrorOr<ExecResult> try_show(Badge<FileSystemAccessServer::ConnectionFromClient>, i32 window_server_client_id, i32 parent_window_id, StringView text, StringView title);
|
||||
static ErrorOr<ExecResult> try_show(Window* parent_window, StringView text, StringView title, Type type = Type::None, InputType input_type = InputType::OK);
|
||||
static ErrorOr<ExecResult> try_show_error(Window* parent_window, StringView text);
|
||||
static ErrorOr<ExecResult> try_ask_about_unsaved_changes(Window* parent_window, StringView path, Optional<Duration> last_unmodified_timestamp = {});
|
||||
static ErrorOr<ExecResult> try_ask_about_unsaved_changes(Window* parent_window, StringView path, Optional<MonotonicTime> last_unmodified_timestamp = {});
|
||||
|
||||
static ErrorOr<NonnullRefPtr<MessageBox>> create(Window* parent_window, StringView text, StringView title, Type type = Type::None, InputType input_type = InputType::OK);
|
||||
|
||||
|
|
|
@ -894,7 +894,7 @@ bool InsertTextCommand::merge_with(GUI::Command const& other)
|
|||
m_text = builder.to_deprecated_string();
|
||||
m_range.set_end(typed_other.m_range.end());
|
||||
|
||||
m_timestamp = Duration::now_monotonic();
|
||||
m_timestamp = MonotonicTime::now();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -994,7 +994,7 @@ bool RemoveTextCommand::merge_with(GUI::Command const& other)
|
|||
m_text = builder.to_deprecated_string();
|
||||
m_range.set_start(typed_other.m_range.start());
|
||||
|
||||
m_timestamp = Duration::now_monotonic();
|
||||
m_timestamp = MonotonicTime::now();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -228,9 +228,9 @@ public:
|
|||
}
|
||||
|
||||
protected:
|
||||
bool commit_time_expired() const { return Duration::now_monotonic() - m_timestamp >= COMMAND_COMMIT_TIME; }
|
||||
bool commit_time_expired() const { return MonotonicTime::now() - m_timestamp >= COMMAND_COMMIT_TIME; }
|
||||
|
||||
Duration m_timestamp = Duration::now_monotonic();
|
||||
MonotonicTime m_timestamp = MonotonicTime::now();
|
||||
TextDocument& m_document;
|
||||
TextDocument::Client const* m_client { nullptr };
|
||||
};
|
||||
|
|
|
@ -81,7 +81,7 @@ void UndoStack::set_current_unmodified()
|
|||
return;
|
||||
|
||||
m_clean_index = m_stack_index;
|
||||
m_last_unmodified_timestamp = Duration::now_monotonic();
|
||||
m_last_unmodified_timestamp = MonotonicTime::now();
|
||||
|
||||
if (on_state_change)
|
||||
on_state_change();
|
||||
|
|
|
@ -31,7 +31,7 @@ public:
|
|||
void set_current_unmodified();
|
||||
bool is_current_modified() const;
|
||||
|
||||
Optional<Duration> last_unmodified_timestamp() const { return m_last_unmodified_timestamp; }
|
||||
Optional<MonotonicTime> last_unmodified_timestamp() const { return m_last_unmodified_timestamp; }
|
||||
|
||||
void clear();
|
||||
|
||||
|
@ -44,7 +44,7 @@ private:
|
|||
Vector<NonnullOwnPtr<Command>> m_stack;
|
||||
size_t m_stack_index { 0 };
|
||||
Optional<size_t> m_clean_index;
|
||||
Optional<Duration> m_last_unmodified_timestamp;
|
||||
Optional<MonotonicTime> m_last_unmodified_timestamp;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -33,8 +33,8 @@ JS::ThrowCompletionOr<void> AgentObject::initialize(JS::Realm& realm)
|
|||
|
||||
JS_DEFINE_NATIVE_FUNCTION(AgentObject::monotonic_now)
|
||||
{
|
||||
auto time = Duration::now_monotonic();
|
||||
auto milliseconds = time.to_milliseconds();
|
||||
auto time = MonotonicTime::now();
|
||||
auto milliseconds = time.milliseconds();
|
||||
return Value(static_cast<double>(milliseconds));
|
||||
}
|
||||
|
||||
|
|
|
@ -67,7 +67,7 @@ DecoderErrorOr<NonnullOwnPtr<PlaybackManager>> PlaybackManager::create(NonnullOw
|
|||
},
|
||||
"Media Decoder"sv));
|
||||
|
||||
playback_manager->m_playback_handler = make<SeekingStateHandler>(*playback_manager, false, Time::zero(), SeekMode::Fast);
|
||||
playback_manager->m_playback_handler = make<SeekingStateHandler>(*playback_manager, false, Duration::zero(), SeekMode::Fast);
|
||||
DECODER_TRY_ALLOC(playback_manager->m_playback_handler->on_enter());
|
||||
|
||||
playback_manager->m_decode_thread->start();
|
||||
|
@ -217,7 +217,7 @@ void PlaybackManager::restart_playback()
|
|||
void PlaybackManager::decode_and_queue_one_sample()
|
||||
{
|
||||
#if PLAYBACK_MANAGER_DEBUG
|
||||
auto start_time = Duration::now_monotonic();
|
||||
auto start_time = MonotonicTime::now();
|
||||
#endif
|
||||
|
||||
FrameQueueItem item_to_enqueue;
|
||||
|
@ -292,7 +292,7 @@ void PlaybackManager::decode_and_queue_one_sample()
|
|||
|
||||
VERIFY(!item_to_enqueue.is_empty());
|
||||
#if PLAYBACK_MANAGER_DEBUG
|
||||
dbgln("Media Decoder: Sample at {}ms took {}ms to decode, queue contains ~{} items", item_to_enqueue.timestamp().to_milliseconds(), (Time::now_monotonic() - start_time).to_milliseconds(), m_frame_queue.weak_used());
|
||||
dbgln("Media Decoder: Sample at {}ms took {}ms to decode, queue contains ~{} items", item_to_enqueue.timestamp().to_milliseconds(), (MonotonicTime::now() - start_time).to_milliseconds(), m_frame_queue.weak_used());
|
||||
#endif
|
||||
|
||||
auto wait = [&] {
|
||||
|
@ -408,7 +408,7 @@ public:
|
|||
private:
|
||||
ErrorOr<void> on_enter() override
|
||||
{
|
||||
m_last_present_in_real_time = Duration::now_monotonic();
|
||||
m_last_present_in_real_time = MonotonicTime::now();
|
||||
return do_timed_state_update();
|
||||
}
|
||||
|
||||
|
@ -429,7 +429,7 @@ private:
|
|||
|
||||
Duration current_time() const override
|
||||
{
|
||||
return manager().m_last_present_in_media_time + (Duration::now_monotonic() - m_last_present_in_real_time);
|
||||
return manager().m_last_present_in_media_time + (MonotonicTime::now() - m_last_present_in_real_time);
|
||||
}
|
||||
|
||||
ErrorOr<void> do_timed_state_update() override
|
||||
|
@ -498,7 +498,7 @@ private:
|
|||
|
||||
// If we have a frame, send it for presentation.
|
||||
if (should_present_frame) {
|
||||
auto now = Duration::now_monotonic();
|
||||
auto now = MonotonicTime::now();
|
||||
manager().m_last_present_in_media_time += now - m_last_present_in_real_time;
|
||||
m_last_present_in_real_time = now;
|
||||
|
||||
|
@ -520,7 +520,7 @@ private:
|
|||
return {};
|
||||
}
|
||||
|
||||
Duration m_last_present_in_real_time = Duration::zero();
|
||||
MonotonicTime m_last_present_in_real_time = MonotonicTime::now_coarse();
|
||||
};
|
||||
|
||||
class PlaybackManager::PausedStateHandler : public PlaybackManager::PlaybackStateHandler {
|
||||
|
|
|
@ -1585,7 +1585,7 @@ WebIDL::ExceptionOr<void> HTMLMediaElement::dispatch_time_update_event()
|
|||
ScopeGuard guard { [this] { m_running_time_update_event_handler = false; } };
|
||||
m_running_time_update_event_handler = true;
|
||||
|
||||
m_last_time_update_event_time = Duration::now_monotonic();
|
||||
m_last_time_update_event_time = MonotonicTime::now();
|
||||
|
||||
dispatch_event(TRY(DOM::Event::create(realm(), HTML::EventNames::timeupdate)));
|
||||
return {};
|
||||
|
@ -1617,7 +1617,7 @@ void HTMLMediaElement::time_marches_on(TimeMarchesOnReason reason)
|
|||
auto dispatch_event = true;
|
||||
|
||||
if (m_last_time_update_event_time.has_value()) {
|
||||
auto time_since_last_event = Duration::now_monotonic() - *m_last_time_update_event_time;
|
||||
auto time_since_last_event = MonotonicTime::now() - *m_last_time_update_event_time;
|
||||
dispatch_event = time_since_last_event.to_milliseconds() > 250;
|
||||
}
|
||||
|
||||
|
|
|
@ -211,7 +211,7 @@ private:
|
|||
Optional<DOM::DocumentLoadEventDelayer> m_delaying_the_load_event;
|
||||
|
||||
bool m_running_time_update_event_handler { false };
|
||||
Optional<Duration> m_last_time_update_event_time;
|
||||
Optional<MonotonicTime> m_last_time_update_event_time;
|
||||
|
||||
JS::GCPtr<DOM::DocumentObserver> m_document_observer;
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ JS::GCPtr<NavigationTiming::PerformanceTiming> Performance::timing()
|
|||
|
||||
double Performance::time_origin() const
|
||||
{
|
||||
return static_cast<double>(m_timer.origin_time().to_milliseconds());
|
||||
return static_cast<double>(m_timer.origin_time().milliseconds());
|
||||
}
|
||||
|
||||
// https://w3c.github.io/user-timing/#mark-method
|
||||
|
|
|
@ -55,7 +55,7 @@ DOMHighResTimeStamp coarsened_shared_current_time(bool cross_origin_isolated_cap
|
|||
DOMHighResTimeStamp unsafe_shared_current_time()
|
||||
{
|
||||
// The unsafe shared current time must return the current value of the shared monotonic clock.
|
||||
return Duration::now_monotonic().to_nanoseconds() / 1e6;
|
||||
return MonotonicTime::now().truncated_seconds();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -329,7 +329,7 @@ ExecuteScriptResultSerialized execute_async_script(Web::Page& page, DeprecatedSt
|
|||
auto* window = page.top_level_browsing_context().active_window();
|
||||
auto& realm = window->realm();
|
||||
auto& vm = window->vm();
|
||||
auto start = Duration::now_monotonic();
|
||||
auto start = MonotonicTime::now();
|
||||
|
||||
// 4. Let promise be a new Promise.
|
||||
auto promise = JS::Promise::create(realm);
|
||||
|
@ -383,7 +383,7 @@ ExecuteScriptResultSerialized execute_async_script(Web::Page& page, DeprecatedSt
|
|||
vm.custom_data()->spin_event_loop_until([&] {
|
||||
if (script_promise.state() != JS::Promise::State::Pending)
|
||||
return true;
|
||||
if (timeout.has_value() && (Duration::now_monotonic() - start) > Duration::from_seconds(static_cast<i64>(*timeout)))
|
||||
if (timeout.has_value() && (MonotonicTime::now() - start) > Duration::from_seconds(static_cast<i64>(*timeout)))
|
||||
return true;
|
||||
return false;
|
||||
});
|
||||
|
|
|
@ -1958,7 +1958,7 @@ Gfx::IntRect WebDriverConnection::iconify_the_window()
|
|||
ErrorOr<JsonArray, Web::WebDriver::Error> WebDriverConnection::find(StartNodeGetter&& start_node_getter, Web::WebDriver::LocationStrategy using_, StringView value)
|
||||
{
|
||||
// 1. Let end time be the current time plus the session implicit wait timeout.
|
||||
auto end_time = Duration::now_monotonic() + Duration::from_milliseconds(static_cast<i64>(m_timeouts_configuration.implicit_wait_timeout));
|
||||
auto end_time = MonotonicTime::now() + Duration::from_milliseconds(static_cast<i64>(m_timeouts_configuration.implicit_wait_timeout));
|
||||
|
||||
// 2. Let location strategy be equal to using.
|
||||
auto location_strategy = using_;
|
||||
|
@ -1985,7 +1985,7 @@ ErrorOr<JsonArray, Web::WebDriver::Error> WebDriverConnection::find(StartNodeGet
|
|||
return true;
|
||||
|
||||
// 6. If elements returned is empty and the current time is less than end time return to step 4. Otherwise, continue to the next step.
|
||||
return maybe_elements.value()->length() != 0 || Duration::now_monotonic() >= end_time;
|
||||
return maybe_elements.value()->length() != 0 || MonotonicTime::now() >= end_time;
|
||||
});
|
||||
|
||||
auto elements = TRY(maybe_elements);
|
||||
|
|
Loading…
Reference in a new issue