MXL : Media eXchange Layer
MXL
Loading...
Searching...
No Matches
ClockHelpers.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2025 Contributors to the Media eXchange Layer project.
2// SPDX-License-Identifier: Apache-2.0
3
4#pragma once
5
6#include <ctime>
7#include "../Timing.hpp"
8
10{
11 constexpr clockid_t clockToId(Clock clock) noexcept
12 {
13 switch (clock)
14 {
16#if defined(CLOCK_MONOTONIC_RAW)
17 return CLOCK_MONOTONIC_RAW;
18#else
19 return CLOCK_MONOTONIC;
20#endif
21
22#if defined(CLOCK_TAI)
23 case Clock::TAI: return CLOCK_TAI;
24#endif
25 case Clock::ProcessCPUTime: return CLOCK_PROCESS_CPUTIME_ID;
26
27 case Clock::ThreadCPUTime: return CLOCK_THREAD_CPUTIME_ID;
28
29 default: return CLOCK_REALTIME;
30 }
31 }
32
33 constexpr Duration getClockOffset(Clock clock) noexcept
34 {
35 [[maybe_unused]]
36 constexpr auto const ZERO_SECONDS = fromSeconds(0.0);
37 [[maybe_unused]]
38 constexpr auto const TAI_LEAP_SECONDS = fromSeconds(37.0);
39
40 switch (clock)
41 {
42#if !defined(CLOCK_TAI)
43 case Clock::TAI: return TAI_LEAP_SECONDS;
44#endif
45 default: return ZERO_SECONDS;
46 }
47 }
48}
constexpr clockid_t clockToId(Clock clock) noexcept
constexpr Duration getClockOffset(Clock clock) noexcept
constexpr Duration fromSeconds(double duration) noexcept
Definition Timing.hpp:370