ladybird/Userland/Libraries/LibCore/ElapsedTimer.cpp
kleines Filmröllchen fc5cab5c21 Everywhere: Use MonotonicTime instead of Duration
This is easily identifiable by anyone who uses Duration::now_monotonic,
and any downstream users of that data.
2023-05-24 23:18:07 +02:00

44 lines
795 B
C++

/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/Assertions.h>
#include <AK/Time.h>
#include <LibCore/ElapsedTimer.h>
namespace Core {
ElapsedTimer ElapsedTimer::start_new()
{
ElapsedTimer timer;
timer.start();
return timer;
}
void ElapsedTimer::start()
{
m_valid = true;
m_origin_time = m_precise ? MonotonicTime::now() : MonotonicTime::now_coarse();
}
void ElapsedTimer::reset()
{
m_valid = false;
}
i64 ElapsedTimer::elapsed_milliseconds() const
{
return elapsed_time().to_milliseconds();
}
Duration ElapsedTimer::elapsed_time() const
{
VERIFY(is_valid());
auto now = m_precise ? MonotonicTime::now() : MonotonicTime::now_coarse();
return now - m_origin_time;
}
}