2020-03-16 08:02:55 +00:00
|
|
|
/*
|
2021-10-04 19:59:10 +00:00
|
|
|
* Copyright (c) Atmosphère-NX
|
2020-03-16 08:02:55 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms and conditions of the GNU General Public License,
|
|
|
|
* version 2, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#pragma once
|
2021-10-01 02:21:08 +00:00
|
|
|
#include <stratosphere/os/os_common_types.hpp>
|
2020-03-16 08:02:55 +00:00
|
|
|
|
|
|
|
namespace ams::os {
|
|
|
|
|
|
|
|
class Tick;
|
|
|
|
|
|
|
|
/* Tick API. */
|
|
|
|
Tick GetSystemTick();
|
2020-04-14 00:07:06 +00:00
|
|
|
Tick GetSystemTickOrdered();
|
2020-03-16 08:02:55 +00:00
|
|
|
s64 GetSystemTickFrequency();
|
|
|
|
TimeSpan ConvertToTimeSpan(Tick tick);
|
|
|
|
Tick ConvertToTick(TimeSpan ts);
|
|
|
|
|
|
|
|
class Tick {
|
|
|
|
private:
|
2021-10-10 07:14:06 +00:00
|
|
|
s64 m_tick;
|
2020-03-16 08:02:55 +00:00
|
|
|
public:
|
2021-10-10 07:14:06 +00:00
|
|
|
constexpr explicit Tick(s64 t = 0) : m_tick(t) { /* ... */ }
|
|
|
|
Tick(TimeSpan ts) : m_tick(ConvertToTick(ts).GetInt64Value()) { /* ... */ }
|
2020-03-16 08:02:55 +00:00
|
|
|
public:
|
2021-10-10 07:14:06 +00:00
|
|
|
constexpr s64 GetInt64Value() const { return m_tick; }
|
2020-03-16 08:02:55 +00:00
|
|
|
TimeSpan ToTimeSpan() const { return ConvertToTimeSpan(*this); }
|
|
|
|
|
|
|
|
/* Tick arithmetic. */
|
2021-10-10 07:14:06 +00:00
|
|
|
constexpr Tick &operator+=(Tick rhs) { m_tick += rhs.m_tick; return *this; }
|
|
|
|
constexpr Tick &operator-=(Tick rhs) { m_tick -= rhs.m_tick; return *this; }
|
2020-03-16 08:02:55 +00:00
|
|
|
constexpr Tick operator+(Tick rhs) const { Tick r(*this); return r += rhs; }
|
|
|
|
constexpr Tick operator-(Tick rhs) const { Tick r(*this); return r -= rhs; }
|
|
|
|
|
|
|
|
constexpr bool operator==(const Tick &rhs) const {
|
2021-10-10 07:14:06 +00:00
|
|
|
return m_tick == rhs.m_tick;
|
2020-03-16 08:02:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
constexpr bool operator!=(const Tick &rhs) const {
|
|
|
|
return !(*this == rhs);
|
|
|
|
}
|
|
|
|
|
|
|
|
constexpr bool operator<(const Tick &rhs) const {
|
2021-10-10 07:14:06 +00:00
|
|
|
return m_tick < rhs.m_tick;
|
2020-03-16 08:02:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
constexpr bool operator>=(const Tick &rhs) const {
|
|
|
|
return !(*this < rhs);
|
|
|
|
}
|
|
|
|
|
|
|
|
constexpr bool operator>(const Tick &rhs) const {
|
2021-10-10 07:14:06 +00:00
|
|
|
return m_tick > rhs.m_tick;
|
2020-03-16 08:02:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
constexpr bool operator<=(const Tick &rhs) const {
|
|
|
|
return !(*this > rhs);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|