mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-26 04:35:41 +03:00
AK: Rename Time to Duration
That's what this class really is; in fact that's what the first line of the comment says it is. This commit does not rename the main files, since those will contain other time-related classes in a little bit.
This commit is contained in:
parent
82ddc813d5
commit
213025f210
Notes:
sideshowbarker
2024-07-17 02:55:44 +09:00
Author: https://github.com/kleinesfilmroellchen Commit: https://github.com/SerenityOS/serenity/commit/213025f210 Pull-request: https://github.com/SerenityOS/serenity/pull/17842 Reviewed-by: https://github.com/me-minus Reviewed-by: https://github.com/timschumi
@ -8,12 +8,12 @@
|
||||
|
||||
namespace AK {
|
||||
|
||||
Time time_from_packed_dos(DOSPackedDate date, DOSPackedTime time)
|
||||
Duration time_from_packed_dos(DOSPackedDate date, DOSPackedTime time)
|
||||
{
|
||||
if (date.value == 0)
|
||||
return Time();
|
||||
return Duration();
|
||||
|
||||
return Time::from_timestamp(first_dos_year + date.year, date.month, date.day, time.hour, time.minute, time.second * 2, 0);
|
||||
return Duration::from_timestamp(first_dos_year + date.year, date.month, date.day, time.hour, time.minute, time.second * 2, 0);
|
||||
}
|
||||
|
||||
DOSPackedDate to_packed_dos_date(unsigned year, unsigned month, unsigned day)
|
||||
|
@ -33,7 +33,7 @@ static_assert(sizeof(DOSPackedDate) == 2);
|
||||
|
||||
inline constexpr u16 first_dos_year = 1980;
|
||||
|
||||
Time time_from_packed_dos(DOSPackedDate, DOSPackedTime);
|
||||
Duration time_from_packed_dos(DOSPackedDate, DOSPackedTime);
|
||||
DOSPackedDate to_packed_dos_date(unsigned year, unsigned month, unsigned day);
|
||||
DOSPackedTime to_packed_dos_time(unsigned hour, unsigned minute, unsigned second);
|
||||
|
||||
|
@ -27,6 +27,7 @@ class CountingStream;
|
||||
class DeprecatedFlyString;
|
||||
class DeprecatedString;
|
||||
class DeprecatedStringCodePointIterator;
|
||||
class Duration;
|
||||
class Error;
|
||||
class FlyString;
|
||||
class GenericLexer;
|
||||
@ -44,7 +45,6 @@ class String;
|
||||
class StringBuilder;
|
||||
class StringImpl;
|
||||
class StringView;
|
||||
class Time;
|
||||
class URL;
|
||||
class Utf16View;
|
||||
class Utf32CodePointIterator;
|
||||
@ -163,6 +163,7 @@ using AK::DeprecatedFlyString;
|
||||
using AK::DeprecatedString;
|
||||
using AK::DeprecatedStringCodePointIterator;
|
||||
using AK::DoublyLinkedList;
|
||||
using AK::Duration;
|
||||
using AK::Error;
|
||||
using AK::ErrorOr;
|
||||
using AK::FixedArray;
|
||||
@ -194,7 +195,6 @@ using AK::String;
|
||||
using AK::StringBuilder;
|
||||
using AK::StringImpl;
|
||||
using AK::StringView;
|
||||
using AK::Time;
|
||||
using AK::Traits;
|
||||
using AK::URL;
|
||||
using AK::Utf16View;
|
||||
|
74
AK/Time.cpp
74
AK/Time.cpp
@ -38,31 +38,31 @@ unsigned day_of_week(int year, unsigned month, int day)
|
||||
return (year + year / 4 - year / 100 + year / 400 + seek_table[month - 1] + day) % 7;
|
||||
}
|
||||
|
||||
Time Time::from_ticks(clock_t ticks, time_t ticks_per_second)
|
||||
Duration Duration::from_ticks(clock_t ticks, time_t ticks_per_second)
|
||||
{
|
||||
auto secs = ticks % ticks_per_second;
|
||||
|
||||
i32 nsecs = 1'000'000'000 * (ticks - (ticks_per_second * secs)) / ticks_per_second;
|
||||
i32 extra_secs = sane_mod(nsecs, 1'000'000'000);
|
||||
return Time::from_half_sanitized(secs, extra_secs, nsecs);
|
||||
return Duration::from_half_sanitized(secs, extra_secs, nsecs);
|
||||
}
|
||||
|
||||
Time Time::from_timespec(const struct timespec& ts)
|
||||
Duration Duration::from_timespec(const struct timespec& ts)
|
||||
{
|
||||
i32 nsecs = ts.tv_nsec;
|
||||
i32 extra_secs = sane_mod(nsecs, 1'000'000'000);
|
||||
return Time::from_half_sanitized(ts.tv_sec, extra_secs, nsecs);
|
||||
return Duration::from_half_sanitized(ts.tv_sec, extra_secs, nsecs);
|
||||
}
|
||||
|
||||
Time Time::from_timeval(const struct timeval& tv)
|
||||
Duration Duration::from_timeval(const struct timeval& tv)
|
||||
{
|
||||
i32 usecs = tv.tv_usec;
|
||||
i32 extra_secs = sane_mod(usecs, 1'000'000);
|
||||
VERIFY(0 <= usecs && usecs < 1'000'000);
|
||||
return Time::from_half_sanitized(tv.tv_sec, extra_secs, usecs * 1'000);
|
||||
return Duration::from_half_sanitized(tv.tv_sec, extra_secs, usecs * 1'000);
|
||||
}
|
||||
|
||||
i64 Time::to_truncated_seconds() const
|
||||
i64 Duration::to_truncated_seconds() const
|
||||
{
|
||||
VERIFY(m_nanoseconds < 1'000'000'000);
|
||||
if (m_seconds < 0 && m_nanoseconds) {
|
||||
@ -72,7 +72,7 @@ i64 Time::to_truncated_seconds() const
|
||||
return m_seconds;
|
||||
}
|
||||
|
||||
i64 Time::to_truncated_milliseconds() const
|
||||
i64 Duration::to_truncated_milliseconds() const
|
||||
{
|
||||
VERIFY(m_nanoseconds < 1'000'000'000);
|
||||
Checked<i64> milliseconds((m_seconds < 0) ? m_seconds + 1 : m_seconds);
|
||||
@ -91,7 +91,7 @@ i64 Time::to_truncated_milliseconds() const
|
||||
return m_seconds < 0 ? -0x8000'0000'0000'0000LL : 0x7fff'ffff'ffff'ffffLL;
|
||||
}
|
||||
|
||||
i64 Time::to_truncated_microseconds() const
|
||||
i64 Duration::to_truncated_microseconds() const
|
||||
{
|
||||
VERIFY(m_nanoseconds < 1'000'000'000);
|
||||
Checked<i64> microseconds((m_seconds < 0) ? m_seconds + 1 : m_seconds);
|
||||
@ -110,7 +110,7 @@ i64 Time::to_truncated_microseconds() const
|
||||
return m_seconds < 0 ? -0x8000'0000'0000'0000LL : 0x7fff'ffff'ffff'ffffLL;
|
||||
}
|
||||
|
||||
i64 Time::to_seconds() const
|
||||
i64 Duration::to_seconds() const
|
||||
{
|
||||
VERIFY(m_nanoseconds < 1'000'000'000);
|
||||
if (m_seconds >= 0 && m_nanoseconds) {
|
||||
@ -121,7 +121,7 @@ i64 Time::to_seconds() const
|
||||
return m_seconds;
|
||||
}
|
||||
|
||||
i64 Time::to_milliseconds() const
|
||||
i64 Duration::to_milliseconds() const
|
||||
{
|
||||
VERIFY(m_nanoseconds < 1'000'000'000);
|
||||
Checked<i64> milliseconds((m_seconds < 0) ? m_seconds + 1 : m_seconds);
|
||||
@ -138,7 +138,7 @@ i64 Time::to_milliseconds() const
|
||||
return m_seconds < 0 ? -0x8000'0000'0000'0000LL : 0x7fff'ffff'ffff'ffffLL;
|
||||
}
|
||||
|
||||
i64 Time::to_microseconds() const
|
||||
i64 Duration::to_microseconds() const
|
||||
{
|
||||
VERIFY(m_nanoseconds < 1'000'000'000);
|
||||
Checked<i64> microseconds((m_seconds < 0) ? m_seconds + 1 : m_seconds);
|
||||
@ -155,7 +155,7 @@ i64 Time::to_microseconds() const
|
||||
return m_seconds < 0 ? -0x8000'0000'0000'0000LL : 0x7fff'ffff'ffff'ffffLL;
|
||||
}
|
||||
|
||||
i64 Time::to_nanoseconds() const
|
||||
i64 Duration::to_nanoseconds() const
|
||||
{
|
||||
VERIFY(m_nanoseconds < 1'000'000'000);
|
||||
Checked<i64> nanoseconds((m_seconds < 0) ? m_seconds + 1 : m_seconds);
|
||||
@ -170,13 +170,13 @@ i64 Time::to_nanoseconds() const
|
||||
return m_seconds < 0 ? -0x8000'0000'0000'0000LL : 0x7fff'ffff'ffff'ffffLL;
|
||||
}
|
||||
|
||||
timespec Time::to_timespec() const
|
||||
timespec Duration::to_timespec() const
|
||||
{
|
||||
VERIFY(m_nanoseconds < 1'000'000'000);
|
||||
return { static_cast<time_t>(m_seconds), static_cast<long>(m_nanoseconds) };
|
||||
}
|
||||
|
||||
timeval Time::to_timeval() const
|
||||
timeval Duration::to_timeval() const
|
||||
{
|
||||
VERIFY(m_nanoseconds < 1'000'000'000);
|
||||
// This is done because winsock defines tv_sec and tv_usec as long, and Linux64 as long int.
|
||||
@ -185,7 +185,7 @@ timeval Time::to_timeval() const
|
||||
return { static_cast<sec_type>(m_seconds), static_cast<usec_type>(m_nanoseconds) / 1000 };
|
||||
}
|
||||
|
||||
Time Time::operator+(Time const& other) const
|
||||
Duration Duration::operator+(Duration const& other) const
|
||||
{
|
||||
VERIFY(m_nanoseconds < 1'000'000'000);
|
||||
VERIFY(other.m_nanoseconds < 1'000'000'000);
|
||||
@ -209,7 +209,7 @@ Time Time::operator+(Time const& other) const
|
||||
other_secs += 1;
|
||||
} else {
|
||||
/* If *both* are INT64_MAX, then adding them will overflow in any case. */
|
||||
return Time::max();
|
||||
return Duration::max();
|
||||
}
|
||||
}
|
||||
|
||||
@ -217,46 +217,46 @@ Time Time::operator+(Time const& other) const
|
||||
new_secs += other_secs;
|
||||
if (new_secs.has_overflow()) {
|
||||
if (other_secs > 0)
|
||||
return Time::max();
|
||||
return Duration::max();
|
||||
else
|
||||
return Time::min();
|
||||
return Duration::min();
|
||||
}
|
||||
|
||||
return Time { new_secs.value(), new_nsecs };
|
||||
return Duration { new_secs.value(), new_nsecs };
|
||||
}
|
||||
|
||||
Time& Time::operator+=(Time const& other)
|
||||
Duration& Duration::operator+=(Duration const& other)
|
||||
{
|
||||
*this = *this + other;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Time Time::operator-(Time const& other) const
|
||||
Duration Duration::operator-(Duration const& other) const
|
||||
{
|
||||
VERIFY(m_nanoseconds < 1'000'000'000);
|
||||
VERIFY(other.m_nanoseconds < 1'000'000'000);
|
||||
|
||||
if (other.m_nanoseconds)
|
||||
return *this + Time((i64) ~(u64)other.m_seconds, 1'000'000'000 - other.m_nanoseconds);
|
||||
return *this + Duration((i64) ~(u64)other.m_seconds, 1'000'000'000 - other.m_nanoseconds);
|
||||
|
||||
if (other.m_seconds != (i64)-0x8000'0000'0000'0000)
|
||||
return *this + Time(-other.m_seconds, 0);
|
||||
return *this + Duration(-other.m_seconds, 0);
|
||||
|
||||
// Only remaining case: We want to subtract -0x8000'0000'0000'0000 seconds,
|
||||
// i.e. add a very large number.
|
||||
|
||||
if (m_seconds >= 0)
|
||||
return Time::max();
|
||||
return Time { (m_seconds + 0x4000'0000'0000'0000) + 0x4000'0000'0000'0000, m_nanoseconds };
|
||||
return Duration::max();
|
||||
return Duration { (m_seconds + 0x4000'0000'0000'0000) + 0x4000'0000'0000'0000, m_nanoseconds };
|
||||
}
|
||||
|
||||
Time& Time::operator-=(Time const& other)
|
||||
Duration& Duration::operator-=(Duration const& other)
|
||||
{
|
||||
*this = *this - other;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Time Time::from_half_sanitized(i64 seconds, i32 extra_seconds, u32 nanoseconds)
|
||||
Duration Duration::from_half_sanitized(i64 seconds, i32 extra_seconds, u32 nanoseconds)
|
||||
{
|
||||
VERIFY(nanoseconds < 1'000'000'000);
|
||||
|
||||
@ -269,41 +269,41 @@ Time Time::from_half_sanitized(i64 seconds, i32 extra_seconds, u32 nanoseconds)
|
||||
// Now the only possible way to become invalid is overflowing i64 towards positive infinity:
|
||||
if (Checked<i64>::addition_would_overflow<i64, i64>(seconds, extra_seconds)) {
|
||||
if (seconds < 0) {
|
||||
return Time::min();
|
||||
return Duration::min();
|
||||
} else {
|
||||
return Time::max();
|
||||
return Duration::max();
|
||||
}
|
||||
}
|
||||
|
||||
return Time { seconds + extra_seconds, nanoseconds };
|
||||
return Duration { seconds + extra_seconds, nanoseconds };
|
||||
}
|
||||
|
||||
#ifndef KERNEL
|
||||
namespace {
|
||||
static Time now_time_from_clock(clockid_t clock_id)
|
||||
static Duration now_time_from_clock(clockid_t clock_id)
|
||||
{
|
||||
timespec now_spec {};
|
||||
::clock_gettime(clock_id, &now_spec);
|
||||
return Time::from_timespec(now_spec);
|
||||
return Duration::from_timespec(now_spec);
|
||||
}
|
||||
}
|
||||
|
||||
Time Time::now_realtime()
|
||||
Duration Duration::now_realtime()
|
||||
{
|
||||
return now_time_from_clock(CLOCK_REALTIME);
|
||||
}
|
||||
|
||||
Time Time::now_realtime_coarse()
|
||||
Duration Duration::now_realtime_coarse()
|
||||
{
|
||||
return now_time_from_clock(CLOCK_REALTIME_COARSE);
|
||||
}
|
||||
|
||||
Time Time::now_monotonic()
|
||||
Duration Duration::now_monotonic()
|
||||
{
|
||||
return now_time_from_clock(CLOCK_MONOTONIC);
|
||||
}
|
||||
|
||||
Time Time::now_monotonic_coarse()
|
||||
Duration Duration::now_monotonic_coarse()
|
||||
{
|
||||
return now_time_from_clock(CLOCK_MONOTONIC_COARSE);
|
||||
}
|
||||
|
92
AK/Time.h
92
AK/Time.h
@ -130,26 +130,28 @@ constexpr i64 seconds_since_epoch_to_year(i64 seconds)
|
||||
return 1970 + round_down(years_since_epoch);
|
||||
}
|
||||
|
||||
/*
|
||||
* Represents a time amount in a "safe" way.
|
||||
* Minimum: 0 seconds, 0 nanoseconds
|
||||
* Maximum: 2**63-1 seconds, 999'999'999 nanoseconds
|
||||
* If any operation (e.g. 'from_timeval' or operator-) would over- or underflow, the closest legal value is returned instead.
|
||||
* Inputs (e.g. to 'from_timespec') are allowed to be in non-normal form (e.g. "1 second, 2'012'345'678 nanoseconds" or "1 second, -2 microseconds").
|
||||
* Outputs (e.g. from 'to_timeval') are always in normal form.
|
||||
*/
|
||||
class Time {
|
||||
// Represents a duration in a "safe" way.
|
||||
// Minimum: -(2**63) seconds, 0 nanoseconds
|
||||
// Maximum: 2**63-1 seconds, 999'999'999 nanoseconds
|
||||
// If any operation (e.g. 'from_timeval' or operator-) would over- or underflow, the closest legal value is returned instead.
|
||||
// Inputs (e.g. to 'from_timespec') are allowed to be in non-normal form (e.g. "1 second, 2'012'345'678 nanoseconds" or "1 second, -2 microseconds").
|
||||
// Outputs (e.g. from 'to_timeval') are always in normal form.
|
||||
//
|
||||
// NOTE: This class is naive. It may represent either absolute offsets or relative durations. It does not have a reference point in itself,
|
||||
// and therefore comparing multiple instances of this class is only sensible if you are sure that their reference point is identical.
|
||||
// You should not be using this class directly to represent absolute time.
|
||||
class Duration {
|
||||
public:
|
||||
Time() = default;
|
||||
Time(Time const&) = default;
|
||||
Time& operator=(Time const&) = default;
|
||||
Duration() = default;
|
||||
Duration(Duration const&) = default;
|
||||
Duration& operator=(Duration const&) = default;
|
||||
|
||||
Time(Time&& other)
|
||||
Duration(Duration&& other)
|
||||
: m_seconds(exchange(other.m_seconds, 0))
|
||||
, m_nanoseconds(exchange(other.m_nanoseconds, 0))
|
||||
{
|
||||
}
|
||||
Time& operator=(Time&& other)
|
||||
Duration& operator=(Duration&& other)
|
||||
{
|
||||
if (this != &other) {
|
||||
m_seconds = exchange(other.m_seconds, 0);
|
||||
@ -188,7 +190,7 @@ private:
|
||||
}
|
||||
|
||||
public:
|
||||
[[nodiscard]] constexpr static Time from_timestamp(i32 year, u8 month, u8 day, u8 hour, u8 minute, u8 second, u16 millisecond)
|
||||
[[nodiscard]] constexpr static Duration from_timestamp(i32 year, u8 month, u8 day, u8 hour, u8 minute, u8 second, u16 millisecond)
|
||||
{
|
||||
constexpr auto milliseconds_per_day = 86'400'000;
|
||||
constexpr auto milliseconds_per_hour = 3'600'000;
|
||||
@ -206,35 +208,35 @@ public:
|
||||
return from_milliseconds(milliseconds_since_epoch);
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr static Time from_seconds(i64 seconds) { return Time(seconds, 0); }
|
||||
[[nodiscard]] constexpr static Time from_nanoseconds(i64 nanoseconds)
|
||||
[[nodiscard]] constexpr static Duration from_seconds(i64 seconds) { return Duration(seconds, 0); }
|
||||
[[nodiscard]] constexpr static Duration from_nanoseconds(i64 nanoseconds)
|
||||
{
|
||||
i64 seconds = sane_mod(nanoseconds, 1'000'000'000);
|
||||
return Time(seconds, nanoseconds);
|
||||
return Duration(seconds, nanoseconds);
|
||||
}
|
||||
[[nodiscard]] constexpr static Time from_microseconds(i64 microseconds)
|
||||
[[nodiscard]] constexpr static Duration from_microseconds(i64 microseconds)
|
||||
{
|
||||
i64 seconds = sane_mod(microseconds, 1'000'000);
|
||||
return Time(seconds, microseconds * 1'000);
|
||||
return Duration(seconds, microseconds * 1'000);
|
||||
}
|
||||
[[nodiscard]] constexpr static Time from_milliseconds(i64 milliseconds)
|
||||
[[nodiscard]] constexpr static Duration from_milliseconds(i64 milliseconds)
|
||||
{
|
||||
i64 seconds = sane_mod(milliseconds, 1'000);
|
||||
return Time(seconds, milliseconds * 1'000'000);
|
||||
return Duration(seconds, milliseconds * 1'000'000);
|
||||
}
|
||||
[[nodiscard]] static Time from_ticks(clock_t, time_t);
|
||||
[[nodiscard]] static Time from_timespec(const struct timespec&);
|
||||
[[nodiscard]] static Time from_timeval(const struct timeval&);
|
||||
[[nodiscard]] static Duration from_ticks(clock_t, time_t);
|
||||
[[nodiscard]] static Duration from_timespec(const struct timespec&);
|
||||
[[nodiscard]] static Duration from_timeval(const struct timeval&);
|
||||
// We don't pull in <stdint.h> for the pretty min/max definitions because this file is also included in the Kernel
|
||||
[[nodiscard]] constexpr static Time min() { return Time(-__INT64_MAX__ - 1LL, 0); };
|
||||
[[nodiscard]] constexpr static Time zero() { return Time(0, 0); };
|
||||
[[nodiscard]] constexpr static Time max() { return Time(__INT64_MAX__, 999'999'999); };
|
||||
[[nodiscard]] constexpr static Duration min() { return Duration(-__INT64_MAX__ - 1LL, 0); };
|
||||
[[nodiscard]] constexpr static Duration zero() { return Duration(0, 0); };
|
||||
[[nodiscard]] constexpr static Duration max() { return Duration(__INT64_MAX__, 999'999'999); };
|
||||
|
||||
#ifndef KERNEL
|
||||
[[nodiscard]] static Time now_realtime();
|
||||
[[nodiscard]] static Time now_realtime_coarse();
|
||||
[[nodiscard]] static Time now_monotonic();
|
||||
[[nodiscard]] static Time now_monotonic_coarse();
|
||||
[[nodiscard]] static Duration now_realtime();
|
||||
[[nodiscard]] static Duration now_realtime_coarse();
|
||||
[[nodiscard]] static Duration now_monotonic();
|
||||
[[nodiscard]] static Duration now_monotonic_coarse();
|
||||
#endif
|
||||
|
||||
// Truncates towards zero (2.8s to 2s, -2.8s to -2s).
|
||||
@ -253,13 +255,13 @@ public:
|
||||
[[nodiscard]] bool is_zero() const { return (m_seconds == 0) && (m_nanoseconds == 0); }
|
||||
[[nodiscard]] bool is_negative() const { return m_seconds < 0; }
|
||||
|
||||
Time operator+(Time const& other) const;
|
||||
Time& operator+=(Time const& other);
|
||||
Time operator-(Time const& other) const;
|
||||
Time& operator-=(Time const& other);
|
||||
Duration operator+(Duration const& other) const;
|
||||
Duration& operator+=(Duration const& other);
|
||||
Duration operator-(Duration const& other) const;
|
||||
Duration& operator-=(Duration const& other);
|
||||
|
||||
constexpr bool operator==(Time const& other) const = default;
|
||||
constexpr int operator<=>(Time const& other) const
|
||||
constexpr bool operator==(Duration const& other) const = default;
|
||||
constexpr int operator<=>(Duration const& other) const
|
||||
{
|
||||
if (int cmp = (m_seconds > other.m_seconds ? 1 : m_seconds < other.m_seconds ? -1
|
||||
: 0);
|
||||
@ -273,13 +275,13 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
constexpr explicit Time(i64 seconds, u32 nanoseconds)
|
||||
constexpr explicit Duration(i64 seconds, u32 nanoseconds)
|
||||
: m_seconds(seconds)
|
||||
, m_nanoseconds(nanoseconds)
|
||||
{
|
||||
}
|
||||
|
||||
[[nodiscard]] static Time from_half_sanitized(i64 seconds, i32 extra_seconds, u32 nanoseconds);
|
||||
[[nodiscard]] static Duration from_half_sanitized(i64 seconds, i32 extra_seconds, u32 nanoseconds);
|
||||
|
||||
i64 m_seconds { 0 };
|
||||
u32 m_nanoseconds { 0 }; // Always less than 1'000'000'000
|
||||
@ -357,10 +359,10 @@ inline void timespec_to_timeval(TimespecType const& ts, TimevalType& tv)
|
||||
// To use these, add a ``using namespace AK::TimeLiterals`` at block or file scope
|
||||
namespace TimeLiterals {
|
||||
|
||||
constexpr Time operator""_ns(unsigned long long nanoseconds) { return Time::from_nanoseconds(static_cast<i64>(nanoseconds)); }
|
||||
constexpr Time operator""_us(unsigned long long microseconds) { return Time::from_microseconds(static_cast<i64>(microseconds)); }
|
||||
constexpr Time operator""_ms(unsigned long long milliseconds) { return Time::from_milliseconds(static_cast<i64>(milliseconds)); }
|
||||
constexpr Time operator""_sec(unsigned long long seconds) { return Time::from_seconds(static_cast<i64>(seconds)); }
|
||||
constexpr Duration operator""_ns(unsigned long long nanoseconds) { return Duration::from_nanoseconds(static_cast<i64>(nanoseconds)); }
|
||||
constexpr Duration operator""_us(unsigned long long microseconds) { return Duration::from_microseconds(static_cast<i64>(microseconds)); }
|
||||
constexpr Duration operator""_ms(unsigned long long milliseconds) { return Duration::from_milliseconds(static_cast<i64>(milliseconds)); }
|
||||
constexpr Duration operator""_sec(unsigned long long seconds) { return Duration::from_seconds(static_cast<i64>(seconds)); }
|
||||
|
||||
}
|
||||
|
||||
@ -372,9 +374,9 @@ using AK::day_of_year;
|
||||
using AK::days_in_month;
|
||||
using AK::days_in_year;
|
||||
using AK::days_since_epoch;
|
||||
using AK::Duration;
|
||||
using AK::is_leap_year;
|
||||
using AK::seconds_since_epoch_to_year;
|
||||
using AK::Time;
|
||||
using AK::timespec_add;
|
||||
using AK::timespec_add_timeval;
|
||||
using AK::timespec_sub;
|
||||
|
@ -19,9 +19,9 @@ void initialize()
|
||||
s_boot_time = now();
|
||||
}
|
||||
|
||||
Time boot_time()
|
||||
Duration boot_time()
|
||||
{
|
||||
return Time::from_timespec({ s_boot_time, 0 });
|
||||
return Duration::from_timespec({ s_boot_time, 0 });
|
||||
}
|
||||
|
||||
static bool update_in_progress()
|
||||
|
@ -6,12 +6,13 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Time.h>
|
||||
#include <Kernel/UnixTypes.h>
|
||||
|
||||
namespace Kernel::RTC {
|
||||
|
||||
void initialize();
|
||||
time_t now();
|
||||
Time boot_time();
|
||||
Duration boot_time();
|
||||
|
||||
}
|
||||
|
@ -590,7 +590,7 @@ ErrorOr<void> UHCIController::spawn_port_process()
|
||||
if (m_root_hub)
|
||||
m_root_hub->check_for_port_updates();
|
||||
|
||||
(void)Thread::current()->sleep(Time::from_seconds(1));
|
||||
(void)Thread::current()->sleep(Duration::from_seconds(1));
|
||||
}
|
||||
}));
|
||||
return {};
|
||||
@ -616,7 +616,7 @@ ErrorOr<void> UHCIController::spawn_async_poll_process()
|
||||
}
|
||||
}
|
||||
}
|
||||
(void)Thread::current()->sleep(Time::from_milliseconds(poll_interval_ms));
|
||||
(void)Thread::current()->sleep(Duration::from_milliseconds(poll_interval_ms));
|
||||
}
|
||||
}));
|
||||
return {};
|
||||
|
@ -51,7 +51,7 @@ void AsyncDeviceRequest::request_finished()
|
||||
m_queue.wake_all();
|
||||
}
|
||||
|
||||
auto AsyncDeviceRequest::wait(Time* timeout) -> RequestWaitResult
|
||||
auto AsyncDeviceRequest::wait(Duration* timeout) -> RequestWaitResult
|
||||
{
|
||||
VERIFY(!m_parent_request);
|
||||
auto request_result = get_request_result();
|
||||
|
@ -60,7 +60,7 @@ public:
|
||||
|
||||
void add_sub_request(NonnullLockRefPtr<AsyncDeviceRequest>);
|
||||
|
||||
[[nodiscard]] RequestWaitResult wait(Time* = nullptr);
|
||||
[[nodiscard]] RequestWaitResult wait(Duration* = nullptr);
|
||||
|
||||
void do_start(SpinlockLocker<Spinlock<LockRank::None>>&& requests_lock)
|
||||
{
|
||||
|
@ -192,7 +192,7 @@ ErrorOr<size_t> OutputStream::write(UserOrKernelBuffer const& data, size_t lengt
|
||||
dbgln_if(INTEL_HDA_DEBUG, "IntelHDA: Waiting {} µs until buffer {} becomes writeable", microseconds_to_wait, buffer_index);
|
||||
|
||||
// NOTE: we don't care about the reason for interruption - we simply calculate the next delay
|
||||
[[maybe_unused]] auto block_result = Thread::current()->sleep(Time::from_microseconds(microseconds_to_wait));
|
||||
[[maybe_unused]] auto block_result = Thread::current()->sleep(Duration::from_microseconds(microseconds_to_wait));
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -38,7 +38,7 @@ InodeMetadata DevPtsFSInode::metadata() const
|
||||
{
|
||||
if (auto pty = m_pty.strong_ref()) {
|
||||
auto metadata = m_metadata;
|
||||
metadata.mtime = Time::from_timespec({ pty->time_of_last_write(), 0 });
|
||||
metadata.mtime = Duration::from_timespec({ pty->time_of_last_write(), 0 });
|
||||
return metadata;
|
||||
}
|
||||
return m_metadata;
|
||||
|
@ -474,10 +474,10 @@ InodeMetadata Ext2FSInode::metadata() const
|
||||
metadata.uid = m_raw_inode.i_uid;
|
||||
metadata.gid = m_raw_inode.i_gid;
|
||||
metadata.link_count = m_raw_inode.i_links_count;
|
||||
metadata.atime = Time::from_timespec({ m_raw_inode.i_atime, 0 });
|
||||
metadata.ctime = Time::from_timespec({ m_raw_inode.i_ctime, 0 });
|
||||
metadata.mtime = Time::from_timespec({ m_raw_inode.i_mtime, 0 });
|
||||
metadata.dtime = Time::from_timespec({ m_raw_inode.i_dtime, 0 });
|
||||
metadata.atime = Duration::from_timespec({ m_raw_inode.i_atime, 0 });
|
||||
metadata.ctime = Duration::from_timespec({ m_raw_inode.i_ctime, 0 });
|
||||
metadata.mtime = Duration::from_timespec({ m_raw_inode.i_mtime, 0 });
|
||||
metadata.dtime = Duration::from_timespec({ m_raw_inode.i_dtime, 0 });
|
||||
metadata.block_size = fs().block_size();
|
||||
metadata.block_count = m_raw_inode.i_blocks;
|
||||
|
||||
@ -985,7 +985,7 @@ ErrorOr<NonnullRefPtr<Inode>> Ext2FSInode::lookup(StringView name)
|
||||
return fs().get_inode({ fsid(), inode_index });
|
||||
}
|
||||
|
||||
ErrorOr<void> Ext2FSInode::update_timestamps(Optional<Time> atime, Optional<Time> ctime, Optional<Time> mtime)
|
||||
ErrorOr<void> Ext2FSInode::update_timestamps(Optional<Duration> atime, Optional<Duration> ctime, Optional<Duration> mtime)
|
||||
{
|
||||
MutexLocker locker(m_inode_lock);
|
||||
if (fs().is_readonly())
|
||||
|
@ -37,7 +37,7 @@ private:
|
||||
virtual ErrorOr<void> add_child(Inode& child, StringView name, mode_t) override;
|
||||
virtual ErrorOr<void> remove_child(StringView name) override;
|
||||
virtual ErrorOr<void> replace_child(StringView name, Inode& child) override;
|
||||
virtual ErrorOr<void> update_timestamps(Optional<Time> atime, Optional<Time> ctime, Optional<Time> mtime) override;
|
||||
virtual ErrorOr<void> update_timestamps(Optional<Duration> atime, Optional<Duration> ctime, Optional<Duration> mtime) override;
|
||||
virtual ErrorOr<void> increment_link_count() override;
|
||||
virtual ErrorOr<void> decrement_link_count() override;
|
||||
virtual ErrorOr<void> chmod(mode_t) override;
|
||||
|
@ -145,7 +145,7 @@ ErrorOr<void> ISO9660Inode::truncate(u64)
|
||||
return EROFS;
|
||||
}
|
||||
|
||||
ErrorOr<void> ISO9660Inode::update_timestamps(Optional<Time>, Optional<Time>, Optional<Time>)
|
||||
ErrorOr<void> ISO9660Inode::update_timestamps(Optional<Duration>, Optional<Duration>, Optional<Duration>)
|
||||
{
|
||||
return EROFS;
|
||||
}
|
||||
@ -169,7 +169,7 @@ void ISO9660Inode::create_metadata()
|
||||
{
|
||||
u32 data_length = LittleEndian { m_record.data_length.little };
|
||||
bool is_directory = has_flag(m_record.file_flags, ISO::FileFlags::Directory);
|
||||
auto recorded_at = Time::from_timespec({ parse_numerical_date_time(m_record.recording_date_and_time), 0 });
|
||||
auto recorded_at = Duration::from_timespec({ parse_numerical_date_time(m_record.recording_date_and_time), 0 });
|
||||
|
||||
m_metadata = {
|
||||
.inode = identifier(),
|
||||
|
@ -32,7 +32,7 @@ public:
|
||||
virtual ErrorOr<void> chmod(mode_t) override;
|
||||
virtual ErrorOr<void> chown(UserID, GroupID) override;
|
||||
virtual ErrorOr<void> truncate(u64) override;
|
||||
virtual ErrorOr<void> update_timestamps(Optional<Time> atime, Optional<Time> ctime, Optional<Time> mtime) override;
|
||||
virtual ErrorOr<void> update_timestamps(Optional<Duration> atime, Optional<Duration> ctime, Optional<Duration> mtime) override;
|
||||
|
||||
private:
|
||||
// HACK: The base ISO 9660 standard says the maximum filename length is 37
|
||||
|
@ -115,7 +115,7 @@ ErrorOr<size_t> Inode::read_until_filled_or_end(off_t offset, size_t length, Use
|
||||
return length - remaining_length;
|
||||
}
|
||||
|
||||
ErrorOr<void> Inode::update_timestamps([[maybe_unused]] Optional<Time> atime, [[maybe_unused]] Optional<Time> ctime, [[maybe_unused]] Optional<Time> mtime)
|
||||
ErrorOr<void> Inode::update_timestamps([[maybe_unused]] Optional<Duration> atime, [[maybe_unused]] Optional<Duration> ctime, [[maybe_unused]] Optional<Duration> mtime)
|
||||
{
|
||||
return ENOTIMPL;
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ public:
|
||||
|
||||
bool is_metadata_dirty() const { return m_metadata_dirty; }
|
||||
|
||||
virtual ErrorOr<void> update_timestamps(Optional<Time> atime, Optional<Time> ctime, Optional<Time> mtime);
|
||||
virtual ErrorOr<void> update_timestamps(Optional<Duration> atime, Optional<Duration> ctime, Optional<Duration> mtime);
|
||||
virtual ErrorOr<void> increment_link_count();
|
||||
virtual ErrorOr<void> decrement_link_count();
|
||||
|
||||
|
@ -120,10 +120,10 @@ struct InodeMetadata {
|
||||
UserID uid { 0 };
|
||||
GroupID gid { 0 };
|
||||
nlink_t link_count { 0 };
|
||||
Time atime {};
|
||||
Time ctime {};
|
||||
Time mtime {};
|
||||
Time dtime {};
|
||||
Duration atime {};
|
||||
Duration ctime {};
|
||||
Duration mtime {};
|
||||
Duration dtime {};
|
||||
blkcnt_t block_count { 0 };
|
||||
blksize_t block_size { 0 };
|
||||
MajorNumber major_device { 0 };
|
||||
|
@ -54,7 +54,7 @@ private:
|
||||
|
||||
// ^Inode (Silent ignore handling)
|
||||
virtual ErrorOr<void> flush_metadata() override { return {}; }
|
||||
virtual ErrorOr<void> update_timestamps(Optional<Time>, Optional<Time>, Optional<Time>) override { return {}; }
|
||||
virtual ErrorOr<void> update_timestamps(Optional<Duration>, Optional<Duration>, Optional<Duration>) override { return {}; }
|
||||
|
||||
// ^Inode
|
||||
virtual ErrorOr<void> attach(OpenFileDescription& description) override;
|
||||
|
@ -381,7 +381,7 @@ ErrorOr<void> RAMFSInode::truncate(u64 size)
|
||||
return {};
|
||||
}
|
||||
|
||||
ErrorOr<void> RAMFSInode::update_timestamps(Optional<Time> atime, Optional<Time> ctime, Optional<Time> mtime)
|
||||
ErrorOr<void> RAMFSInode::update_timestamps(Optional<Duration> atime, Optional<Duration> ctime, Optional<Duration> mtime)
|
||||
{
|
||||
MutexLocker locker(m_inode_lock);
|
||||
|
||||
|
@ -35,7 +35,7 @@ public:
|
||||
virtual ErrorOr<void> chmod(mode_t) override;
|
||||
virtual ErrorOr<void> chown(UserID, GroupID) override;
|
||||
virtual ErrorOr<void> truncate(u64) override;
|
||||
virtual ErrorOr<void> update_timestamps(Optional<Time> atime, Optional<Time> ctime, Optional<Time> mtime) override;
|
||||
virtual ErrorOr<void> update_timestamps(Optional<Duration> atime, Optional<Duration> ctime, Optional<Duration> mtime) override;
|
||||
|
||||
private:
|
||||
RAMFSInode(RAMFS& fs, InodeMetadata const& metadata, LockWeakPtr<RAMFSInode> parent);
|
||||
|
@ -110,7 +110,7 @@ ErrorOr<void> SysFSInode::truncate(u64 size)
|
||||
return m_associated_component->truncate(size);
|
||||
}
|
||||
|
||||
ErrorOr<void> SysFSInode::update_timestamps(Optional<Time>, Optional<Time>, Optional<Time>)
|
||||
ErrorOr<void> SysFSInode::update_timestamps(Optional<Duration>, Optional<Duration>, Optional<Duration>)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ protected:
|
||||
virtual ErrorOr<void> chmod(mode_t) override;
|
||||
virtual ErrorOr<void> chown(UserID, GroupID) override;
|
||||
virtual ErrorOr<void> truncate(u64) override;
|
||||
virtual ErrorOr<void> update_timestamps(Optional<Time> atime, Optional<Time> ctime, Optional<Time> mtime) override;
|
||||
virtual ErrorOr<void> update_timestamps(Optional<Duration> atime, Optional<Duration> ctime, Optional<Duration> mtime) override;
|
||||
|
||||
virtual ErrorOr<void> attach(OpenFileDescription& description) override final;
|
||||
virtual void did_seek(OpenFileDescription&, off_t) override final;
|
||||
|
@ -306,7 +306,7 @@ ErrorOr<void> VirtualFileSystem::utime(Credentials const& credentials, StringVie
|
||||
if (custody->is_readonly())
|
||||
return EROFS;
|
||||
|
||||
TRY(inode.update_timestamps(Time::from_timespec({ atime, 0 }), {}, Time::from_timespec({ mtime, 0 })));
|
||||
TRY(inode.update_timestamps(Duration::from_timespec({ atime, 0 }), {}, Duration::from_timespec({ mtime, 0 })));
|
||||
return {};
|
||||
}
|
||||
|
||||
@ -326,9 +326,9 @@ ErrorOr<void> VirtualFileSystem::do_utimens(Credentials const& credentials, Cust
|
||||
|
||||
// NOTE: A standard ext2 inode cannot store nanosecond timestamps.
|
||||
TRY(inode.update_timestamps(
|
||||
(atime.tv_nsec != UTIME_OMIT) ? Time::from_timespec(atime) : Optional<Time> {},
|
||||
(atime.tv_nsec != UTIME_OMIT) ? Duration::from_timespec(atime) : Optional<Duration> {},
|
||||
{},
|
||||
(mtime.tv_nsec != UTIME_OMIT) ? Time::from_timespec(mtime) : Optional<Time> {}));
|
||||
(mtime.tv_nsec != UTIME_OMIT) ? Duration::from_timespec(mtime) : Optional<Duration> {}));
|
||||
|
||||
return {};
|
||||
}
|
||||
|
@ -9,7 +9,7 @@
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
constexpr static AK::Time refresh_interval = AK::Time::from_milliseconds(16);
|
||||
constexpr static AK::Duration refresh_interval = AK::Duration::from_milliseconds(16);
|
||||
|
||||
NonnullLockRefPtr<VMWareFramebufferConsole> VMWareFramebufferConsole::initialize(VMWareDisplayConnector& parent_display_connector)
|
||||
{
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
namespace Kernel::Graphics::VirtIOGPU {
|
||||
|
||||
constexpr static AK::Time refresh_interval = AK::Time::from_milliseconds(16);
|
||||
constexpr static AK::Duration refresh_interval = AK::Duration::from_milliseconds(16);
|
||||
|
||||
NonnullLockRefPtr<Console> Console::initialize(VirtIODisplayConnector& parent_display_connector)
|
||||
{
|
||||
|
@ -287,7 +287,7 @@ ErrorOr<size_t> IPv4Socket::receive_byte_buffered(OpenFileDescription& descripti
|
||||
return nreceived_or_error;
|
||||
}
|
||||
|
||||
ErrorOr<size_t> IPv4Socket::receive_packet_buffered(OpenFileDescription& description, UserOrKernelBuffer& buffer, size_t buffer_length, int flags, Userspace<sockaddr*> addr, Userspace<socklen_t*> addr_length, Time& packet_timestamp, bool blocking)
|
||||
ErrorOr<size_t> IPv4Socket::receive_packet_buffered(OpenFileDescription& description, UserOrKernelBuffer& buffer, size_t buffer_length, int flags, Userspace<sockaddr*> addr, Userspace<socklen_t*> addr_length, Duration& packet_timestamp, bool blocking)
|
||||
{
|
||||
MutexLocker locker(mutex());
|
||||
ReceivedPacket taken_packet;
|
||||
@ -382,7 +382,7 @@ ErrorOr<size_t> IPv4Socket::receive_packet_buffered(OpenFileDescription& descrip
|
||||
return protocol_receive(packet->data->bytes(), buffer, buffer_length, flags);
|
||||
}
|
||||
|
||||
ErrorOr<size_t> IPv4Socket::recvfrom(OpenFileDescription& description, UserOrKernelBuffer& buffer, size_t buffer_length, int flags, Userspace<sockaddr*> user_addr, Userspace<socklen_t*> user_addr_length, Time& packet_timestamp, bool blocking)
|
||||
ErrorOr<size_t> IPv4Socket::recvfrom(OpenFileDescription& description, UserOrKernelBuffer& buffer, size_t buffer_length, int flags, Userspace<sockaddr*> user_addr, Userspace<socklen_t*> user_addr_length, Duration& packet_timestamp, bool blocking)
|
||||
{
|
||||
if (user_addr_length) {
|
||||
socklen_t addr_length;
|
||||
@ -415,7 +415,7 @@ ErrorOr<size_t> IPv4Socket::recvfrom(OpenFileDescription& description, UserOrKer
|
||||
return total_nreceived;
|
||||
}
|
||||
|
||||
bool IPv4Socket::did_receive(IPv4Address const& source_address, u16 source_port, ReadonlyBytes packet, Time const& packet_timestamp)
|
||||
bool IPv4Socket::did_receive(IPv4Address const& source_address, u16 source_port, ReadonlyBytes packet, Duration const& packet_timestamp)
|
||||
{
|
||||
MutexLocker locker(mutex());
|
||||
|
||||
|
@ -40,13 +40,13 @@ public:
|
||||
virtual bool can_read(OpenFileDescription const&, u64) const override;
|
||||
virtual bool can_write(OpenFileDescription const&, u64) const override;
|
||||
virtual ErrorOr<size_t> sendto(OpenFileDescription&, UserOrKernelBuffer const&, size_t, int, Userspace<sockaddr const*>, socklen_t) override;
|
||||
virtual ErrorOr<size_t> recvfrom(OpenFileDescription&, UserOrKernelBuffer&, size_t, int flags, Userspace<sockaddr*>, Userspace<socklen_t*>, Time&, bool blocking) override;
|
||||
virtual ErrorOr<size_t> recvfrom(OpenFileDescription&, UserOrKernelBuffer&, size_t, int flags, Userspace<sockaddr*>, Userspace<socklen_t*>, Duration&, bool blocking) override;
|
||||
virtual ErrorOr<void> setsockopt(int level, int option, Userspace<void const*>, socklen_t) override;
|
||||
virtual ErrorOr<void> getsockopt(OpenFileDescription&, int level, int option, Userspace<void*>, Userspace<socklen_t*>) override;
|
||||
|
||||
virtual ErrorOr<void> ioctl(OpenFileDescription&, unsigned request, Userspace<void*> arg) override;
|
||||
|
||||
bool did_receive(IPv4Address const& peer_address, u16 peer_port, ReadonlyBytes, Time const&);
|
||||
bool did_receive(IPv4Address const& peer_address, u16 peer_port, ReadonlyBytes, Duration const&);
|
||||
|
||||
IPv4Address const& local_address() const { return m_local_address; }
|
||||
u16 local_port() const { return m_local_port; }
|
||||
@ -99,7 +99,7 @@ private:
|
||||
virtual bool is_ipv4() const override { return true; }
|
||||
|
||||
ErrorOr<size_t> receive_byte_buffered(OpenFileDescription&, UserOrKernelBuffer& buffer, size_t buffer_length, int flags, Userspace<sockaddr*>, Userspace<socklen_t*>, bool blocking);
|
||||
ErrorOr<size_t> receive_packet_buffered(OpenFileDescription&, UserOrKernelBuffer& buffer, size_t buffer_length, int flags, Userspace<sockaddr*>, Userspace<socklen_t*>, Time&, bool blocking);
|
||||
ErrorOr<size_t> receive_packet_buffered(OpenFileDescription&, UserOrKernelBuffer& buffer, size_t buffer_length, int flags, Userspace<sockaddr*>, Userspace<socklen_t*>, Duration&, bool blocking);
|
||||
|
||||
void set_can_read(bool);
|
||||
|
||||
@ -112,7 +112,7 @@ private:
|
||||
struct ReceivedPacket {
|
||||
IPv4Address peer_address;
|
||||
u16 peer_port;
|
||||
Time timestamp;
|
||||
Duration timestamp;
|
||||
OwnPtr<KBuffer> data;
|
||||
};
|
||||
|
||||
|
@ -333,7 +333,7 @@ DoubleBuffer* LocalSocket::send_buffer_for(OpenFileDescription& description)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ErrorOr<size_t> LocalSocket::recvfrom(OpenFileDescription& description, UserOrKernelBuffer& buffer, size_t buffer_size, int, Userspace<sockaddr*>, Userspace<socklen_t*>, Time&, bool blocking)
|
||||
ErrorOr<size_t> LocalSocket::recvfrom(OpenFileDescription& description, UserOrKernelBuffer& buffer, size_t buffer_size, int, Userspace<sockaddr*>, Userspace<socklen_t*>, Duration&, bool blocking)
|
||||
{
|
||||
auto* socket_buffer = receive_buffer_for(description);
|
||||
if (!socket_buffer)
|
||||
|
@ -47,7 +47,7 @@ public:
|
||||
virtual bool can_read(OpenFileDescription const&, u64) const override;
|
||||
virtual bool can_write(OpenFileDescription const&, u64) const override;
|
||||
virtual ErrorOr<size_t> sendto(OpenFileDescription&, UserOrKernelBuffer const&, size_t, int, Userspace<sockaddr const*>, socklen_t) override;
|
||||
virtual ErrorOr<size_t> recvfrom(OpenFileDescription&, UserOrKernelBuffer&, size_t, int flags, Userspace<sockaddr*>, Userspace<socklen_t*>, Time&, bool blocking) override;
|
||||
virtual ErrorOr<size_t> recvfrom(OpenFileDescription&, UserOrKernelBuffer&, size_t, int flags, Userspace<sockaddr*>, Userspace<socklen_t*>, Duration&, bool blocking) override;
|
||||
virtual ErrorOr<void> getsockopt(OpenFileDescription&, int level, int option, Userspace<void*>, Userspace<socklen_t*>) override;
|
||||
virtual ErrorOr<void> ioctl(OpenFileDescription&, unsigned request, Userspace<void*> arg) override;
|
||||
virtual ErrorOr<void> chown(Credentials const&, OpenFileDescription&, UserID, GroupID) override;
|
||||
|
@ -95,7 +95,7 @@ void NetworkAdapter::did_receive(ReadonlyBytes payload)
|
||||
on_receive();
|
||||
}
|
||||
|
||||
size_t NetworkAdapter::dequeue_packet(u8* buffer, size_t buffer_size, Time& packet_timestamp)
|
||||
size_t NetworkAdapter::dequeue_packet(u8* buffer, size_t buffer_size, Duration& packet_timestamp)
|
||||
{
|
||||
InterruptDisabler disabler;
|
||||
if (m_packet_queue.is_empty())
|
||||
|
@ -29,7 +29,7 @@ class NetworkAdapter;
|
||||
using NetworkByteBuffer = AK::Detail::ByteBuffer<1500>;
|
||||
|
||||
struct PacketWithTimestamp final : public AtomicRefCounted<PacketWithTimestamp> {
|
||||
PacketWithTimestamp(NonnullOwnPtr<KBuffer> buffer, Time timestamp)
|
||||
PacketWithTimestamp(NonnullOwnPtr<KBuffer> buffer, Duration timestamp)
|
||||
: buffer(move(buffer))
|
||||
, timestamp(timestamp)
|
||||
{
|
||||
@ -38,7 +38,7 @@ struct PacketWithTimestamp final : public AtomicRefCounted<PacketWithTimestamp>
|
||||
ReadonlyBytes bytes() { return buffer->bytes(); }
|
||||
|
||||
NonnullOwnPtr<KBuffer> buffer;
|
||||
Time timestamp;
|
||||
Duration timestamp;
|
||||
IntrusiveListNode<PacketWithTimestamp, RefPtr<PacketWithTimestamp>> packet_node;
|
||||
};
|
||||
|
||||
@ -79,7 +79,7 @@ public:
|
||||
void send(MACAddress const&, ARPPacket const&);
|
||||
void fill_in_ipv4_header(PacketWithTimestamp&, IPv4Address const&, MACAddress const&, IPv4Address const&, IPv4Protocol, size_t, u8 type_of_service, u8 ttl);
|
||||
|
||||
size_t dequeue_packet(u8* buffer, size_t buffer_size, Time& packet_timestamp);
|
||||
size_t dequeue_packet(u8* buffer, size_t buffer_size, Duration& packet_timestamp);
|
||||
|
||||
bool has_queued_packets() const { return !m_packet_queue.is_empty(); }
|
||||
|
||||
|
@ -26,10 +26,10 @@
|
||||
namespace Kernel {
|
||||
|
||||
static void handle_arp(EthernetFrameHeader const&, size_t frame_size);
|
||||
static void handle_ipv4(EthernetFrameHeader const&, size_t frame_size, Time const& packet_timestamp);
|
||||
static void handle_icmp(EthernetFrameHeader const&, IPv4Packet const&, Time const& packet_timestamp);
|
||||
static void handle_udp(IPv4Packet const&, Time const& packet_timestamp);
|
||||
static void handle_tcp(IPv4Packet const&, Time const& packet_timestamp);
|
||||
static void handle_ipv4(EthernetFrameHeader const&, size_t frame_size, Duration const& packet_timestamp);
|
||||
static void handle_icmp(EthernetFrameHeader const&, IPv4Packet const&, Duration const& packet_timestamp);
|
||||
static void handle_udp(IPv4Packet const&, Duration const& packet_timestamp);
|
||||
static void handle_tcp(IPv4Packet const&, Duration const& packet_timestamp);
|
||||
static void send_delayed_tcp_ack(TCPSocket& socket);
|
||||
static void send_tcp_rst(IPv4Packet const& ipv4_packet, TCPPacket const& tcp_packet, RefPtr<NetworkAdapter> adapter);
|
||||
static void flush_delayed_tcp_acks();
|
||||
@ -74,7 +74,7 @@ void NetworkTask_main(void*)
|
||||
};
|
||||
});
|
||||
|
||||
auto dequeue_packet = [&pending_packets](u8* buffer, size_t buffer_size, Time& packet_timestamp) -> size_t {
|
||||
auto dequeue_packet = [&pending_packets](u8* buffer, size_t buffer_size, Duration& packet_timestamp) -> size_t {
|
||||
if (pending_packets == 0)
|
||||
return 0;
|
||||
size_t packet_size = 0;
|
||||
@ -94,14 +94,14 @@ void NetworkTask_main(void*)
|
||||
TODO();
|
||||
auto buffer_region = region_or_error.release_value();
|
||||
auto buffer = (u8*)buffer_region->vaddr().get();
|
||||
Time packet_timestamp;
|
||||
Duration packet_timestamp;
|
||||
|
||||
for (;;) {
|
||||
flush_delayed_tcp_acks();
|
||||
retransmit_tcp_packets();
|
||||
size_t packet_size = dequeue_packet(buffer, buffer_size, packet_timestamp);
|
||||
if (!packet_size) {
|
||||
auto timeout_time = Time::from_milliseconds(500);
|
||||
auto timeout_time = Duration::from_milliseconds(500);
|
||||
auto timeout = Thread::BlockTimeout { false, &timeout_time };
|
||||
[[maybe_unused]] auto result = packet_wait_queue.wait_on(timeout, "NetworkTask"sv);
|
||||
continue;
|
||||
@ -177,7 +177,7 @@ void handle_arp(EthernetFrameHeader const& eth, size_t frame_size)
|
||||
}
|
||||
}
|
||||
|
||||
void handle_ipv4(EthernetFrameHeader const& eth, size_t frame_size, Time const& packet_timestamp)
|
||||
void handle_ipv4(EthernetFrameHeader const& eth, size_t frame_size, Duration const& packet_timestamp)
|
||||
{
|
||||
constexpr size_t minimum_ipv4_frame_size = sizeof(EthernetFrameHeader) + sizeof(IPv4Packet);
|
||||
if (frame_size < minimum_ipv4_frame_size) {
|
||||
@ -222,7 +222,7 @@ void handle_ipv4(EthernetFrameHeader const& eth, size_t frame_size, Time const&
|
||||
}
|
||||
}
|
||||
|
||||
void handle_icmp(EthernetFrameHeader const& eth, IPv4Packet const& ipv4_packet, Time const& packet_timestamp)
|
||||
void handle_icmp(EthernetFrameHeader const& eth, IPv4Packet const& ipv4_packet, Duration const& packet_timestamp)
|
||||
{
|
||||
auto& icmp_header = *static_cast<ICMPHeader const*>(ipv4_packet.payload());
|
||||
dbgln_if(ICMP_DEBUG, "handle_icmp: source={}, destination={}, type={:#02x}, code={:#02x}", ipv4_packet.source().to_string(), ipv4_packet.destination().to_string(), icmp_header.type(), icmp_header.code());
|
||||
@ -273,7 +273,7 @@ void handle_icmp(EthernetFrameHeader const& eth, IPv4Packet const& ipv4_packet,
|
||||
}
|
||||
}
|
||||
|
||||
void handle_udp(IPv4Packet const& ipv4_packet, Time const& packet_timestamp)
|
||||
void handle_udp(IPv4Packet const& ipv4_packet, Duration const& packet_timestamp)
|
||||
{
|
||||
if (ipv4_packet.payload_size() < sizeof(UDPPacket)) {
|
||||
dbgln("handle_udp: Packet too small ({}, need {})", ipv4_packet.payload_size(), sizeof(UDPPacket));
|
||||
@ -367,7 +367,7 @@ void send_tcp_rst(IPv4Packet const& ipv4_packet, TCPPacket const& tcp_packet, Re
|
||||
routing_decision.adapter->release_packet_buffer(*packet);
|
||||
}
|
||||
|
||||
void handle_tcp(IPv4Packet const& ipv4_packet, Time const& packet_timestamp)
|
||||
void handle_tcp(IPv4Packet const& ipv4_packet, Duration const& packet_timestamp)
|
||||
{
|
||||
if (ipv4_packet.payload_size() < sizeof(TCPPacket)) {
|
||||
dbgln("handle_tcp: IPv4 payload is too small to be a TCP packet ({}, need {})", ipv4_packet.payload_size(), sizeof(TCPPacket));
|
||||
|
@ -245,7 +245,7 @@ ErrorOr<size_t> Socket::read(OpenFileDescription& description, u64, UserOrKernel
|
||||
{
|
||||
if (is_shut_down_for_reading())
|
||||
return 0;
|
||||
Time t {};
|
||||
Duration t {};
|
||||
return recvfrom(description, buffer, size, 0, {}, 0, t, description.is_blocking());
|
||||
}
|
||||
|
||||
|
@ -79,7 +79,7 @@ public:
|
||||
virtual bool is_local() const { return false; }
|
||||
virtual bool is_ipv4() const { return false; }
|
||||
virtual ErrorOr<size_t> sendto(OpenFileDescription&, UserOrKernelBuffer const&, size_t, int flags, Userspace<sockaddr const*>, socklen_t) = 0;
|
||||
virtual ErrorOr<size_t> recvfrom(OpenFileDescription&, UserOrKernelBuffer&, size_t, int flags, Userspace<sockaddr*>, Userspace<socklen_t*>, Time&, bool blocking) = 0;
|
||||
virtual ErrorOr<size_t> recvfrom(OpenFileDescription&, UserOrKernelBuffer&, size_t, int flags, Userspace<sockaddr*>, Userspace<socklen_t*>, Duration&, bool blocking) = 0;
|
||||
|
||||
virtual ErrorOr<void> setsockopt(int level, int option, Userspace<void const*>, socklen_t);
|
||||
virtual ErrorOr<void> getsockopt(OpenFileDescription&, int level, int option, Userspace<void*>, Userspace<socklen_t*>);
|
||||
@ -100,11 +100,11 @@ public:
|
||||
virtual ErrorOr<struct stat> stat() const override;
|
||||
virtual ErrorOr<NonnullOwnPtr<KString>> pseudo_path(OpenFileDescription const&) const override = 0;
|
||||
|
||||
bool has_receive_timeout() const { return m_receive_timeout != Time::zero(); }
|
||||
Time const& receive_timeout() const { return m_receive_timeout; }
|
||||
bool has_receive_timeout() const { return m_receive_timeout != Duration::zero(); }
|
||||
Duration const& receive_timeout() const { return m_receive_timeout; }
|
||||
|
||||
bool has_send_timeout() const { return m_send_timeout != Time::zero(); }
|
||||
Time const& send_timeout() const { return m_send_timeout; }
|
||||
bool has_send_timeout() const { return m_send_timeout != Duration::zero(); }
|
||||
Duration const& send_timeout() const { return m_send_timeout; }
|
||||
|
||||
bool wants_timestamp() const { return m_timestamp; }
|
||||
|
||||
@ -173,8 +173,8 @@ private:
|
||||
|
||||
SpinlockProtected<RefPtr<NetworkAdapter>, LockRank::None> m_bound_interface;
|
||||
|
||||
Time m_receive_timeout {};
|
||||
Time m_send_timeout {};
|
||||
Duration m_receive_timeout {};
|
||||
Duration m_send_timeout {};
|
||||
int m_timestamp { 0 };
|
||||
|
||||
SpinlockProtected<Optional<ErrnoCode>, LockRank::None> m_so_error;
|
||||
|
@ -354,7 +354,7 @@ bool TCPSocket::should_delay_next_ack() const
|
||||
return false;
|
||||
|
||||
// RFC 1122 says we should not delay ACKs for more than 500 milliseconds.
|
||||
if (kgettimeofday() >= m_last_ack_sent_time + Time::from_milliseconds(500))
|
||||
if (kgettimeofday() >= m_last_ack_sent_time + Duration::from_milliseconds(500))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
@ -586,7 +586,7 @@ void TCPSocket::retransmit_packets()
|
||||
for (decltype(m_retransmit_attempts) i = 0; i < m_retransmit_attempts; i++)
|
||||
retransmit_interval *= 2;
|
||||
|
||||
if (m_last_retransmit_time > now - Time::from_seconds(retransmit_interval))
|
||||
if (m_last_retransmit_time > now - Duration::from_seconds(retransmit_interval))
|
||||
return;
|
||||
|
||||
dbgln_if(TCP_SOCKET_DEBUG, "TCPSocket({}) handling retransmit", this);
|
||||
|
@ -216,11 +216,11 @@ private:
|
||||
u32 m_duplicate_acks { 0 };
|
||||
|
||||
u32 m_last_ack_number_sent { 0 };
|
||||
Time m_last_ack_sent_time;
|
||||
Duration m_last_ack_sent_time;
|
||||
|
||||
// FIXME: Make this configurable (sysctl)
|
||||
static constexpr u32 maximum_retransmits = 5;
|
||||
Time m_last_retransmit_time;
|
||||
Duration m_last_retransmit_time;
|
||||
u32 m_retransmit_attempts { 0 };
|
||||
|
||||
// FIXME: Parse window size TCP option from the peer
|
||||
|
@ -164,11 +164,11 @@ public:
|
||||
|
||||
static void timer_tick(RegisterState const& regs)
|
||||
{
|
||||
static Time last_wakeup;
|
||||
static Duration last_wakeup;
|
||||
auto now = kgettimeofday();
|
||||
constexpr auto ideal_interval = Time::from_microseconds(1000'000 / OPTIMAL_PROFILE_TICKS_PER_SECOND_RATE);
|
||||
constexpr auto ideal_interval = Duration::from_microseconds(1000'000 / OPTIMAL_PROFILE_TICKS_PER_SECOND_RATE);
|
||||
auto expected_wakeup = last_wakeup + ideal_interval;
|
||||
auto delay = (now > expected_wakeup) ? now - expected_wakeup : Time::from_microseconds(0);
|
||||
auto delay = (now > expected_wakeup) ? now - expected_wakeup : Duration::from_microseconds(0);
|
||||
last_wakeup = now;
|
||||
auto* current_thread = Thread::current();
|
||||
// FIXME: We currently don't collect samples while idle.
|
||||
|
@ -635,7 +635,7 @@ ErrorOr<Process::ScopedDescriptionAllocation> Process::OpenFileDescriptions::all
|
||||
return EMFILE;
|
||||
}
|
||||
|
||||
Time kgettimeofday()
|
||||
Duration kgettimeofday()
|
||||
{
|
||||
return TimeManagement::now();
|
||||
}
|
||||
|
@ -41,7 +41,7 @@
|
||||
namespace Kernel {
|
||||
|
||||
MutexProtected<OwnPtr<KString>>& hostname();
|
||||
Time kgettimeofday();
|
||||
Duration kgettimeofday();
|
||||
|
||||
#define ENUMERATE_PLEDGE_PROMISES \
|
||||
__ENUMERATE_PLEDGE_PROMISE(stdio) \
|
||||
|
@ -39,28 +39,28 @@ ErrorOr<NonnullOwnPtr<Kernel::KString>> try_copy_kstring_from_user(Userspace<cha
|
||||
return new_string;
|
||||
}
|
||||
|
||||
ErrorOr<Time> copy_time_from_user(timespec const* ts_user)
|
||||
ErrorOr<Duration> copy_time_from_user(timespec const* ts_user)
|
||||
{
|
||||
timespec ts {};
|
||||
TRY(copy_from_user(&ts, ts_user, sizeof(timespec)));
|
||||
return Time::from_timespec(ts);
|
||||
return Duration::from_timespec(ts);
|
||||
}
|
||||
|
||||
ErrorOr<Time> copy_time_from_user(timeval const* tv_user)
|
||||
ErrorOr<Duration> copy_time_from_user(timeval const* tv_user)
|
||||
{
|
||||
timeval tv {};
|
||||
TRY(copy_from_user(&tv, tv_user, sizeof(timeval)));
|
||||
return Time::from_timeval(tv);
|
||||
return Duration::from_timeval(tv);
|
||||
}
|
||||
|
||||
template<>
|
||||
ErrorOr<Time> copy_time_from_user<timeval const>(Userspace<timeval const*> src) { return copy_time_from_user(src.unsafe_userspace_ptr()); }
|
||||
ErrorOr<Duration> copy_time_from_user<timeval const>(Userspace<timeval const*> src) { return copy_time_from_user(src.unsafe_userspace_ptr()); }
|
||||
template<>
|
||||
ErrorOr<Time> copy_time_from_user<timeval>(Userspace<timeval*> src) { return copy_time_from_user(src.unsafe_userspace_ptr()); }
|
||||
ErrorOr<Duration> copy_time_from_user<timeval>(Userspace<timeval*> src) { return copy_time_from_user(src.unsafe_userspace_ptr()); }
|
||||
template<>
|
||||
ErrorOr<Time> copy_time_from_user<timespec const>(Userspace<timespec const*> src) { return copy_time_from_user(src.unsafe_userspace_ptr()); }
|
||||
ErrorOr<Duration> copy_time_from_user<timespec const>(Userspace<timespec const*> src) { return copy_time_from_user(src.unsafe_userspace_ptr()); }
|
||||
template<>
|
||||
ErrorOr<Time> copy_time_from_user<timespec>(Userspace<timespec*> src) { return copy_time_from_user(src.unsafe_userspace_ptr()); }
|
||||
ErrorOr<Duration> copy_time_from_user<timespec>(Userspace<timespec*> src) { return copy_time_from_user(src.unsafe_userspace_ptr()); }
|
||||
|
||||
Optional<u32> user_atomic_fetch_add_relaxed(u32 volatile* var, u32 val)
|
||||
{
|
||||
|
@ -15,10 +15,10 @@
|
||||
#include <Kernel/UnixTypes.h>
|
||||
|
||||
ErrorOr<NonnullOwnPtr<Kernel::KString>> try_copy_kstring_from_user(Userspace<char const*>, size_t);
|
||||
ErrorOr<Time> copy_time_from_user(timespec const*);
|
||||
ErrorOr<Time> copy_time_from_user(timeval const*);
|
||||
ErrorOr<Duration> copy_time_from_user(timespec const*);
|
||||
ErrorOr<Duration> copy_time_from_user(timeval const*);
|
||||
template<typename T>
|
||||
ErrorOr<Time> copy_time_from_user(Userspace<T*>);
|
||||
ErrorOr<Duration> copy_time_from_user(Userspace<T*>);
|
||||
|
||||
[[nodiscard]] Optional<u32> user_atomic_fetch_add_relaxed(u32 volatile* var, u32 val);
|
||||
[[nodiscard]] Optional<u32> user_atomic_exchange_relaxed(u32 volatile* var, u32 val);
|
||||
|
@ -50,7 +50,7 @@ UNMAP_AFTER_INIT ErrorOr<void> NVMeController::initialize(bool is_queue_polled)
|
||||
m_controller_regs = TRY(Memory::map_typed_writable<ControllerRegister volatile>(PhysicalAddress(m_bar)));
|
||||
|
||||
auto caps = m_controller_regs->cap;
|
||||
m_ready_timeout = Time::from_milliseconds((CAP_TO(caps) + 1) * 500); // CAP.TO is in 500ms units
|
||||
m_ready_timeout = Duration::from_milliseconds((CAP_TO(caps) + 1) * 500); // CAP.TO is in 500ms units
|
||||
|
||||
calculate_doorbell_stride();
|
||||
// IO queues + 1 admin queue
|
||||
|
@ -74,7 +74,7 @@ private:
|
||||
Memory::TypedMapping<ControllerRegister volatile> m_controller_regs;
|
||||
bool m_admin_queue_ready { false };
|
||||
size_t m_device_count { 0 };
|
||||
AK::Time m_ready_timeout;
|
||||
AK::Duration m_ready_timeout;
|
||||
u32 m_bar { 0 };
|
||||
u8 m_dbl_stride { 0 };
|
||||
PCI::InterruptType m_irq_type;
|
||||
|
@ -20,7 +20,7 @@ ErrorOr<FlatPtr> Process::sys$alarm(unsigned seconds)
|
||||
bool was_in_use = false;
|
||||
if (TimerQueue::the().cancel_timer(*timer, &was_in_use)) {
|
||||
// The timer hasn't fired. Round up the remaining time (if any)
|
||||
Time remaining = timer->remaining() + Time::from_nanoseconds(999'999'999);
|
||||
Duration remaining = timer->remaining() + Duration::from_nanoseconds(999'999'999);
|
||||
previous_alarm_remaining = remaining.to_truncated_seconds();
|
||||
}
|
||||
// We had an existing alarm, must return a non-zero value here!
|
||||
@ -30,7 +30,7 @@ ErrorOr<FlatPtr> Process::sys$alarm(unsigned seconds)
|
||||
|
||||
if (seconds > 0) {
|
||||
auto deadline = TimeManagement::the().current_time(CLOCK_REALTIME_COARSE);
|
||||
deadline = deadline + Time::from_seconds(seconds);
|
||||
deadline = deadline + Duration::from_seconds(seconds);
|
||||
if (!timer) {
|
||||
timer = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) Timer));
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ ErrorOr<FlatPtr> Process::sys$beep(int tone)
|
||||
return EINVAL;
|
||||
#if ARCH(X86_64)
|
||||
PCSpeaker::tone_on(tone);
|
||||
auto result = Thread::current()->sleep(Time::from_nanoseconds(200'000'000));
|
||||
auto result = Thread::current()->sleep(Duration::from_nanoseconds(200'000'000));
|
||||
PCSpeaker::tone_off();
|
||||
if (result.was_interrupted())
|
||||
return EINTR;
|
||||
|
@ -82,7 +82,7 @@ ErrorOr<FlatPtr> Process::sys$clock_nanosleep(Userspace<Syscall::SC_clock_nanosl
|
||||
if (is_absolute) {
|
||||
was_interrupted = Thread::current()->sleep_until(params.clock_id, requested_sleep).was_interrupted();
|
||||
} else {
|
||||
Time remaining_sleep;
|
||||
Duration remaining_sleep;
|
||||
was_interrupted = Thread::current()->sleep(params.clock_id, requested_sleep, &remaining_sleep).was_interrupted();
|
||||
timespec remaining_sleep_ts = remaining_sleep.to_timespec();
|
||||
if (was_interrupted && params.remaining_sleep) {
|
||||
@ -123,7 +123,7 @@ ErrorOr<FlatPtr> Process::sys$adjtime(Userspace<timeval const*> user_delta, User
|
||||
return EPERM;
|
||||
auto delta = TRY(copy_time_from_user(user_delta));
|
||||
|
||||
// FIXME: Should use AK::Time internally
|
||||
// FIXME: Should use AK::Duration internally
|
||||
TimeManagement::the().set_remaining_epoch_time_adjustment(delta.to_timespec());
|
||||
}
|
||||
|
||||
|
@ -19,12 +19,12 @@ ErrorOr<FlatPtr> Process::sys$getrusage(int who, Userspace<rusage*> user_usage)
|
||||
|
||||
switch (who) {
|
||||
case RUSAGE_SELF:
|
||||
usage.ru_utime = Time::from_ticks(m_ticks_in_user, ticks_per_second).to_timeval();
|
||||
usage.ru_stime = Time::from_ticks(m_ticks_in_kernel, ticks_per_second).to_timeval();
|
||||
usage.ru_utime = Duration::from_ticks(m_ticks_in_user, ticks_per_second).to_timeval();
|
||||
usage.ru_stime = Duration::from_ticks(m_ticks_in_kernel, ticks_per_second).to_timeval();
|
||||
break;
|
||||
case RUSAGE_CHILDREN:
|
||||
usage.ru_utime = Time::from_ticks(m_ticks_in_user_for_dead_children, ticks_per_second).to_timeval();
|
||||
usage.ru_stime = Time::from_ticks(m_ticks_in_kernel_for_dead_children, ticks_per_second).to_timeval();
|
||||
usage.ru_utime = Duration::from_ticks(m_ticks_in_user_for_dead_children, ticks_per_second).to_timeval();
|
||||
usage.ru_stime = Duration::from_ticks(m_ticks_in_kernel_for_dead_children, ticks_per_second).to_timeval();
|
||||
break;
|
||||
default:
|
||||
return EINVAL;
|
||||
|
@ -272,7 +272,7 @@ ErrorOr<FlatPtr> Process::sys$recvmsg(int sockfd, Userspace<struct msghdr*> user
|
||||
return 0;
|
||||
|
||||
auto data_buffer = TRY(UserOrKernelBuffer::for_user_buffer((u8*)iovs[0].iov_base, iovs[0].iov_len));
|
||||
Time timestamp {};
|
||||
Duration timestamp {};
|
||||
bool blocking = (flags & MSG_DONTWAIT) ? false : description->is_blocking();
|
||||
auto result = socket.recvfrom(*description, data_buffer, iovs[0].iov_len, flags, user_addr, user_addr_length, timestamp, blocking);
|
||||
|
||||
|
@ -18,7 +18,7 @@ UNMAP_AFTER_INIT void SyncTask::spawn()
|
||||
dbgln("VFS SyncTask is running");
|
||||
for (;;) {
|
||||
VirtualFileSystem::sync();
|
||||
(void)Thread::current()->sleep(Time::from_seconds(1));
|
||||
(void)Thread::current()->sleep(Duration::from_seconds(1));
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
@ -495,14 +495,14 @@ void Thread::relock_process(LockMode previous_locked, u32 lock_count_to_restore)
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE(readability-make-member-function-const) False positive; We call block<SleepBlocker> which is not const
|
||||
auto Thread::sleep(clockid_t clock_id, Time const& duration, Time* remaining_time) -> BlockResult
|
||||
auto Thread::sleep(clockid_t clock_id, Duration const& duration, Duration* remaining_time) -> BlockResult
|
||||
{
|
||||
VERIFY(state() == Thread::State::Running);
|
||||
return Thread::current()->block<Thread::SleepBlocker>({}, Thread::BlockTimeout(false, &duration, nullptr, clock_id), remaining_time);
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE(readability-make-member-function-const) False positive; We call block<SleepBlocker> which is not const
|
||||
auto Thread::sleep_until(clockid_t clock_id, Time const& deadline) -> BlockResult
|
||||
auto Thread::sleep_until(clockid_t clock_id, Duration const& deadline) -> BlockResult
|
||||
{
|
||||
VERIFY(state() == Thread::State::Running);
|
||||
return Thread::current()->block<Thread::SleepBlocker>({}, Thread::BlockTimeout(true, &deadline, nullptr, clock_id));
|
||||
|
@ -159,16 +159,16 @@ public:
|
||||
: m_infinite(true)
|
||||
{
|
||||
}
|
||||
explicit BlockTimeout(bool is_absolute, Time const* time, Time const* start_time = nullptr, clockid_t clock_id = CLOCK_MONOTONIC_COARSE);
|
||||
explicit BlockTimeout(bool is_absolute, Duration const* time, Duration const* start_time = nullptr, clockid_t clock_id = CLOCK_MONOTONIC_COARSE);
|
||||
|
||||
Time const& absolute_time() const { return m_time; }
|
||||
Time const* start_time() const { return !m_infinite ? &m_start_time : nullptr; }
|
||||
Duration const& absolute_time() const { return m_time; }
|
||||
Duration const* start_time() const { return !m_infinite ? &m_start_time : nullptr; }
|
||||
clockid_t clock_id() const { return m_clock_id; }
|
||||
bool is_infinite() const { return m_infinite; }
|
||||
|
||||
private:
|
||||
Time m_time {};
|
||||
Time m_start_time {};
|
||||
Duration m_time {};
|
||||
Duration m_start_time {};
|
||||
clockid_t m_clock_id { CLOCK_MONOTONIC_COARSE };
|
||||
bool m_infinite { false };
|
||||
};
|
||||
@ -559,7 +559,7 @@ public:
|
||||
|
||||
class SleepBlocker final : public Blocker {
|
||||
public:
|
||||
explicit SleepBlocker(BlockTimeout const&, Time* = nullptr);
|
||||
explicit SleepBlocker(BlockTimeout const&, Duration* = nullptr);
|
||||
virtual StringView state_string() const override { return "Sleeping"sv; }
|
||||
virtual Type blocker_type() const override { return Type::Sleep; }
|
||||
virtual BlockTimeout const& override_timeout(BlockTimeout const&) override;
|
||||
@ -571,7 +571,7 @@ public:
|
||||
void calculate_remaining();
|
||||
|
||||
BlockTimeout m_deadline;
|
||||
Time* m_remaining;
|
||||
Duration* m_remaining;
|
||||
};
|
||||
|
||||
class SelectBlocker final : public FileBlocker {
|
||||
@ -824,13 +824,13 @@ public:
|
||||
return block<Thread::WaitQueueBlocker>(timeout, wait_queue, forward<Args>(args)...);
|
||||
}
|
||||
|
||||
BlockResult sleep(clockid_t, Time const&, Time* = nullptr);
|
||||
BlockResult sleep(Time const& duration, Time* remaining_time = nullptr)
|
||||
BlockResult sleep(clockid_t, Duration const&, Duration* = nullptr);
|
||||
BlockResult sleep(Duration const& duration, Duration* remaining_time = nullptr)
|
||||
{
|
||||
return sleep(CLOCK_MONOTONIC_COARSE, duration, remaining_time);
|
||||
}
|
||||
BlockResult sleep_until(clockid_t, Time const&);
|
||||
BlockResult sleep_until(Time const& duration)
|
||||
BlockResult sleep_until(clockid_t, Duration const&);
|
||||
BlockResult sleep_until(Duration const& duration)
|
||||
{
|
||||
return sleep_until(CLOCK_MONOTONIC_COARSE, duration);
|
||||
}
|
||||
|
@ -15,13 +15,13 @@
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
Thread::BlockTimeout::BlockTimeout(bool is_absolute, Time const* time, Time const* start_time, clockid_t clock_id)
|
||||
Thread::BlockTimeout::BlockTimeout(bool is_absolute, Duration const* time, Duration const* start_time, clockid_t clock_id)
|
||||
: m_clock_id(clock_id)
|
||||
, m_infinite(!time)
|
||||
{
|
||||
if (m_infinite)
|
||||
return;
|
||||
if (*time > Time::zero())
|
||||
if (*time > Duration::zero())
|
||||
m_time = *time;
|
||||
m_start_time = start_time ? *start_time : TimeManagement::the().current_time(clock_id);
|
||||
if (!is_absolute)
|
||||
@ -272,7 +272,7 @@ auto Thread::WriteBlocker::override_timeout(BlockTimeout const& timeout) -> Bloc
|
||||
if (description.is_socket()) {
|
||||
auto const& socket = *description.socket();
|
||||
if (socket.has_send_timeout()) {
|
||||
Time send_timeout = socket.send_timeout();
|
||||
Duration send_timeout = socket.send_timeout();
|
||||
m_timeout = BlockTimeout(false, &send_timeout, timeout.start_time(), timeout.clock_id());
|
||||
if (timeout.is_infinite() || (!m_timeout.is_infinite() && m_timeout.absolute_time() < timeout.absolute_time()))
|
||||
return m_timeout;
|
||||
@ -292,7 +292,7 @@ auto Thread::ReadBlocker::override_timeout(BlockTimeout const& timeout) -> Block
|
||||
if (description.is_socket()) {
|
||||
auto const& socket = *description.socket();
|
||||
if (socket.has_receive_timeout()) {
|
||||
Time receive_timeout = socket.receive_timeout();
|
||||
Duration receive_timeout = socket.receive_timeout();
|
||||
m_timeout = BlockTimeout(false, &receive_timeout, timeout.start_time(), timeout.clock_id());
|
||||
if (timeout.is_infinite() || (!m_timeout.is_infinite() && m_timeout.absolute_time() < timeout.absolute_time()))
|
||||
return m_timeout;
|
||||
@ -301,7 +301,7 @@ auto Thread::ReadBlocker::override_timeout(BlockTimeout const& timeout) -> Block
|
||||
return timeout;
|
||||
}
|
||||
|
||||
Thread::SleepBlocker::SleepBlocker(BlockTimeout const& deadline, Time* remaining)
|
||||
Thread::SleepBlocker::SleepBlocker(BlockTimeout const& deadline, Duration* remaining)
|
||||
: m_deadline(deadline)
|
||||
, m_remaining(remaining)
|
||||
{
|
||||
|
@ -77,7 +77,7 @@ ErrorOr<void> TimeManagement::validate_clock_id(clockid_t clock_id)
|
||||
};
|
||||
}
|
||||
|
||||
Time TimeManagement::current_time(clockid_t clock_id) const
|
||||
Duration TimeManagement::current_time(clockid_t clock_id) const
|
||||
{
|
||||
switch (clock_id) {
|
||||
case CLOCK_MONOTONIC:
|
||||
@ -101,15 +101,15 @@ bool TimeManagement::is_system_timer(HardwareTimerBase const& timer) const
|
||||
return &timer == m_system_timer.ptr();
|
||||
}
|
||||
|
||||
void TimeManagement::set_epoch_time(Time ts)
|
||||
void TimeManagement::set_epoch_time(Duration ts)
|
||||
{
|
||||
InterruptDisabler disabler;
|
||||
// FIXME: Should use AK::Time internally
|
||||
// FIXME: Should use AK::Duration internally
|
||||
m_epoch_time = ts.to_timespec();
|
||||
m_remaining_epoch_time_adjustment = { 0, 0 };
|
||||
}
|
||||
|
||||
Time TimeManagement::monotonic_time(TimePrecision precision) const
|
||||
Duration TimeManagement::monotonic_time(TimePrecision precision) const
|
||||
{
|
||||
// This is the time when last updated by an interrupt.
|
||||
u64 seconds;
|
||||
@ -144,10 +144,10 @@ Time 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 Time::from_timespec({ (i64)seconds, (i32)ns });
|
||||
return Duration::from_timespec({ (i64)seconds, (i32)ns });
|
||||
}
|
||||
|
||||
Time TimeManagement::epoch_time(TimePrecision) const
|
||||
Duration TimeManagement::epoch_time(TimePrecision) const
|
||||
{
|
||||
// TODO: Take into account precision
|
||||
timespec ts;
|
||||
@ -156,7 +156,7 @@ Time TimeManagement::epoch_time(TimePrecision) const
|
||||
update_iteration = m_update1.load(AK::MemoryOrder::memory_order_acquire);
|
||||
ts = m_epoch_time;
|
||||
} while (update_iteration != m_update2.load(AK::MemoryOrder::memory_order_acquire));
|
||||
return Time::from_timespec(ts);
|
||||
return Duration::from_timespec(ts);
|
||||
}
|
||||
|
||||
u64 TimeManagement::uptime_ms() const
|
||||
@ -186,14 +186,14 @@ UNMAP_AFTER_INIT void TimeManagement::initialize([[maybe_unused]] u32 cpu)
|
||||
// would trigger a deadlock trying to get the s_the instance while
|
||||
// creating it.
|
||||
if (auto* apic_timer = APIC::the().initialize_timers(*s_the->m_system_timer)) {
|
||||
dmesgln("Time: Using APIC timer as system timer");
|
||||
dmesgln("Duration: Using APIC timer as system timer");
|
||||
s_the->set_system_timer(*apic_timer);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
VERIFY(s_the.is_initialized());
|
||||
if (auto* apic_timer = APIC::the().get_timer()) {
|
||||
dmesgln("Time: Enable APIC timer on CPU #{}", cpu);
|
||||
dmesgln("Duration: Enable APIC timer on CPU #{}", cpu);
|
||||
apic_timer->enable_local_timer();
|
||||
}
|
||||
}
|
||||
@ -226,26 +226,26 @@ time_t TimeManagement::ticks_per_second() const
|
||||
return m_time_keeper_timer->ticks_per_second();
|
||||
}
|
||||
|
||||
Time TimeManagement::boot_time()
|
||||
Duration TimeManagement::boot_time()
|
||||
{
|
||||
#if ARCH(X86_64)
|
||||
return RTC::boot_time();
|
||||
#elif ARCH(AARCH64)
|
||||
// FIXME: Return correct boot time
|
||||
return Time::from_seconds(0);
|
||||
return Duration::from_seconds(0);
|
||||
#else
|
||||
# error Unknown architecture
|
||||
#endif
|
||||
}
|
||||
|
||||
Time TimeManagement::clock_resolution() const
|
||||
Duration TimeManagement::clock_resolution() const
|
||||
{
|
||||
long nanoseconds_per_tick = 1'000'000'000 / m_time_keeper_timer->ticks_per_second();
|
||||
return Time::from_nanoseconds(nanoseconds_per_tick);
|
||||
return Duration::from_nanoseconds(nanoseconds_per_tick);
|
||||
}
|
||||
|
||||
UNMAP_AFTER_INIT TimeManagement::TimeManagement()
|
||||
: m_time_page_region(MM.allocate_kernel_region(PAGE_SIZE, "Time page"sv, Memory::Region::Access::ReadWrite, AllocationStrategy::AllocateNow).release_value_but_fixme_should_propagate_errors())
|
||||
: m_time_page_region(MM.allocate_kernel_region(PAGE_SIZE, "Duration page"sv, Memory::Region::Access::ReadWrite, AllocationStrategy::AllocateNow).release_value_but_fixme_should_propagate_errors())
|
||||
{
|
||||
#if ARCH(X86_64)
|
||||
bool probe_non_legacy_hardware_timers = !(kernel_command_line().is_legacy_time_enabled());
|
||||
@ -275,7 +275,7 @@ UNMAP_AFTER_INIT TimeManagement::TimeManagement()
|
||||
#endif
|
||||
}
|
||||
|
||||
Time TimeManagement::now()
|
||||
Duration TimeManagement::now()
|
||||
{
|
||||
return s_the.ptr()->epoch_time();
|
||||
}
|
||||
@ -283,7 +283,7 @@ Time TimeManagement::now()
|
||||
UNMAP_AFTER_INIT Vector<HardwareTimerBase*> TimeManagement::scan_and_initialize_periodic_timers()
|
||||
{
|
||||
bool should_enable = is_hpet_periodic_mode_allowed();
|
||||
dbgln("Time: Scanning for periodic timers");
|
||||
dbgln("Duration: Scanning for periodic timers");
|
||||
Vector<HardwareTimerBase*> timers;
|
||||
for (auto& hardware_timer : m_hardware_timers) {
|
||||
if (hardware_timer->is_periodic_capable()) {
|
||||
@ -297,7 +297,7 @@ UNMAP_AFTER_INIT Vector<HardwareTimerBase*> TimeManagement::scan_and_initialize_
|
||||
|
||||
UNMAP_AFTER_INIT Vector<HardwareTimerBase*> TimeManagement::scan_for_non_periodic_timers()
|
||||
{
|
||||
dbgln("Time: Scanning for non-periodic timers");
|
||||
dbgln("Duration: Scanning for non-periodic timers");
|
||||
Vector<HardwareTimerBase*> timers;
|
||||
for (auto& hardware_timer : m_hardware_timers) {
|
||||
if (!hardware_timer->is_periodic_capable())
|
||||
|
@ -41,18 +41,18 @@ public:
|
||||
static u64 scheduler_current_time();
|
||||
|
||||
static ErrorOr<void> validate_clock_id(clockid_t);
|
||||
Time current_time(clockid_t) const;
|
||||
Time monotonic_time(TimePrecision = TimePrecision::Coarse) const;
|
||||
Time monotonic_time_raw() const
|
||||
Duration current_time(clockid_t) const;
|
||||
Duration monotonic_time(TimePrecision = TimePrecision::Coarse) const;
|
||||
Duration monotonic_time_raw() const
|
||||
{
|
||||
// TODO: implement
|
||||
return monotonic_time(TimePrecision::Precise);
|
||||
}
|
||||
Time epoch_time(TimePrecision = TimePrecision::Precise) const;
|
||||
void set_epoch_time(Time);
|
||||
Duration epoch_time(TimePrecision = TimePrecision::Precise) const;
|
||||
void set_epoch_time(Duration);
|
||||
time_t ticks_per_second() const;
|
||||
static Time boot_time();
|
||||
Time clock_resolution() const;
|
||||
static Duration boot_time();
|
||||
Duration clock_resolution() const;
|
||||
|
||||
bool is_system_timer(HardwareTimerBase const&) const;
|
||||
|
||||
@ -64,12 +64,12 @@ public:
|
||||
bool disable_profile_timer();
|
||||
|
||||
u64 uptime_ms() const;
|
||||
static Time now();
|
||||
static Duration now();
|
||||
|
||||
// FIXME: Should use AK::Time internally
|
||||
// FIXME: Should use AK::Duration internally
|
||||
// FIXME: Also, most likely broken, because it does not check m_update[12] for in-progress updates.
|
||||
timespec remaining_epoch_time_adjustment() const { return m_remaining_epoch_time_adjustment; }
|
||||
// FIXME: Should use AK::Time internally
|
||||
// FIXME: Should use AK::Duration internally
|
||||
// FIXME: Also, most likely broken, because it does not check m_update[12] for in-progress updates.
|
||||
void set_remaining_epoch_time_adjustment(timespec const& adjustment) { m_remaining_epoch_time_adjustment = adjustment; }
|
||||
|
||||
@ -102,7 +102,7 @@ private:
|
||||
Atomic<u32> m_update1 { 0 };
|
||||
u32 m_ticks_this_second { 0 };
|
||||
u64 m_seconds_since_boot { 0 };
|
||||
// FIXME: Should use AK::Time internally
|
||||
// FIXME: Should use AK::Duration internally
|
||||
timespec m_epoch_time { 0, 0 };
|
||||
timespec m_remaining_epoch_time_adjustment { 0, 0 };
|
||||
Atomic<u32> m_update2 { 0 };
|
||||
|
@ -16,12 +16,12 @@ namespace Kernel {
|
||||
static Singleton<TimerQueue> s_the;
|
||||
static Spinlock<LockRank::None> g_timerqueue_lock {};
|
||||
|
||||
Time Timer::remaining() const
|
||||
Duration Timer::remaining() const
|
||||
{
|
||||
return m_remaining;
|
||||
}
|
||||
|
||||
Time Timer::now(bool is_firing) const
|
||||
Duration Timer::now(bool is_firing) const
|
||||
{
|
||||
// NOTE: If is_firing is true then TimePrecision::Precise isn't really useful here.
|
||||
// We already have a quite precise time stamp because we just updated the time in the
|
||||
@ -55,7 +55,7 @@ UNMAP_AFTER_INIT TimerQueue::TimerQueue()
|
||||
m_ticks_per_second = TimeManagement::the().ticks_per_second();
|
||||
}
|
||||
|
||||
bool TimerQueue::add_timer_without_id(NonnullRefPtr<Timer> timer, clockid_t clock_id, Time const& deadline, Function<void()>&& callback)
|
||||
bool TimerQueue::add_timer_without_id(NonnullRefPtr<Timer> timer, clockid_t clock_id, Duration const& deadline, Function<void()>&& callback)
|
||||
{
|
||||
if (deadline <= TimeManagement::the().current_time(clock_id))
|
||||
return false;
|
||||
@ -86,7 +86,7 @@ TimerId TimerQueue::add_timer(NonnullRefPtr<Timer>&& timer)
|
||||
|
||||
void TimerQueue::add_timer_locked(NonnullRefPtr<Timer> timer)
|
||||
{
|
||||
Time timer_expiration = timer->m_expires;
|
||||
Duration timer_expiration = timer->m_expires;
|
||||
|
||||
timer->clear_cancelled();
|
||||
timer->clear_callback_finished();
|
||||
|
@ -22,7 +22,7 @@ class Timer final : public AtomicRefCounted<Timer> {
|
||||
friend class TimerQueue;
|
||||
|
||||
public:
|
||||
void setup(clockid_t clock_id, Time expires, Function<void()>&& callback)
|
||||
void setup(clockid_t clock_id, Duration expires, Function<void()>&& callback)
|
||||
{
|
||||
VERIFY(!is_queued());
|
||||
m_clock_id = clock_id;
|
||||
@ -35,13 +35,13 @@ public:
|
||||
VERIFY(!is_queued());
|
||||
}
|
||||
|
||||
Time remaining() const;
|
||||
Duration remaining() const;
|
||||
|
||||
private:
|
||||
TimerId m_id;
|
||||
clockid_t m_clock_id;
|
||||
Time m_expires;
|
||||
Time m_remaining {};
|
||||
Duration m_expires;
|
||||
Duration m_remaining {};
|
||||
Function<void()> m_callback;
|
||||
Atomic<bool> m_cancelled { false };
|
||||
Atomic<bool> m_callback_finished { false };
|
||||
@ -71,7 +71,7 @@ private:
|
||||
void clear_callback_finished() { m_callback_finished.store(false, AK::memory_order_release); }
|
||||
void set_callback_finished() { m_callback_finished.store(true, AK::memory_order_release); }
|
||||
|
||||
Time now(bool) const;
|
||||
Duration now(bool) const;
|
||||
|
||||
bool is_queued() const { return m_list_node.is_in_list(); }
|
||||
|
||||
@ -88,14 +88,14 @@ public:
|
||||
static TimerQueue& the();
|
||||
|
||||
TimerId add_timer(NonnullRefPtr<Timer>&&);
|
||||
bool add_timer_without_id(NonnullRefPtr<Timer>, clockid_t, Time const&, Function<void()>&&);
|
||||
bool add_timer_without_id(NonnullRefPtr<Timer>, clockid_t, Duration const&, Function<void()>&&);
|
||||
bool cancel_timer(Timer& timer, bool* was_in_use = nullptr);
|
||||
void fire();
|
||||
|
||||
private:
|
||||
struct Queue {
|
||||
Timer::List list;
|
||||
Time next_timer_due {};
|
||||
Duration next_timer_due {};
|
||||
};
|
||||
void remove_timer_locked(Queue&, Timer&);
|
||||
void update_next_timer_due(Queue&);
|
||||
|
@ -110,7 +110,7 @@ struct AK::Formatter<DaylightSavingsOffset> : Formatter<FormatString> {
|
||||
ErrorOr<void> format(FormatBuilder& builder, DaylightSavingsOffset const& dst_offset)
|
||||
{
|
||||
auto format_time = [&](auto year) {
|
||||
return DeprecatedString::formatted("AK::Time::from_timestamp({}, 1, 1, 0, 0, 0, 0)", year);
|
||||
return DeprecatedString::formatted("AK::Duration::from_timestamp({}, 1, 1, 0, 0, 0, 0)", year);
|
||||
};
|
||||
|
||||
static DeprecatedString max_year_as_time("max_year_as_time"sv);
|
||||
@ -494,13 +494,13 @@ static ErrorOr<void> generate_time_zone_data_implementation(Core::InputBufferedF
|
||||
|
||||
namespace TimeZone {
|
||||
|
||||
static constexpr auto max_year_as_time = AK::Time::from_timestamp(NumericLimits<u16>::max(), 1, 1, 0, 0, 0, 0);
|
||||
static constexpr auto max_year_as_time = AK::Duration::from_timestamp(NumericLimits<u16>::max(), 1, 1, 0, 0, 0, 0);
|
||||
|
||||
struct DateTime {
|
||||
AK::Time time_since_epoch() const
|
||||
AK::Duration time_since_epoch() const
|
||||
{
|
||||
// FIXME: This implementation does not take last_weekday, after_weekday, or before_weekday into account.
|
||||
return AK::Time::from_timestamp(year, month, day, hour, minute, second, 0);
|
||||
return AK::Duration::from_timestamp(year, month, day, hour, minute, second, 0);
|
||||
}
|
||||
|
||||
u16 year { 0 };
|
||||
@ -530,7 +530,7 @@ struct TimeZoneOffset {
|
||||
};
|
||||
|
||||
struct DaylightSavingsOffset {
|
||||
AK::Time time_in_effect(AK::Time time) const
|
||||
AK::Duration time_in_effect(AK::Duration time) const
|
||||
{
|
||||
auto in_effect = this->in_effect;
|
||||
in_effect.year = seconds_since_epoch_to_year(time.to_seconds());
|
||||
@ -539,8 +539,8 @@ struct DaylightSavingsOffset {
|
||||
}
|
||||
|
||||
i64 offset { 0 };
|
||||
AK::Time year_from {};
|
||||
AK::Time year_to {};
|
||||
AK::Duration year_from {};
|
||||
AK::Duration year_to {};
|
||||
DateTime in_effect {};
|
||||
|
||||
@string_index_type@ format { 0 };
|
||||
@ -635,7 +635,7 @@ static constexpr Array<Location, @size@> s_time_zone_locations { {
|
||||
TRY(append_string_conversions("Region"sv, "region"sv, time_zone_data.time_zone_region_names));
|
||||
|
||||
generator.append(R"~~~(
|
||||
static Array<DaylightSavingsOffset const*, 2> find_dst_offsets(TimeZoneOffset const& time_zone_offset, AK::Time time)
|
||||
static Array<DaylightSavingsOffset const*, 2> find_dst_offsets(TimeZoneOffset const& time_zone_offset, AK::Duration time)
|
||||
{
|
||||
auto const& dst_rules = s_dst_offsets[time_zone_offset.dst_rule];
|
||||
|
||||
@ -677,7 +677,7 @@ static Array<DaylightSavingsOffset const*, 2> find_dst_offsets(TimeZoneOffset co
|
||||
return { standard_offset, daylight_offset ? daylight_offset : standard_offset };
|
||||
}
|
||||
|
||||
static Offset get_active_dst_offset(TimeZoneOffset const& time_zone_offset, AK::Time time)
|
||||
static Offset get_active_dst_offset(TimeZoneOffset const& time_zone_offset, AK::Duration time)
|
||||
{
|
||||
auto offsets = find_dst_offsets(time_zone_offset, time);
|
||||
if (offsets[0] == offsets[1])
|
||||
@ -697,7 +697,7 @@ static Offset get_active_dst_offset(TimeZoneOffset const& time_zone_offset, AK::
|
||||
return { offsets[1]->offset, InDST::Yes };
|
||||
}
|
||||
|
||||
static TimeZoneOffset const& find_time_zone_offset(TimeZone time_zone, AK::Time time)
|
||||
static TimeZoneOffset const& find_time_zone_offset(TimeZone time_zone, AK::Duration time)
|
||||
{
|
||||
auto const& time_zone_offsets = s_time_zone_offsets[to_underlying(time_zone)];
|
||||
|
||||
@ -713,7 +713,7 @@ static TimeZoneOffset const& find_time_zone_offset(TimeZone time_zone, AK::Time
|
||||
return time_zone_offsets[index];
|
||||
}
|
||||
|
||||
Optional<Offset> get_time_zone_offset(TimeZone time_zone, AK::Time time)
|
||||
Optional<Offset> get_time_zone_offset(TimeZone time_zone, AK::Duration time)
|
||||
{
|
||||
auto const& time_zone_offset = find_time_zone_offset(time_zone, time);
|
||||
|
||||
@ -729,7 +729,7 @@ Optional<Offset> get_time_zone_offset(TimeZone time_zone, AK::Time time)
|
||||
return dst_offset;
|
||||
}
|
||||
|
||||
Optional<Array<NamedOffset, 2>> get_named_time_zone_offsets(TimeZone time_zone, AK::Time time)
|
||||
Optional<Array<NamedOffset, 2>> get_named_time_zone_offsets(TimeZone time_zone, AK::Duration time)
|
||||
{
|
||||
auto const& time_zone_offset = find_time_zone_offset(time_zone, time);
|
||||
Array<NamedOffset, 2> named_offsets;
|
||||
|
@ -316,7 +316,7 @@ index 0000000000000000000000000000000000000000..e1cd5348b67c23c49b25f99f4f36e020
|
||||
+ return (static_cast<double>(input) - NumericLimits<i16>::min()) / NumericLimits<u16>::max() * 2. - 1.;
|
||||
+ };
|
||||
+
|
||||
+ auto const sleep_spec = Time::from_nanoseconds(100).to_timespec();
|
||||
+ auto const sleep_spec = Duration::from_nanoseconds(100).to_timespec();
|
||||
+ auto input_buffer = reinterpret_cast<i16*>(h->mixbuf);
|
||||
+ auto input_samples = h->mixlen / that->spec.channels / sizeof(i16);
|
||||
+ size_t input_position = 0;
|
||||
|
@ -74,7 +74,7 @@ set(AK_TEST_SOURCES
|
||||
TestStringFloatingPointConversions.cpp
|
||||
TestStringUtils.cpp
|
||||
TestStringView.cpp
|
||||
TestTime.cpp
|
||||
TestDuration.cpp
|
||||
TestTrie.cpp
|
||||
TestTuple.cpp
|
||||
TestTypeTraits.cpp
|
||||
|
@ -9,7 +9,7 @@
|
||||
#include <AK/Time.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#define EXPECT_TIME(t, s, ns) \
|
||||
#define EXPECT_DURATION(t, s, ns) \
|
||||
do { \
|
||||
auto ts = (t).to_timespec(); \
|
||||
EXPECT_EQ(ts.tv_sec, (s)); \
|
||||
@ -18,116 +18,116 @@
|
||||
|
||||
TEST_CASE(is_sane)
|
||||
{
|
||||
auto t0 = Time::from_seconds(0);
|
||||
auto t2 = Time::from_seconds(2);
|
||||
auto t5 = Time::from_seconds(5);
|
||||
auto tn3 = Time::from_seconds(-3);
|
||||
auto t0 = Duration::from_seconds(0);
|
||||
auto t2 = Duration::from_seconds(2);
|
||||
auto t5 = Duration::from_seconds(5);
|
||||
auto tn3 = Duration::from_seconds(-3);
|
||||
EXPECT(t0 == t0);
|
||||
EXPECT(t2 == t2);
|
||||
EXPECT(t5 == t5);
|
||||
EXPECT(t0 != t2);
|
||||
EXPECT(t2 != tn3);
|
||||
EXPECT(t2 != t5);
|
||||
EXPECT_TIME(t0, 0, 0);
|
||||
EXPECT_TIME(t2, 2, 0);
|
||||
EXPECT_TIME(t5, 5, 0);
|
||||
EXPECT_TIME(t2 + t5, 7, 0);
|
||||
EXPECT_TIME(tn3 + t2, -1, 0);
|
||||
EXPECT_TIME(tn3 + t5, 2, 0);
|
||||
EXPECT_DURATION(t0, 0, 0);
|
||||
EXPECT_DURATION(t2, 2, 0);
|
||||
EXPECT_DURATION(t5, 5, 0);
|
||||
EXPECT_DURATION(t2 + t5, 7, 0);
|
||||
EXPECT_DURATION(tn3 + t2, -1, 0);
|
||||
EXPECT_DURATION(tn3 + t5, 2, 0);
|
||||
}
|
||||
|
||||
TEST_CASE(limits)
|
||||
{
|
||||
EXPECT_TIME(Time::min(), (i64)-0x8000'0000'0000'0000, 0);
|
||||
EXPECT_TIME(Time::max(), 0x7fff'ffff'ffff'ffff, 999'999'999);
|
||||
EXPECT_DURATION(Duration::min(), (i64)-0x8000'0000'0000'0000, 0);
|
||||
EXPECT_DURATION(Duration::max(), 0x7fff'ffff'ffff'ffff, 999'999'999);
|
||||
}
|
||||
|
||||
TEST_CASE(seconds_parsing)
|
||||
{
|
||||
EXPECT_TIME(Time::from_seconds(0), 0, 0);
|
||||
EXPECT_TIME(Time::from_seconds(42), 42, 0);
|
||||
EXPECT_TIME(Time::from_seconds(-1), -1, 0);
|
||||
EXPECT_DURATION(Duration::from_seconds(0), 0, 0);
|
||||
EXPECT_DURATION(Duration::from_seconds(42), 42, 0);
|
||||
EXPECT_DURATION(Duration::from_seconds(-1), -1, 0);
|
||||
|
||||
// "6.4.4.1.5: The type of an integer constant is the first of the corresponding list in which its value can be represented."
|
||||
// In the case of "0x8000'0000", the list is "int, unsigned int, …", and unsigned int (u32) matches.
|
||||
// Then the unary minus: On unsigned 32-bit integers, -0x8000'0000 == 0x8000'0000, which only then is made signed again.
|
||||
// So we would pass a medium-large *positive* number to 'from_seconds', which is not what we want to test here.
|
||||
// That's why this is the only place that needs an "LL" suffix.
|
||||
EXPECT_TIME(Time::from_seconds(-0x8000'0000LL), -0x8000'0000LL, 0);
|
||||
EXPECT_TIME(Time::from_seconds(-0x8000'0000'0000'0000), (i64)-0x8000'0000'0000'0000, 0);
|
||||
EXPECT_TIME(Time::from_seconds(0x7fff'ffff'ffff'ffff), 0x7fff'ffff'ffff'ffff, 0);
|
||||
EXPECT_DURATION(Duration::from_seconds(-0x8000'0000LL), -0x8000'0000LL, 0);
|
||||
EXPECT_DURATION(Duration::from_seconds(-0x8000'0000'0000'0000), (i64)-0x8000'0000'0000'0000, 0);
|
||||
EXPECT_DURATION(Duration::from_seconds(0x7fff'ffff'ffff'ffff), 0x7fff'ffff'ffff'ffff, 0);
|
||||
}
|
||||
|
||||
TEST_CASE(timespec_parsing)
|
||||
{
|
||||
EXPECT_TIME(Time::from_timespec(timespec { 2, 4 }), 2, 4);
|
||||
EXPECT_TIME(Time::from_timespec(timespec { 1234, 5678 }), 1234, 5678);
|
||||
EXPECT_DURATION(Duration::from_timespec(timespec { 2, 4 }), 2, 4);
|
||||
EXPECT_DURATION(Duration::from_timespec(timespec { 1234, 5678 }), 1234, 5678);
|
||||
|
||||
EXPECT_TIME(Time::from_timespec(timespec { 0, 1'000'000'000 }), 1, 0);
|
||||
EXPECT_TIME(Time::from_timespec(timespec { 8, 2'000'000'000 }), 10, 0);
|
||||
EXPECT_TIME(Time::from_timespec(timespec { 0, 2'147'483'647 }), 2, 147'483'647);
|
||||
EXPECT_DURATION(Duration::from_timespec(timespec { 0, 1'000'000'000 }), 1, 0);
|
||||
EXPECT_DURATION(Duration::from_timespec(timespec { 8, 2'000'000'000 }), 10, 0);
|
||||
EXPECT_DURATION(Duration::from_timespec(timespec { 0, 2'147'483'647 }), 2, 147'483'647);
|
||||
|
||||
EXPECT_TIME(Time::from_timespec(timespec { 1, -1 }), 0, 999'999'999);
|
||||
EXPECT_TIME(Time::from_timespec(timespec { 0, -1 }), -1, 999'999'999);
|
||||
EXPECT_TIME(Time::from_timespec(timespec { -1, 0 }), -1, 0);
|
||||
EXPECT_TIME(Time::from_timespec(timespec { -1, 1'000'000'001 }), 0, 1);
|
||||
EXPECT_TIME(Time::from_timespec(timespec { -2, 2'000'000'003 }), 0, 3);
|
||||
EXPECT_TIME(Time::from_timespec(timespec { -2, 1'999'999'999 }), -1, 999'999'999);
|
||||
EXPECT_DURATION(Duration::from_timespec(timespec { 1, -1 }), 0, 999'999'999);
|
||||
EXPECT_DURATION(Duration::from_timespec(timespec { 0, -1 }), -1, 999'999'999);
|
||||
EXPECT_DURATION(Duration::from_timespec(timespec { -1, 0 }), -1, 0);
|
||||
EXPECT_DURATION(Duration::from_timespec(timespec { -1, 1'000'000'001 }), 0, 1);
|
||||
EXPECT_DURATION(Duration::from_timespec(timespec { -2, 2'000'000'003 }), 0, 3);
|
||||
EXPECT_DURATION(Duration::from_timespec(timespec { -2, 1'999'999'999 }), -1, 999'999'999);
|
||||
|
||||
EXPECT_TIME(Time::from_timespec(timespec { 0x7fff'ffff'ffff'fffe, 999'999'998 }), 0x7fff'ffff'ffff'fffe, 999'999'998);
|
||||
EXPECT_TIME(Time::from_timespec(timespec { 0x7fff'ffff'ffff'fffe, 1'999'999'998 }), 0x7fff'ffff'ffff'ffff, 999'999'998);
|
||||
EXPECT_TIME(Time::from_timespec(timespec { 0x7fff'ffff'ffff'fffe, 1'999'999'999 }), 0x7fff'ffff'ffff'ffff, 999'999'999);
|
||||
EXPECT_TIME(Time::from_timespec(timespec { 0x7fff'ffff'ffff'fffe, 2'000'000'000 }), 0x7fff'ffff'ffff'ffff, 999'999'999);
|
||||
EXPECT_DURATION(Duration::from_timespec(timespec { 0x7fff'ffff'ffff'fffe, 999'999'998 }), 0x7fff'ffff'ffff'fffe, 999'999'998);
|
||||
EXPECT_DURATION(Duration::from_timespec(timespec { 0x7fff'ffff'ffff'fffe, 1'999'999'998 }), 0x7fff'ffff'ffff'ffff, 999'999'998);
|
||||
EXPECT_DURATION(Duration::from_timespec(timespec { 0x7fff'ffff'ffff'fffe, 1'999'999'999 }), 0x7fff'ffff'ffff'ffff, 999'999'999);
|
||||
EXPECT_DURATION(Duration::from_timespec(timespec { 0x7fff'ffff'ffff'fffe, 2'000'000'000 }), 0x7fff'ffff'ffff'ffff, 999'999'999);
|
||||
|
||||
EXPECT_TIME(Time::from_timespec(timespec { -0x7fff'ffff'ffff'fffe, -1 }), -0x7fff'ffff'ffff'ffff, 999'999'999);
|
||||
EXPECT_TIME(Time::from_timespec(timespec { -0x7fff'ffff'ffff'fffe, -999'999'999 }), -0x7fff'ffff'ffff'ffff, 1);
|
||||
EXPECT_TIME(Time::from_timespec(timespec { -0x7fff'ffff'ffff'fffe, -1'999'999'999 }), (i64)-0x8000'0000'0000'0000, 1);
|
||||
EXPECT_TIME(Time::from_timespec(timespec { -0x7fff'ffff'ffff'fffe, -2'000'000'000 }), (i64)-0x8000'0000'0000'0000, 0);
|
||||
EXPECT_TIME(Time::from_timespec(timespec { -0x7fff'ffff'ffff'fffe, -2'000'000'001 }), (i64)-0x8000'0000'0000'0000, 0);
|
||||
EXPECT_DURATION(Duration::from_timespec(timespec { -0x7fff'ffff'ffff'fffe, -1 }), -0x7fff'ffff'ffff'ffff, 999'999'999);
|
||||
EXPECT_DURATION(Duration::from_timespec(timespec { -0x7fff'ffff'ffff'fffe, -999'999'999 }), -0x7fff'ffff'ffff'ffff, 1);
|
||||
EXPECT_DURATION(Duration::from_timespec(timespec { -0x7fff'ffff'ffff'fffe, -1'999'999'999 }), (i64)-0x8000'0000'0000'0000, 1);
|
||||
EXPECT_DURATION(Duration::from_timespec(timespec { -0x7fff'ffff'ffff'fffe, -2'000'000'000 }), (i64)-0x8000'0000'0000'0000, 0);
|
||||
EXPECT_DURATION(Duration::from_timespec(timespec { -0x7fff'ffff'ffff'fffe, -2'000'000'001 }), (i64)-0x8000'0000'0000'0000, 0);
|
||||
}
|
||||
|
||||
TEST_CASE(timeval_parsing)
|
||||
{
|
||||
EXPECT_TIME(Time::from_timeval(timeval { 2, 4 }), 2, 4'000);
|
||||
EXPECT_TIME(Time::from_timeval(timeval { 1234, 5'678 }), 1234, 5'678'000);
|
||||
EXPECT_TIME(Time::from_timeval(timeval { -123, -45'678 }), -124, 954'322'000);
|
||||
EXPECT_DURATION(Duration::from_timeval(timeval { 2, 4 }), 2, 4'000);
|
||||
EXPECT_DURATION(Duration::from_timeval(timeval { 1234, 5'678 }), 1234, 5'678'000);
|
||||
EXPECT_DURATION(Duration::from_timeval(timeval { -123, -45'678 }), -124, 954'322'000);
|
||||
|
||||
EXPECT_TIME(Time::from_timeval(timeval { 0, 1'000'000 }), 1, 0);
|
||||
EXPECT_TIME(Time::from_timeval(timeval { 0, 1'000'000'000 }), 1'000, 0);
|
||||
EXPECT_TIME(Time::from_timeval(timeval { 8, 2'000'000 }), 10, 0);
|
||||
EXPECT_TIME(Time::from_timeval(timeval { 0, 2'147'483'647 }), 2'147, 483'647'000);
|
||||
EXPECT_DURATION(Duration::from_timeval(timeval { 0, 1'000'000 }), 1, 0);
|
||||
EXPECT_DURATION(Duration::from_timeval(timeval { 0, 1'000'000'000 }), 1'000, 0);
|
||||
EXPECT_DURATION(Duration::from_timeval(timeval { 8, 2'000'000 }), 10, 0);
|
||||
EXPECT_DURATION(Duration::from_timeval(timeval { 0, 2'147'483'647 }), 2'147, 483'647'000);
|
||||
|
||||
EXPECT_TIME(Time::from_timeval(timeval { 1, -1 }), 0, 999'999'000);
|
||||
EXPECT_TIME(Time::from_timeval(timeval { 0, -1 }), -1, 999'999'000);
|
||||
EXPECT_TIME(Time::from_timeval(timeval { -1, 0 }), -1, 0);
|
||||
EXPECT_TIME(Time::from_timeval(timeval { -1, 1'000'001 }), 0, 1'000);
|
||||
EXPECT_TIME(Time::from_timeval(timeval { -2, 2'000'003 }), 0, 3'000);
|
||||
EXPECT_TIME(Time::from_timeval(timeval { -2, 1'999'999 }), -1, 999'999'000);
|
||||
EXPECT_DURATION(Duration::from_timeval(timeval { 1, -1 }), 0, 999'999'000);
|
||||
EXPECT_DURATION(Duration::from_timeval(timeval { 0, -1 }), -1, 999'999'000);
|
||||
EXPECT_DURATION(Duration::from_timeval(timeval { -1, 0 }), -1, 0);
|
||||
EXPECT_DURATION(Duration::from_timeval(timeval { -1, 1'000'001 }), 0, 1'000);
|
||||
EXPECT_DURATION(Duration::from_timeval(timeval { -2, 2'000'003 }), 0, 3'000);
|
||||
EXPECT_DURATION(Duration::from_timeval(timeval { -2, 1'999'999 }), -1, 999'999'000);
|
||||
|
||||
EXPECT_TIME(Time::from_timeval(timeval { 0x7fff'ffff'ffff'fffe, 999'998 }), 0x7fff'ffff'ffff'fffe, 999'998'000);
|
||||
EXPECT_TIME(Time::from_timeval(timeval { 0x7fff'ffff'ffff'fffe, 1'999'998 }), 0x7fff'ffff'ffff'ffff, 999'998'000);
|
||||
EXPECT_TIME(Time::from_timeval(timeval { 0x7fff'ffff'ffff'fffe, 1'999'999 }), 0x7fff'ffff'ffff'ffff, 999'999'000);
|
||||
EXPECT_TIME(Time::from_timeval(timeval { 0x7fff'ffff'ffff'fffe, 2'000'000 }), 0x7fff'ffff'ffff'ffff, 999'999'999);
|
||||
EXPECT_DURATION(Duration::from_timeval(timeval { 0x7fff'ffff'ffff'fffe, 999'998 }), 0x7fff'ffff'ffff'fffe, 999'998'000);
|
||||
EXPECT_DURATION(Duration::from_timeval(timeval { 0x7fff'ffff'ffff'fffe, 1'999'998 }), 0x7fff'ffff'ffff'ffff, 999'998'000);
|
||||
EXPECT_DURATION(Duration::from_timeval(timeval { 0x7fff'ffff'ffff'fffe, 1'999'999 }), 0x7fff'ffff'ffff'ffff, 999'999'000);
|
||||
EXPECT_DURATION(Duration::from_timeval(timeval { 0x7fff'ffff'ffff'fffe, 2'000'000 }), 0x7fff'ffff'ffff'ffff, 999'999'999);
|
||||
|
||||
EXPECT_TIME(Time::from_timeval(timeval { -0x7fff'ffff'ffff'fffe, -1 }), -0x7fff'ffff'ffff'ffff, 999'999'000);
|
||||
EXPECT_TIME(Time::from_timeval(timeval { -0x7fff'ffff'ffff'fffe, -999'999 }), -0x7fff'ffff'ffff'ffff, 1'000);
|
||||
EXPECT_TIME(Time::from_timeval(timeval { -0x7fff'ffff'ffff'fffe, -1'999'999 }), (i64)-0x8000'0000'0000'0000, 1'000);
|
||||
EXPECT_TIME(Time::from_timeval(timeval { -0x7fff'ffff'ffff'fffe, -2'000'000 }), (i64)-0x8000'0000'0000'0000, 0);
|
||||
EXPECT_TIME(Time::from_timeval(timeval { -0x7fff'ffff'ffff'fffe, -2'000'001 }), (i64)-0x8000'0000'0000'0000, 0);
|
||||
EXPECT_DURATION(Duration::from_timeval(timeval { -0x7fff'ffff'ffff'fffe, -1 }), -0x7fff'ffff'ffff'ffff, 999'999'000);
|
||||
EXPECT_DURATION(Duration::from_timeval(timeval { -0x7fff'ffff'ffff'fffe, -999'999 }), -0x7fff'ffff'ffff'ffff, 1'000);
|
||||
EXPECT_DURATION(Duration::from_timeval(timeval { -0x7fff'ffff'ffff'fffe, -1'999'999 }), (i64)-0x8000'0000'0000'0000, 1'000);
|
||||
EXPECT_DURATION(Duration::from_timeval(timeval { -0x7fff'ffff'ffff'fffe, -2'000'000 }), (i64)-0x8000'0000'0000'0000, 0);
|
||||
EXPECT_DURATION(Duration::from_timeval(timeval { -0x7fff'ffff'ffff'fffe, -2'000'001 }), (i64)-0x8000'0000'0000'0000, 0);
|
||||
}
|
||||
|
||||
#define TIME(s, ns) \
|
||||
Time::from_timespec(timespec { (s), (ns) })
|
||||
#define DURATION(s, ns) \
|
||||
Duration::from_timespec(timespec { (s), (ns) })
|
||||
|
||||
TEST_CASE(addition)
|
||||
{
|
||||
#define EXPECT_ADDITION(s1, ns1, s2, ns2, sr, nsr) \
|
||||
do { \
|
||||
EXPECT_TIME(TIME(s1, ns1) + TIME(s2, ns2), sr, nsr); \
|
||||
EXPECT_TIME(TIME(s2, ns2) + TIME(s1, ns1), sr, nsr); \
|
||||
auto t = TIME(s1, ns1); \
|
||||
t += TIME(s2, ns2); \
|
||||
EXPECT_TIME(t, sr, nsr); \
|
||||
#define EXPECT_ADDITION(s1, ns1, s2, ns2, sr, nsr) \
|
||||
do { \
|
||||
EXPECT_DURATION(DURATION(s1, ns1) + DURATION(s2, ns2), sr, nsr); \
|
||||
EXPECT_DURATION(DURATION(s2, ns2) + DURATION(s1, ns1), sr, nsr); \
|
||||
auto t = DURATION(s1, ns1); \
|
||||
t += DURATION(s2, ns2); \
|
||||
EXPECT_DURATION(t, sr, nsr); \
|
||||
} while (0)
|
||||
|
||||
EXPECT_ADDITION(11, 123'456'789, 22, 900'000'000, 34, 23'456'789);
|
||||
@ -156,12 +156,12 @@ TEST_CASE(addition)
|
||||
|
||||
TEST_CASE(subtraction)
|
||||
{
|
||||
#define EXPECT_SUBTRACTION(s1, ns1, s2, ns2, sr, nsr) \
|
||||
do { \
|
||||
EXPECT_TIME(TIME(s1, ns1) - TIME(s2, ns2), sr, nsr); \
|
||||
auto t = TIME(s1, ns1); \
|
||||
t -= TIME(s2, ns2); \
|
||||
EXPECT_TIME(t, sr, nsr); \
|
||||
#define EXPECT_SUBTRACTION(s1, ns1, s2, ns2, sr, nsr) \
|
||||
do { \
|
||||
EXPECT_DURATION(DURATION(s1, ns1) - DURATION(s2, ns2), sr, nsr); \
|
||||
auto t = DURATION(s1, ns1); \
|
||||
t -= DURATION(s2, ns2); \
|
||||
EXPECT_DURATION(t, sr, nsr); \
|
||||
} while (0)
|
||||
|
||||
EXPECT_SUBTRACTION(5, 0, 3, 0, 2, 0);
|
||||
@ -194,78 +194,78 @@ TEST_CASE(subtraction)
|
||||
|
||||
TEST_CASE(rounding)
|
||||
{
|
||||
EXPECT_EQ(TIME(2, 800'800'800).to_seconds(), 3);
|
||||
EXPECT_EQ(TIME(2, 800'800'800).to_milliseconds(), 2'801);
|
||||
EXPECT_EQ(TIME(2, 800'800'800).to_microseconds(), 2'800'801);
|
||||
EXPECT_EQ(TIME(2, 800'800'800).to_nanoseconds(), 2'800'800'800);
|
||||
EXPECT_EQ(TIME(-2, 800'800'800).to_seconds(), -2);
|
||||
EXPECT_EQ(TIME(-2, 800'800'800).to_milliseconds(), -1'200);
|
||||
EXPECT_EQ(TIME(-2, 800'800'800).to_microseconds(), -1'199'200);
|
||||
EXPECT_EQ(TIME(-2, 800'800'800).to_nanoseconds(), -1'199'199'200);
|
||||
EXPECT_EQ(DURATION(2, 800'800'800).to_seconds(), 3);
|
||||
EXPECT_EQ(DURATION(2, 800'800'800).to_milliseconds(), 2'801);
|
||||
EXPECT_EQ(DURATION(2, 800'800'800).to_microseconds(), 2'800'801);
|
||||
EXPECT_EQ(DURATION(2, 800'800'800).to_nanoseconds(), 2'800'800'800);
|
||||
EXPECT_EQ(DURATION(-2, 800'800'800).to_seconds(), -2);
|
||||
EXPECT_EQ(DURATION(-2, 800'800'800).to_milliseconds(), -1'200);
|
||||
EXPECT_EQ(DURATION(-2, 800'800'800).to_microseconds(), -1'199'200);
|
||||
EXPECT_EQ(DURATION(-2, 800'800'800).to_nanoseconds(), -1'199'199'200);
|
||||
|
||||
EXPECT_EQ(TIME(0, 0).to_seconds(), 0);
|
||||
EXPECT_EQ(TIME(0, 0).to_milliseconds(), 0);
|
||||
EXPECT_EQ(TIME(0, 0).to_microseconds(), 0);
|
||||
EXPECT_EQ(TIME(0, 0).to_nanoseconds(), 0);
|
||||
EXPECT_EQ(DURATION(0, 0).to_seconds(), 0);
|
||||
EXPECT_EQ(DURATION(0, 0).to_milliseconds(), 0);
|
||||
EXPECT_EQ(DURATION(0, 0).to_microseconds(), 0);
|
||||
EXPECT_EQ(DURATION(0, 0).to_nanoseconds(), 0);
|
||||
|
||||
EXPECT_EQ(TIME(0, 1).to_seconds(), 1);
|
||||
EXPECT_EQ(TIME(0, 1).to_milliseconds(), 1);
|
||||
EXPECT_EQ(TIME(0, 1).to_microseconds(), 1);
|
||||
EXPECT_EQ(TIME(0, 1).to_nanoseconds(), 1);
|
||||
EXPECT_EQ(TIME(0, -1).to_seconds(), -1);
|
||||
EXPECT_EQ(TIME(0, -1).to_milliseconds(), -1);
|
||||
EXPECT_EQ(TIME(0, -1).to_microseconds(), -1);
|
||||
EXPECT_EQ(TIME(0, -1).to_nanoseconds(), -1);
|
||||
EXPECT_EQ(DURATION(0, 1).to_seconds(), 1);
|
||||
EXPECT_EQ(DURATION(0, 1).to_milliseconds(), 1);
|
||||
EXPECT_EQ(DURATION(0, 1).to_microseconds(), 1);
|
||||
EXPECT_EQ(DURATION(0, 1).to_nanoseconds(), 1);
|
||||
EXPECT_EQ(DURATION(0, -1).to_seconds(), -1);
|
||||
EXPECT_EQ(DURATION(0, -1).to_milliseconds(), -1);
|
||||
EXPECT_EQ(DURATION(0, -1).to_microseconds(), -1);
|
||||
EXPECT_EQ(DURATION(0, -1).to_nanoseconds(), -1);
|
||||
|
||||
EXPECT_EQ(TIME(-9223372037, 145'224'191).to_nanoseconds(), (i64)-0x8000'0000'0000'0000);
|
||||
EXPECT_EQ(TIME(-9223372037, 145'224'192).to_nanoseconds(), (i64)-0x8000'0000'0000'0000);
|
||||
EXPECT_EQ(TIME(-9223372037, 145'224'193).to_nanoseconds(), -0x7fff'ffff'ffff'ffff);
|
||||
EXPECT_EQ(TIME(9223372036, 854'775'806).to_nanoseconds(), 0x7fff'ffff'ffff'fffe);
|
||||
EXPECT_EQ(TIME(9223372036, 854'775'807).to_nanoseconds(), 0x7fff'ffff'ffff'ffff);
|
||||
EXPECT_EQ(TIME(9223372036, 854'775'808).to_nanoseconds(), 0x7fff'ffff'ffff'ffff);
|
||||
EXPECT_EQ(DURATION(-9223372037, 145'224'191).to_nanoseconds(), (i64)-0x8000'0000'0000'0000);
|
||||
EXPECT_EQ(DURATION(-9223372037, 145'224'192).to_nanoseconds(), (i64)-0x8000'0000'0000'0000);
|
||||
EXPECT_EQ(DURATION(-9223372037, 145'224'193).to_nanoseconds(), -0x7fff'ffff'ffff'ffff);
|
||||
EXPECT_EQ(DURATION(9223372036, 854'775'806).to_nanoseconds(), 0x7fff'ffff'ffff'fffe);
|
||||
EXPECT_EQ(DURATION(9223372036, 854'775'807).to_nanoseconds(), 0x7fff'ffff'ffff'ffff);
|
||||
EXPECT_EQ(DURATION(9223372036, 854'775'808).to_nanoseconds(), 0x7fff'ffff'ffff'ffff);
|
||||
}
|
||||
|
||||
TEST_CASE(truncation)
|
||||
{
|
||||
// Sanity
|
||||
EXPECT_EQ(TIME(2, 0).to_truncated_seconds(), 2);
|
||||
EXPECT_EQ(TIME(-2, 0).to_truncated_seconds(), -2);
|
||||
EXPECT_EQ(TIME(2, 800'800'800).to_truncated_seconds(), 2);
|
||||
EXPECT_EQ(TIME(2, 800'800'800).to_truncated_milliseconds(), 2'800);
|
||||
EXPECT_EQ(TIME(2, 800'800'800).to_truncated_microseconds(), 2'800'800);
|
||||
EXPECT_EQ(TIME(-2, -800'800'800).to_truncated_seconds(), -2);
|
||||
EXPECT_EQ(TIME(-2, -800'800'800).to_truncated_milliseconds(), -2'800);
|
||||
EXPECT_EQ(TIME(-2, -800'800'800).to_truncated_microseconds(), -2'800'800);
|
||||
EXPECT_EQ(DURATION(2, 0).to_truncated_seconds(), 2);
|
||||
EXPECT_EQ(DURATION(-2, 0).to_truncated_seconds(), -2);
|
||||
EXPECT_EQ(DURATION(2, 800'800'800).to_truncated_seconds(), 2);
|
||||
EXPECT_EQ(DURATION(2, 800'800'800).to_truncated_milliseconds(), 2'800);
|
||||
EXPECT_EQ(DURATION(2, 800'800'800).to_truncated_microseconds(), 2'800'800);
|
||||
EXPECT_EQ(DURATION(-2, -800'800'800).to_truncated_seconds(), -2);
|
||||
EXPECT_EQ(DURATION(-2, -800'800'800).to_truncated_milliseconds(), -2'800);
|
||||
EXPECT_EQ(DURATION(-2, -800'800'800).to_truncated_microseconds(), -2'800'800);
|
||||
|
||||
// Overflow, seconds
|
||||
EXPECT_EQ(Time::min().to_truncated_seconds(), (i64)-0x8000'0000'0000'0000);
|
||||
EXPECT_EQ(Time::max().to_truncated_seconds(), 0x7fff'ffff'ffff'ffff);
|
||||
EXPECT_EQ(Duration::min().to_truncated_seconds(), (i64)-0x8000'0000'0000'0000);
|
||||
EXPECT_EQ(Duration::max().to_truncated_seconds(), 0x7fff'ffff'ffff'ffff);
|
||||
|
||||
// Overflow, milliseconds
|
||||
EXPECT_EQ(TIME(-9223372036854776, 191'000'000).to_truncated_milliseconds(), (i64)-0x8000'0000'0000'0000);
|
||||
EXPECT_EQ(TIME(-9223372036854776, 192'000'000).to_truncated_milliseconds(), (i64)-0x8000'0000'0000'0000);
|
||||
EXPECT_EQ(TIME(-9223372036854776, 192'000'001).to_truncated_milliseconds(), -0x7fff'ffff'ffff'ffff);
|
||||
EXPECT_EQ(TIME(-9223372036854776, 193'000'000).to_truncated_milliseconds(), -0x7fff'ffff'ffff'ffff);
|
||||
EXPECT_EQ(TIME(9223372036854775, 806'000'000).to_truncated_milliseconds(), 0x7fff'ffff'ffff'fffe);
|
||||
EXPECT_EQ(TIME(9223372036854775, 806'999'999).to_truncated_milliseconds(), 0x7fff'ffff'ffff'fffe);
|
||||
EXPECT_EQ(TIME(9223372036854775, 807'000'000).to_truncated_milliseconds(), 0x7fff'ffff'ffff'ffff);
|
||||
EXPECT_EQ(TIME(9223372036854775, 808'000'000).to_truncated_milliseconds(), 0x7fff'ffff'ffff'ffff);
|
||||
EXPECT_EQ(DURATION(-9223372036854776, 191'000'000).to_truncated_milliseconds(), (i64)-0x8000'0000'0000'0000);
|
||||
EXPECT_EQ(DURATION(-9223372036854776, 192'000'000).to_truncated_milliseconds(), (i64)-0x8000'0000'0000'0000);
|
||||
EXPECT_EQ(DURATION(-9223372036854776, 192'000'001).to_truncated_milliseconds(), -0x7fff'ffff'ffff'ffff);
|
||||
EXPECT_EQ(DURATION(-9223372036854776, 193'000'000).to_truncated_milliseconds(), -0x7fff'ffff'ffff'ffff);
|
||||
EXPECT_EQ(DURATION(9223372036854775, 806'000'000).to_truncated_milliseconds(), 0x7fff'ffff'ffff'fffe);
|
||||
EXPECT_EQ(DURATION(9223372036854775, 806'999'999).to_truncated_milliseconds(), 0x7fff'ffff'ffff'fffe);
|
||||
EXPECT_EQ(DURATION(9223372036854775, 807'000'000).to_truncated_milliseconds(), 0x7fff'ffff'ffff'ffff);
|
||||
EXPECT_EQ(DURATION(9223372036854775, 808'000'000).to_truncated_milliseconds(), 0x7fff'ffff'ffff'ffff);
|
||||
|
||||
// Overflow, microseconds
|
||||
EXPECT_EQ(TIME(-9223372036855, 224'191'000).to_truncated_microseconds(), (i64)-0x8000'0000'0000'0000);
|
||||
EXPECT_EQ(TIME(-9223372036855, 224'192'000).to_truncated_microseconds(), (i64)-0x8000'0000'0000'0000);
|
||||
EXPECT_EQ(TIME(-9223372036855, 224'192'001).to_truncated_microseconds(), (i64)-0x7fff'ffff'ffff'ffff);
|
||||
EXPECT_EQ(TIME(-9223372036855, 224'193'000).to_truncated_microseconds(), (i64)-0x7fff'ffff'ffff'ffff);
|
||||
EXPECT_EQ(TIME(9223372036854, 775'806'000).to_truncated_microseconds(), 0x7fff'ffff'ffff'fffe);
|
||||
EXPECT_EQ(TIME(9223372036854, 775'806'999).to_truncated_microseconds(), 0x7fff'ffff'ffff'fffe);
|
||||
EXPECT_EQ(TIME(9223372036854, 775'807'000).to_truncated_microseconds(), 0x7fff'ffff'ffff'ffff);
|
||||
EXPECT_EQ(TIME(9223372036854, 775'808'000).to_truncated_microseconds(), 0x7fff'ffff'ffff'ffff);
|
||||
EXPECT_EQ(DURATION(-9223372036855, 224'191'000).to_truncated_microseconds(), (i64)-0x8000'0000'0000'0000);
|
||||
EXPECT_EQ(DURATION(-9223372036855, 224'192'000).to_truncated_microseconds(), (i64)-0x8000'0000'0000'0000);
|
||||
EXPECT_EQ(DURATION(-9223372036855, 224'192'001).to_truncated_microseconds(), (i64)-0x7fff'ffff'ffff'ffff);
|
||||
EXPECT_EQ(DURATION(-9223372036855, 224'193'000).to_truncated_microseconds(), (i64)-0x7fff'ffff'ffff'ffff);
|
||||
EXPECT_EQ(DURATION(9223372036854, 775'806'000).to_truncated_microseconds(), 0x7fff'ffff'ffff'fffe);
|
||||
EXPECT_EQ(DURATION(9223372036854, 775'806'999).to_truncated_microseconds(), 0x7fff'ffff'ffff'fffe);
|
||||
EXPECT_EQ(DURATION(9223372036854, 775'807'000).to_truncated_microseconds(), 0x7fff'ffff'ffff'ffff);
|
||||
EXPECT_EQ(DURATION(9223372036854, 775'808'000).to_truncated_microseconds(), 0x7fff'ffff'ffff'ffff);
|
||||
}
|
||||
|
||||
TEST_CASE(is_negative)
|
||||
{
|
||||
auto small = Time::from_nanoseconds(10);
|
||||
auto large = Time::from_nanoseconds(15);
|
||||
auto small = Duration::from_nanoseconds(10);
|
||||
auto large = Duration::from_nanoseconds(15);
|
||||
auto result = small - large;
|
||||
EXPECT_EQ(result.to_nanoseconds(), -5);
|
||||
EXPECT(result.is_negative());
|
||||
@ -479,7 +479,7 @@ TEST_CASE(years_to_days_since_epoch_span)
|
||||
TEST_CASE(user_defined_literals)
|
||||
{
|
||||
using namespace AK::TimeLiterals;
|
||||
static_assert(Time::from_nanoseconds(123) == 123_ns, "Factory is same as UDL");
|
||||
static_assert(Duration::from_nanoseconds(123) == 123_ns, "Factory is same as UDL");
|
||||
|
||||
static_assert(100_ms > 10_ms, "LT UDL");
|
||||
static_assert(1000_ns == 1_us, "EQ UDL");
|
@ -17,7 +17,7 @@ public:
|
||||
|
||||
static Core::ElapsedTimer signal_timer;
|
||||
|
||||
static constexpr auto timer_value = Time::from_seconds(1);
|
||||
static constexpr auto timer_value = Duration::from_seconds(1);
|
||||
|
||||
static void test_signal_handler(int signal)
|
||||
{
|
||||
@ -25,7 +25,7 @@ public:
|
||||
auto expected_duration = SuccessContext::timer_value;
|
||||
|
||||
// Add a small buffer to allow for latency on the system.
|
||||
constexpr auto buffer_duration = Time::from_milliseconds(50);
|
||||
constexpr auto buffer_duration = Duration::from_milliseconds(50);
|
||||
|
||||
dbgln("Signal Times - Actual: {} Expected: {}", actual_duration.to_milliseconds(), expected_duration.to_milliseconds());
|
||||
EXPECT(actual_duration >= expected_duration);
|
||||
@ -47,7 +47,7 @@ TEST_CASE(success_case)
|
||||
auto previous_time = alarm(SuccessContext::timer_value.to_seconds());
|
||||
EXPECT_EQ(previous_time, 0u);
|
||||
|
||||
auto sleep_time = SuccessContext::timer_value + Time::from_seconds(1);
|
||||
auto sleep_time = SuccessContext::timer_value + Duration::from_seconds(1);
|
||||
sleep(sleep_time.to_seconds());
|
||||
|
||||
EXPECT(SuccessContext::alarm_fired);
|
||||
@ -57,7 +57,7 @@ TEST_CASE(success_case)
|
||||
// See: https://github.com/SerenityOS/serenity/issues/9071
|
||||
TEST_CASE(regression_inifinite_loop)
|
||||
{
|
||||
constexpr auto hour_long_timer_value = Time::from_seconds(60 * 60);
|
||||
constexpr auto hour_long_timer_value = Duration::from_seconds(60 * 60);
|
||||
|
||||
// Create an alarm timer significantly far into the future.
|
||||
auto previous_time = alarm(hour_long_timer_value.to_seconds());
|
||||
|
@ -72,7 +72,7 @@ TEST_CASE(time_zone_name)
|
||||
TestData { "ar"sv, Locale::CalendarPatternStyle::ShortGeneric, "Africa/Accra"sv, "غرينتش"sv },
|
||||
};
|
||||
|
||||
constexpr auto jan_1_2022 = AK::Time::from_seconds(1640995200); // Saturday, January 1, 2022 12:00:00 AM
|
||||
constexpr auto jan_1_2022 = AK::Duration::from_seconds(1640995200); // Saturday, January 1, 2022 12:00:00 AM
|
||||
|
||||
for (auto const& test : test_data) {
|
||||
auto time_zone = MUST(Locale::format_time_zone(test.locale, test.time_zone, test.style, jan_1_2022));
|
||||
@ -122,7 +122,7 @@ TEST_CASE(time_zone_name_dst)
|
||||
TestData { "ar"sv, Locale::CalendarPatternStyle::Short, "Africa/Accra"sv, "غرينتش"sv },
|
||||
};
|
||||
|
||||
constexpr auto sep_19_2022 = AK::Time::from_seconds(1663553728); // Monday, September 19, 2022 2:15:28 AM
|
||||
constexpr auto sep_19_2022 = AK::Duration::from_seconds(1663553728); // Monday, September 19, 2022 2:15:28 AM
|
||||
|
||||
for (auto const& test : test_data) {
|
||||
auto time_zone = MUST(Locale::format_time_zone(test.locale, test.time_zone, test.style, sep_19_2022));
|
||||
@ -132,13 +132,13 @@ TEST_CASE(time_zone_name_dst)
|
||||
|
||||
TEST_CASE(format_time_zone_offset)
|
||||
{
|
||||
constexpr auto jan_1_1833 = AK::Time::from_seconds(-4323283200); // Tuesday, January 1, 1833 12:00:00 AM
|
||||
constexpr auto jan_1_2022 = AK::Time::from_seconds(1640995200); // Saturday, January 1, 2022 12:00:00 AM
|
||||
constexpr auto jan_1_1833 = AK::Duration::from_seconds(-4323283200); // Tuesday, January 1, 1833 12:00:00 AM
|
||||
constexpr auto jan_1_2022 = AK::Duration::from_seconds(1640995200); // Saturday, January 1, 2022 12:00:00 AM
|
||||
|
||||
struct TestData {
|
||||
StringView locale;
|
||||
Locale::CalendarPatternStyle style;
|
||||
AK::Time time;
|
||||
AK::Duration time;
|
||||
StringView time_zone;
|
||||
StringView expected_result;
|
||||
};
|
||||
|
@ -14,7 +14,7 @@ using enum TimeZone::InDST;
|
||||
|
||||
static void test_offset(StringView time_zone, i64 time, i64 expected_offset, TimeZone::InDST expected_in_dst)
|
||||
{
|
||||
auto actual_offset = TimeZone::get_time_zone_offset(time_zone, AK::Time::from_seconds(time));
|
||||
auto actual_offset = TimeZone::get_time_zone_offset(time_zone, AK::Duration::from_seconds(time));
|
||||
VERIFY(actual_offset.has_value());
|
||||
EXPECT_EQ(actual_offset->seconds, expected_offset);
|
||||
EXPECT_EQ(actual_offset->in_dst, expected_in_dst);
|
||||
@ -183,7 +183,7 @@ TEST_CASE(get_time_zone_offset_with_dst)
|
||||
TEST_CASE(get_named_time_zone_offsets)
|
||||
{
|
||||
auto test_named_offsets = [](auto time_zone, i64 time, i64 expected_standard_offset, i64 expected_daylight_offset, auto expected_standard_name, auto expected_daylight_name) {
|
||||
auto actual_offsets = TimeZone::get_named_time_zone_offsets(time_zone, AK::Time::from_seconds(time));
|
||||
auto actual_offsets = TimeZone::get_named_time_zone_offsets(time_zone, AK::Duration::from_seconds(time));
|
||||
VERIFY(actual_offsets.has_value());
|
||||
|
||||
EXPECT_EQ(actual_offsets->at(0).seconds, expected_standard_offset);
|
||||
|
@ -115,7 +115,7 @@ private:
|
||||
float m_rotation_speed = 60.f;
|
||||
bool m_show_frame_rate = false;
|
||||
int m_cycles = 0;
|
||||
Time m_accumulated_time = {};
|
||||
Duration m_accumulated_time = {};
|
||||
RefPtr<GUI::Label> m_stats;
|
||||
GLint m_wrap_s_mode = GL_REPEAT;
|
||||
GLint m_wrap_t_mode = GL_REPEAT;
|
||||
|
@ -286,7 +286,7 @@ void CookieJar::store_cookie(Web::Cookie::ParsedCookie const& parsed_cookie, con
|
||||
|
||||
// 2. Create a new cookie with name cookie-name, value cookie-value. Set the creation-time and the last-access-time to the current date and time.
|
||||
Web::Cookie::Cookie cookie { parsed_cookie.name, parsed_cookie.value, parsed_cookie.same_site_attribute };
|
||||
cookie.creation_time = Time::now_realtime();
|
||||
cookie.creation_time = Duration::now_realtime();
|
||||
cookie.last_access_time = cookie.creation_time;
|
||||
|
||||
if (parsed_cookie.expiry_time_from_max_age_attribute.has_value()) {
|
||||
@ -302,7 +302,7 @@ void CookieJar::store_cookie(Web::Cookie::ParsedCookie const& parsed_cookie, con
|
||||
} else {
|
||||
// Set the cookie's persistent-flag to false. Set the cookie's expiry-time to the latest representable date.
|
||||
cookie.persistent = false;
|
||||
cookie.expiry_time = Time::max();
|
||||
cookie.expiry_time = Duration::max();
|
||||
}
|
||||
|
||||
// 4. If the cookie-attribute-list contains an attribute with an attribute-name of "Domain":
|
||||
@ -421,7 +421,7 @@ Vector<Web::Cookie::Cookie> CookieJar::get_matching_cookies(const URL& url, Depr
|
||||
});
|
||||
|
||||
// 3. Update the last-access-time of each cookie in the cookie-list to the current date and time.
|
||||
auto now = Time::now_realtime();
|
||||
auto now = Duration::now_realtime();
|
||||
|
||||
for (auto& cookie : cookie_list) {
|
||||
cookie.last_access_time = now;
|
||||
@ -462,7 +462,7 @@ static ErrorOr<Web::Cookie::Cookie> parse_cookie(ReadonlySpan<SQL::Value> row)
|
||||
return Error::from_string_view(name);
|
||||
|
||||
auto time = value.to_int<i64>().value();
|
||||
field = Time::from_seconds(time);
|
||||
field = Duration::from_seconds(time);
|
||||
return {};
|
||||
};
|
||||
|
||||
@ -624,7 +624,7 @@ void CookieJar::select_all_cookies_from_database(OnSelectAllCookiesResult on_res
|
||||
|
||||
void CookieJar::purge_expired_cookies()
|
||||
{
|
||||
auto now = Time::now_realtime().to_seconds();
|
||||
auto now = Duration::now_realtime().to_seconds();
|
||||
|
||||
m_storage.visit(
|
||||
[&](PersistedStorage& storage) {
|
||||
|
@ -130,7 +130,7 @@ void StorageWidget::clear_session_storage_entries()
|
||||
void StorageWidget::delete_cookie(Web::Cookie::Cookie cookie)
|
||||
{
|
||||
// Delete cookie by making its expiry time in the past.
|
||||
cookie.expiry_time = Time::from_seconds(0);
|
||||
cookie.expiry_time = Duration::from_seconds(0);
|
||||
if (on_update_cookie)
|
||||
on_update_cookie(move(cookie));
|
||||
}
|
||||
|
@ -133,7 +133,7 @@ void TimeZoneSettingsWidget::set_time_zone_location()
|
||||
m_time_zone_location = compute_time_zone_location();
|
||||
|
||||
auto locale = Locale::default_locale();
|
||||
auto now = AK::Time::now_realtime();
|
||||
auto now = AK::Duration::now_realtime();
|
||||
|
||||
auto name = Locale::format_time_zone(locale, m_time_zone, Locale::CalendarPatternStyle::Long, now).release_value_but_fixme_should_propagate_errors();
|
||||
auto offset = Locale::format_time_zone(locale, m_time_zone, Locale::CalendarPatternStyle::LongOffset, now).release_value_but_fixme_should_propagate_errors();
|
||||
|
@ -229,7 +229,7 @@ bool HexDocumentUndoCommand::merge_with(GUI::Command const& other)
|
||||
m_old[relative_start + i] = typed_other.m_old[i];
|
||||
}
|
||||
|
||||
m_timestamp = Time::now_monotonic();
|
||||
m_timestamp = Duration::now_monotonic();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
#include <LibCore/Forward.h>
|
||||
#include <LibGUI/Command.h>
|
||||
|
||||
constexpr Time COMMAND_COMMIT_TIME = Time::from_milliseconds(400);
|
||||
constexpr Duration COMMAND_COMMIT_TIME = Duration::from_milliseconds(400);
|
||||
|
||||
class HexDocument : public Weakable<HexDocument> {
|
||||
public:
|
||||
@ -103,9 +103,9 @@ public:
|
||||
ErrorOr<void> try_add_changed_bytes(ByteBuffer old_values, ByteBuffer new_values);
|
||||
|
||||
private:
|
||||
bool commit_time_expired() const { return Time::now_monotonic() - m_timestamp >= COMMAND_COMMIT_TIME; }
|
||||
bool commit_time_expired() const { return Duration::now_monotonic() - m_timestamp >= COMMAND_COMMIT_TIME; }
|
||||
|
||||
Time m_timestamp = Time::now_monotonic();
|
||||
Duration m_timestamp = Duration::now_monotonic();
|
||||
WeakPtr<HexDocument> m_document;
|
||||
size_t m_position;
|
||||
ByteBuffer m_old;
|
||||
|
@ -112,7 +112,7 @@ ErrorOr<void> AudioPlayerLoop::send_audio_to_server()
|
||||
|
||||
auto sample_rate = static_cast<double>(m_resampler->target());
|
||||
auto buffer_play_time_ns = 1'000'000'000.0 / (sample_rate / static_cast<double>(Audio::AUDIO_BUFFER_SIZE));
|
||||
auto good_sleep_time = Time::from_nanoseconds(static_cast<unsigned>(buffer_play_time_ns)).to_timespec();
|
||||
auto good_sleep_time = Duration::from_nanoseconds(static_cast<unsigned>(buffer_play_time_ns)).to_timespec();
|
||||
|
||||
size_t start_of_chunk_to_write = 0;
|
||||
while (start_of_chunk_to_write + Audio::AUDIO_BUFFER_SIZE <= m_remaining_samples.size()) {
|
||||
|
@ -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 = Time::now_monotonic();
|
||||
m_last_modified_time = Duration::now_monotonic();
|
||||
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 = Time::now_monotonic();
|
||||
m_last_modified_time = Duration::now_monotonic();
|
||||
window()->set_modified(false);
|
||||
return {};
|
||||
}
|
||||
|
@ -124,7 +124,7 @@ private:
|
||||
|
||||
Optional<DeprecatedString> m_path;
|
||||
Gfx::Palette m_current_palette;
|
||||
Time m_last_modified_time { Time::now_monotonic() };
|
||||
Duration m_last_modified_time { Duration::now_monotonic() };
|
||||
|
||||
RefPtr<AlignmentModel> m_alignment_model;
|
||||
|
||||
|
@ -59,7 +59,7 @@ ErrorOr<void> VideoPlayerWidget::setup_interface()
|
||||
update_seek_slider_max();
|
||||
auto progress = value / static_cast<double>(m_seek_slider->max());
|
||||
auto duration = m_playback_manager->duration().to_milliseconds();
|
||||
Time timestamp = Time::from_milliseconds(static_cast<i64>(round(progress * static_cast<double>(duration))));
|
||||
Duration timestamp = Duration::from_milliseconds(static_cast<i64>(round(progress * static_cast<double>(duration))));
|
||||
auto seek_mode_to_use = m_seek_slider->knob_dragging() ? seek_mode() : Video::PlaybackManager::SeekMode::Accurate;
|
||||
m_playback_manager->seek_to_timestamp(timestamp, seek_mode_to_use);
|
||||
set_current_timestamp(m_playback_manager->current_playback_time());
|
||||
@ -252,7 +252,7 @@ void VideoPlayerWidget::update_seek_slider_max()
|
||||
m_seek_slider->set_enabled(true);
|
||||
}
|
||||
|
||||
void VideoPlayerWidget::set_current_timestamp(Time timestamp)
|
||||
void VideoPlayerWidget::set_current_timestamp(Duration timestamp)
|
||||
{
|
||||
set_time_label(timestamp);
|
||||
if (!m_playback_manager)
|
||||
@ -261,10 +261,10 @@ void VideoPlayerWidget::set_current_timestamp(Time timestamp)
|
||||
m_seek_slider->set_value(static_cast<int>(round(progress * m_seek_slider->max())), GUI::AllowCallback::No);
|
||||
}
|
||||
|
||||
void VideoPlayerWidget::set_time_label(Time timestamp)
|
||||
void VideoPlayerWidget::set_time_label(Duration timestamp)
|
||||
{
|
||||
StringBuilder string_builder;
|
||||
auto append_time = [&](Time time) {
|
||||
auto append_time = [&](Duration time) {
|
||||
auto seconds = (time.to_milliseconds() + 500) / 1000;
|
||||
string_builder.append(human_readable_digital_time(seconds));
|
||||
};
|
||||
|
@ -45,8 +45,8 @@ private:
|
||||
ErrorOr<void> setup_interface();
|
||||
void update_play_pause_icon();
|
||||
void update_seek_slider_max();
|
||||
void set_current_timestamp(Time);
|
||||
void set_time_label(Time);
|
||||
void set_current_timestamp(Duration);
|
||||
void set_time_label(Duration);
|
||||
void on_decoding_error(Video::DecoderError const&);
|
||||
|
||||
void cycle_sizing_modes();
|
||||
|
@ -197,7 +197,7 @@ void ConnectionToServerWrapper::on_crash()
|
||||
show_crash_notification();
|
||||
m_connection.clear();
|
||||
|
||||
static constexpr Time max_crash_frequency = 10_sec;
|
||||
static constexpr Duration max_crash_frequency = 10_sec;
|
||||
if (m_last_crash_timer.is_valid() && m_last_crash_timer.elapsed_time() < max_crash_frequency) {
|
||||
dbgln("LanguageServer crash frequency is too high");
|
||||
m_respawn_allowed = false;
|
||||
|
@ -355,7 +355,7 @@ public:
|
||||
break;
|
||||
m_level = i;
|
||||
}
|
||||
auto const now { Time::now_realtime() };
|
||||
auto const now { Duration::now_realtime() };
|
||||
auto const delay = s_level_map[m_level].m_delay;
|
||||
if (now - m_last_update > delay) {
|
||||
m_last_update = now;
|
||||
@ -372,7 +372,7 @@ public:
|
||||
m_block.random_shape();
|
||||
m_next_block.random_shape();
|
||||
update_shadow_hint_block();
|
||||
m_last_update = Time::now_realtime();
|
||||
m_last_update = Duration::now_realtime();
|
||||
m_state = GameState::Active;
|
||||
}
|
||||
|
||||
@ -384,28 +384,28 @@ private:
|
||||
unsigned m_level {};
|
||||
unsigned m_score {};
|
||||
GameState m_state { GameState::GameOver };
|
||||
Time m_last_update {};
|
||||
Duration m_last_update {};
|
||||
|
||||
struct LevelMap final {
|
||||
unsigned const m_score;
|
||||
Time const m_delay;
|
||||
Duration const m_delay;
|
||||
};
|
||||
|
||||
static constexpr Array<LevelMap, 14> s_level_map = {
|
||||
LevelMap { 0, Time::from_milliseconds(38000 / 60) },
|
||||
LevelMap { 1000, Time::from_milliseconds(34000 / 60) },
|
||||
LevelMap { 2000, Time::from_milliseconds(29000 / 60) },
|
||||
LevelMap { 3000, Time::from_milliseconds(25000 / 60) },
|
||||
LevelMap { 4000, Time::from_milliseconds(22000 / 60) },
|
||||
LevelMap { 5000, Time::from_milliseconds(18000 / 60) },
|
||||
LevelMap { 6000, Time::from_milliseconds(15000 / 60) },
|
||||
LevelMap { 7000, Time::from_milliseconds(11000 / 60) },
|
||||
LevelMap { 8000, Time::from_milliseconds(7000 / 60) },
|
||||
LevelMap { 9000, Time::from_milliseconds(5000 / 60) },
|
||||
LevelMap { 10000, Time::from_milliseconds(4000 / 60) },
|
||||
LevelMap { 20000, Time::from_milliseconds(3000 / 60) },
|
||||
LevelMap { 30000, Time::from_milliseconds(2000 / 60) },
|
||||
LevelMap { 10000000, Time::from_milliseconds(1000 / 60) }
|
||||
LevelMap { 0, Duration::from_milliseconds(38000 / 60) },
|
||||
LevelMap { 1000, Duration::from_milliseconds(34000 / 60) },
|
||||
LevelMap { 2000, Duration::from_milliseconds(29000 / 60) },
|
||||
LevelMap { 3000, Duration::from_milliseconds(25000 / 60) },
|
||||
LevelMap { 4000, Duration::from_milliseconds(22000 / 60) },
|
||||
LevelMap { 5000, Duration::from_milliseconds(18000 / 60) },
|
||||
LevelMap { 6000, Duration::from_milliseconds(15000 / 60) },
|
||||
LevelMap { 7000, Duration::from_milliseconds(11000 / 60) },
|
||||
LevelMap { 8000, Duration::from_milliseconds(7000 / 60) },
|
||||
LevelMap { 9000, Duration::from_milliseconds(5000 / 60) },
|
||||
LevelMap { 10000, Duration::from_milliseconds(4000 / 60) },
|
||||
LevelMap { 20000, Duration::from_milliseconds(3000 / 60) },
|
||||
LevelMap { 30000, Duration::from_milliseconds(2000 / 60) },
|
||||
LevelMap { 10000000, Duration::from_milliseconds(1000 / 60) }
|
||||
};
|
||||
|
||||
[[nodiscard]] RenderRequest set_current_block(Block const& block)
|
||||
|
@ -88,7 +88,7 @@ void ConnectionToServer::update_good_sleep_time()
|
||||
auto sample_rate = static_cast<double>(get_sample_rate());
|
||||
auto buffer_play_time_ns = 1'000'000'000.0 / (sample_rate / static_cast<double>(AUDIO_BUFFER_SIZE));
|
||||
// A factor of 1 should be good for now.
|
||||
m_good_sleep_time = Time::from_nanoseconds(static_cast<unsigned>(buffer_play_time_ns)).to_timespec();
|
||||
m_good_sleep_time = Duration::from_nanoseconds(static_cast<unsigned>(buffer_play_time_ns)).to_timespec();
|
||||
}
|
||||
|
||||
// Non-realtime audio writing loop
|
||||
|
@ -117,7 +117,7 @@ static struct tm* time_to_tm(struct tm* tm, time_t t, StringView time_zone)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (auto offset = TimeZone::get_time_zone_offset(time_zone, AK::Time::from_seconds(t)); offset.has_value()) {
|
||||
if (auto offset = TimeZone::get_time_zone_offset(time_zone, AK::Duration::from_seconds(t)); offset.has_value()) {
|
||||
tm->tm_isdst = offset->in_dst == TimeZone::InDST::Yes;
|
||||
t += offset->seconds;
|
||||
}
|
||||
@ -171,12 +171,12 @@ static time_t tm_to_time(struct tm* tm, StringView time_zone)
|
||||
auto timestamp = ((days_since_epoch * 24 + tm->tm_hour) * 60 + tm->tm_min) * 60 + tm->tm_sec;
|
||||
|
||||
if (tm->tm_isdst < 0) {
|
||||
if (auto offset = TimeZone::get_time_zone_offset(time_zone, AK::Time::from_seconds(timestamp)); offset.has_value())
|
||||
if (auto offset = TimeZone::get_time_zone_offset(time_zone, AK::Duration::from_seconds(timestamp)); offset.has_value())
|
||||
timestamp -= offset->seconds;
|
||||
} else {
|
||||
auto index = tm->tm_isdst == 0 ? 0 : 1;
|
||||
|
||||
if (auto offsets = TimeZone::get_named_time_zone_offsets(time_zone, AK::Time::from_seconds(timestamp)); offsets.has_value())
|
||||
if (auto offsets = TimeZone::get_named_time_zone_offsets(time_zone, AK::Duration::from_seconds(timestamp)); offsets.has_value())
|
||||
timestamp -= offsets->at(index).seconds;
|
||||
}
|
||||
|
||||
@ -407,7 +407,7 @@ void tzset()
|
||||
tzname[1] = const_cast<char*>(__utc);
|
||||
};
|
||||
|
||||
if (auto offsets = TimeZone::get_named_time_zone_offsets(__tzname, AK::Time::now_realtime()); offsets.has_value()) {
|
||||
if (auto offsets = TimeZone::get_named_time_zone_offsets(__tzname, AK::Duration::now_realtime()); offsets.has_value()) {
|
||||
if (!offsets->at(0).name.copy_characters_to_buffer(__tzname_standard, TZNAME_MAX))
|
||||
return set_default_values();
|
||||
if (!offsets->at(1).name.copy_characters_to_buffer(__tzname_daylight, TZNAME_MAX))
|
||||
|
@ -20,7 +20,7 @@ ElapsedTimer ElapsedTimer::start_new()
|
||||
void ElapsedTimer::start()
|
||||
{
|
||||
m_valid = true;
|
||||
m_origin_time = m_precise ? Time::now_monotonic() : Time::now_monotonic_coarse();
|
||||
m_origin_time = m_precise ? Duration::now_monotonic() : Duration::now_monotonic_coarse();
|
||||
}
|
||||
|
||||
void ElapsedTimer::reset()
|
||||
@ -34,10 +34,10 @@ i64 ElapsedTimer::elapsed_milliseconds() const
|
||||
return elapsed_time().to_milliseconds();
|
||||
}
|
||||
|
||||
Time ElapsedTimer::elapsed_time() const
|
||||
Duration ElapsedTimer::elapsed_time() const
|
||||
{
|
||||
VERIFY(is_valid());
|
||||
auto now = m_precise ? Time::now_monotonic() : Time::now_monotonic_coarse();
|
||||
auto now = m_precise ? Duration::now_monotonic() : Duration::now_monotonic_coarse();
|
||||
return now - m_origin_time;
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,7 @@ public:
|
||||
void reset();
|
||||
|
||||
i64 elapsed_milliseconds() const;
|
||||
Time elapsed_time() const;
|
||||
Duration elapsed_time() const;
|
||||
|
||||
// FIXME: Move callers to elapsed_milliseconds(), remove this.
|
||||
i64 elapsed() const // milliseconds
|
||||
@ -32,10 +32,10 @@ public:
|
||||
return elapsed_milliseconds();
|
||||
}
|
||||
|
||||
Time const& origin_time() const { return m_origin_time; }
|
||||
Duration const& origin_time() const { return m_origin_time; }
|
||||
|
||||
private:
|
||||
Time m_origin_time {};
|
||||
Duration m_origin_time {};
|
||||
bool m_precise { false };
|
||||
bool m_valid { false };
|
||||
};
|
||||
|
@ -29,14 +29,14 @@ thread_local ThreadData* s_thread_data;
|
||||
|
||||
struct EventLoopTimer {
|
||||
int timer_id { 0 };
|
||||
Time interval;
|
||||
Time fire_time;
|
||||
Duration interval;
|
||||
Duration fire_time;
|
||||
bool should_reload { false };
|
||||
TimerShouldFireWhenNotVisible fire_when_not_visible { TimerShouldFireWhenNotVisible::No };
|
||||
WeakPtr<Object> owner;
|
||||
|
||||
void reload(Time const& now) { fire_time = now + interval; }
|
||||
bool has_expired(Time const& now) const { return now > fire_time; }
|
||||
void reload(Duration const& now) { fire_time = now + interval; }
|
||||
bool has_expired(Duration const& now) const { return now > fire_time; }
|
||||
};
|
||||
|
||||
struct ThreadData {
|
||||
@ -171,16 +171,16 @@ 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.
|
||||
Time now;
|
||||
Duration now;
|
||||
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 = Time::now_monotonic_coarse();
|
||||
now = Duration::now_monotonic_coarse();
|
||||
auto computed_timeout = next_timer_expiration.value() - now;
|
||||
if (computed_timeout.is_negative())
|
||||
computed_timeout = Time::zero();
|
||||
computed_timeout = Duration::zero();
|
||||
timeout = computed_timeout.to_timeval();
|
||||
} else {
|
||||
should_wait_forever = true;
|
||||
@ -231,7 +231,7 @@ try_select_again:
|
||||
}
|
||||
|
||||
if (!thread_data.timers.is_empty()) {
|
||||
now = Time::now_monotonic_coarse();
|
||||
now = Duration::now_monotonic_coarse();
|
||||
}
|
||||
|
||||
// Handle expired timers.
|
||||
@ -349,10 +349,10 @@ void EventLoopImplementationUnix::notify_forked_and_in_child()
|
||||
thread_data.pid = getpid();
|
||||
}
|
||||
|
||||
Optional<Time> EventLoopManagerUnix::get_next_timer_expiration()
|
||||
Optional<Duration> EventLoopManagerUnix::get_next_timer_expiration()
|
||||
{
|
||||
auto now = Time::now_monotonic_coarse();
|
||||
Optional<Time> soonest {};
|
||||
auto now = Duration::now_monotonic_coarse();
|
||||
Optional<Duration> soonest {};
|
||||
for (auto& it : ThreadData::the().timers) {
|
||||
auto& fire_time = it.value->fire_time;
|
||||
auto owner = it.value->owner.strong_ref();
|
||||
@ -489,8 +489,8 @@ int EventLoopManagerUnix::register_timer(Object& object, int milliseconds, bool
|
||||
auto& thread_data = ThreadData::the();
|
||||
auto timer = make<EventLoopTimer>();
|
||||
timer->owner = object;
|
||||
timer->interval = Time::from_milliseconds(milliseconds);
|
||||
timer->reload(Time::now_monotonic_coarse());
|
||||
timer->interval = Duration::from_milliseconds(milliseconds);
|
||||
timer->reload(Duration::now_monotonic_coarse());
|
||||
timer->should_reload = should_reload;
|
||||
timer->fire_when_not_visible = fire_when_not_visible;
|
||||
int timer_id = thread_data.id_allocator.allocate();
|
||||
|
@ -28,7 +28,7 @@ public:
|
||||
virtual void unregister_signal(int handler_id) override;
|
||||
|
||||
void wait_for_events(EventLoopImplementation::PumpMode);
|
||||
static Optional<Time> get_next_timer_expiration();
|
||||
static Optional<Duration> get_next_timer_expiration();
|
||||
|
||||
private:
|
||||
void dispatch_signal(int signal_number);
|
||||
|
@ -18,10 +18,13 @@
|
||||
static_assert(false, "This file must only be used for macOS");
|
||||
#endif
|
||||
|
||||
#define FixedPoint FixedPointMacOS // AK::FixedPoint conflicts with FixedPoint from MacTypes.h.
|
||||
// Several AK types conflict with MacOS types.
|
||||
#define FixedPoint FixedPointMacOS
|
||||
#define Duration DurationMacOS
|
||||
#include <CoreServices/CoreServices.h>
|
||||
#include <dispatch/dispatch.h>
|
||||
#undef FixedPoint
|
||||
#undef Duration
|
||||
|
||||
namespace Core {
|
||||
|
||||
|
@ -177,7 +177,7 @@ ErrorOr<void> PosixSocketHelper::set_close_on_exec(bool enabled)
|
||||
return {};
|
||||
}
|
||||
|
||||
ErrorOr<void> PosixSocketHelper::set_receive_timeout(Time timeout)
|
||||
ErrorOr<void> PosixSocketHelper::set_receive_timeout(Duration timeout)
|
||||
{
|
||||
auto timeout_spec = timeout.to_timespec();
|
||||
return System::setsockopt(m_fd, SOL_SOCKET, SO_RCVTIMEO, &timeout_spec, sizeof(timeout_spec));
|
||||
@ -231,13 +231,13 @@ ErrorOr<size_t> PosixSocketHelper::pending_bytes() const
|
||||
return static_cast<size_t>(value);
|
||||
}
|
||||
|
||||
ErrorOr<NonnullOwnPtr<UDPSocket>> UDPSocket::connect(DeprecatedString const& host, u16 port, Optional<Time> timeout)
|
||||
ErrorOr<NonnullOwnPtr<UDPSocket>> UDPSocket::connect(DeprecatedString const& host, u16 port, Optional<Duration> timeout)
|
||||
{
|
||||
auto ip_address = TRY(resolve_host(host, SocketType::Datagram));
|
||||
return connect(SocketAddress { ip_address, port }, timeout);
|
||||
}
|
||||
|
||||
ErrorOr<NonnullOwnPtr<UDPSocket>> UDPSocket::connect(SocketAddress const& address, Optional<Time> timeout)
|
||||
ErrorOr<NonnullOwnPtr<UDPSocket>> UDPSocket::connect(SocketAddress const& address, Optional<Duration> timeout)
|
||||
{
|
||||
auto socket = TRY(adopt_nonnull_own_or_enomem(new (nothrow) UDPSocket()));
|
||||
|
||||
|
@ -141,7 +141,7 @@ public:
|
||||
|
||||
ErrorOr<void> set_blocking(bool enabled);
|
||||
ErrorOr<void> set_close_on_exec(bool enabled);
|
||||
ErrorOr<void> set_receive_timeout(Time timeout);
|
||||
ErrorOr<void> set_receive_timeout(Duration timeout);
|
||||
|
||||
void setup_notifier();
|
||||
RefPtr<Core::Notifier> notifier() { return m_notifier; }
|
||||
@ -215,8 +215,8 @@ private:
|
||||
|
||||
class UDPSocket final : public Socket {
|
||||
public:
|
||||
static ErrorOr<NonnullOwnPtr<UDPSocket>> connect(DeprecatedString const& host, u16 port, Optional<Time> timeout = {});
|
||||
static ErrorOr<NonnullOwnPtr<UDPSocket>> connect(SocketAddress const& address, Optional<Time> timeout = {});
|
||||
static ErrorOr<NonnullOwnPtr<UDPSocket>> connect(DeprecatedString const& host, u16 port, Optional<Duration> timeout = {});
|
||||
static ErrorOr<NonnullOwnPtr<UDPSocket>> connect(SocketAddress const& address, Optional<Duration> timeout = {});
|
||||
|
||||
UDPSocket(UDPSocket&& other)
|
||||
: Socket(static_cast<Socket&&>(other))
|
||||
|
@ -40,7 +40,7 @@ void Screensaver::mousedown_event(GUI::MouseEvent&)
|
||||
|
||||
void Screensaver::mousemove_event(GUI::MouseEvent& event)
|
||||
{
|
||||
auto now = AK::Time::now_monotonic();
|
||||
auto now = AK::Duration::now_monotonic();
|
||||
if ((now - m_start_time).to_milliseconds() < mouse_tracking_delay_milliseconds)
|
||||
return;
|
||||
|
||||
|
@ -30,7 +30,7 @@ public:
|
||||
|
||||
protected:
|
||||
Screensaver()
|
||||
: m_start_time(AK::Time::now_monotonic())
|
||||
: m_start_time(AK::Duration::now_monotonic())
|
||||
{
|
||||
}
|
||||
|
||||
@ -38,7 +38,7 @@ private:
|
||||
void trigger_exit();
|
||||
|
||||
Optional<Gfx::IntPoint> m_mouse_origin;
|
||||
AK::Time m_start_time;
|
||||
AK::Duration 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<Time> last_unmodified_timestamp)
|
||||
Dialog::ExecResult MessageBox::ask_about_unsaved_changes(Window* parent_window, StringView path, Optional<Duration> last_unmodified_timestamp)
|
||||
{
|
||||
return MUST(try_ask_about_unsaved_changes(parent_window, path, last_unmodified_timestamp));
|
||||
}
|
||||
|
||||
ErrorOr<Dialog::ExecResult> MessageBox::try_ask_about_unsaved_changes(Window* parent_window, StringView path, Optional<Time> last_unmodified_timestamp)
|
||||
ErrorOr<Dialog::ExecResult> MessageBox::try_ask_about_unsaved_changes(Window* parent_window, StringView path, Optional<Duration> 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 = (Time::now_monotonic() - *last_unmodified_timestamp).to_seconds();
|
||||
auto age = (Duration::now_monotonic() - *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<Time> last_unmodified_timestamp = {});
|
||||
static ExecResult ask_about_unsaved_changes(Window* parent_window, StringView path, Optional<Duration> 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<Time> last_unmodified_timestamp = {});
|
||||
static ErrorOr<ExecResult> try_ask_about_unsaved_changes(Window* parent_window, StringView path, Optional<Duration> 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 = Time::now_monotonic();
|
||||
m_timestamp = Duration::now_monotonic();
|
||||
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 = Time::now_monotonic();
|
||||
m_timestamp = Duration::now_monotonic();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,7 @@
|
||||
|
||||
namespace GUI {
|
||||
|
||||
constexpr Time COMMAND_COMMIT_TIME = Time::from_milliseconds(400);
|
||||
constexpr Duration COMMAND_COMMIT_TIME = Duration::from_milliseconds(400);
|
||||
|
||||
struct TextDocumentSpan {
|
||||
TextRange range;
|
||||
@ -228,9 +228,9 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
bool commit_time_expired() const { return Time::now_monotonic() - m_timestamp >= COMMAND_COMMIT_TIME; }
|
||||
bool commit_time_expired() const { return Duration::now_monotonic() - m_timestamp >= COMMAND_COMMIT_TIME; }
|
||||
|
||||
Time m_timestamp = Time::now_monotonic();
|
||||
Duration m_timestamp = Duration::now_monotonic();
|
||||
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 = Time::now_monotonic();
|
||||
m_last_unmodified_timestamp = Duration::now_monotonic();
|
||||
|
||||
if (on_state_change)
|
||||
on_state_change();
|
||||
|
@ -31,7 +31,7 @@ public:
|
||||
void set_current_unmodified();
|
||||
bool is_current_modified() const;
|
||||
|
||||
Optional<Time> last_unmodified_timestamp() const { return m_last_unmodified_timestamp; }
|
||||
Optional<Duration> 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<Time> m_last_unmodified_timestamp;
|
||||
Optional<Duration> m_last_unmodified_timestamp;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -70,10 +70,10 @@ ErrorOr<JsonValue> decode(Decoder& decoder)
|
||||
}
|
||||
|
||||
template<>
|
||||
ErrorOr<Time> decode(Decoder& decoder)
|
||||
ErrorOr<Duration> decode(Decoder& decoder)
|
||||
{
|
||||
auto nanoseconds = TRY(decoder.decode<i64>());
|
||||
return AK::Time::from_nanoseconds(nanoseconds);
|
||||
return AK::Duration::from_nanoseconds(nanoseconds);
|
||||
}
|
||||
|
||||
template<>
|
||||
|
@ -94,7 +94,7 @@ template<>
|
||||
ErrorOr<JsonValue> decode(Decoder&);
|
||||
|
||||
template<>
|
||||
ErrorOr<Time> decode(Decoder&);
|
||||
ErrorOr<Duration> decode(Decoder&);
|
||||
|
||||
template<>
|
||||
ErrorOr<URL> decode(Decoder&);
|
||||
|
@ -85,7 +85,7 @@ ErrorOr<void> encode(Encoder& encoder, JsonValue const& value)
|
||||
}
|
||||
|
||||
template<>
|
||||
ErrorOr<void> encode(Encoder& encoder, Time const& value)
|
||||
ErrorOr<void> encode(Encoder& encoder, Duration const& value)
|
||||
{
|
||||
return encoder.encode(value.to_nanoseconds());
|
||||
}
|
||||
|
@ -123,7 +123,7 @@ template<>
|
||||
ErrorOr<void> encode(Encoder&, JsonValue const&);
|
||||
|
||||
template<>
|
||||
ErrorOr<void> encode(Encoder&, Time const&);
|
||||
ErrorOr<void> encode(Encoder&, Duration const&);
|
||||
|
||||
template<>
|
||||
ErrorOr<void> encode(Encoder&, URL const&);
|
||||
|
@ -38,7 +38,7 @@ public:
|
||||
|
||||
protected:
|
||||
Core::ElapsedTimer m_timer;
|
||||
Time m_time_difference {};
|
||||
Duration m_time_difference {};
|
||||
};
|
||||
|
||||
class PassManager : public Pass {
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user