output/Timer: add noexcept

This commit is contained in:
Max Kellermann 2022-07-08 22:57:27 +02:00
parent 7dd65f3028
commit 4b3dcf831b
2 changed files with 16 additions and 12 deletions

View File

@ -22,24 +22,26 @@
#include <cassert> #include <cassert>
Timer::Timer(const AudioFormat af) Timer::Timer(const AudioFormat af) noexcept
:rate(af.sample_rate * af.GetFrameSize()) :rate(af.sample_rate * af.GetFrameSize())
{ {
} }
void Timer::Start() void
Timer::Start() noexcept
{ {
time = Now(); time = Now();
started = true; started = true;
} }
void Timer::Reset() void
Timer::Reset() noexcept
{ {
started = false; started = false;
} }
void void
Timer::Add(size_t size) Timer::Add(size_t size) noexcept
{ {
assert(started); assert(started);
@ -49,7 +51,7 @@ Timer::Add(size_t size)
} }
std::chrono::steady_clock::duration std::chrono::steady_clock::duration
Timer::GetDelay() const Timer::GetDelay() const noexcept
{ {
assert(started); assert(started);

View File

@ -31,22 +31,24 @@ class Timer {
bool started = false; bool started = false;
const int rate; const int rate;
public: public:
explicit Timer(AudioFormat af); explicit Timer(AudioFormat af) noexcept;
bool IsStarted() const { return started; } bool IsStarted() const noexcept { return started; }
void Start(); void Start() noexcept;
void Reset(); void Reset() noexcept;
void Add(size_t size); void Add(size_t size) noexcept;
/** /**
* Returns the duration to sleep to get back to sync. * Returns the duration to sleep to get back to sync.
*/ */
std::chrono::steady_clock::duration GetDelay() const; [[gnu::pure]]
std::chrono::steady_clock::duration GetDelay() const noexcept;
private: private:
static Time Now() { [[gnu::pure]]
static Time Now() noexcept {
return std::chrono::duration_cast<Time>(std::chrono::steady_clock::now().time_since_epoch()); return std::chrono::duration_cast<Time>(std::chrono::steady_clock::now().time_since_epoch());
} }
}; };