mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-23 08:00:20 +00:00
fc5cab5c21
This is easily identifiable by anyone who uses Duration::now_monotonic, and any downstream users of that data.
43 lines
795 B
C++
43 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;
|
|
}
|
|
|
|
}
|