HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
time_stamp_utc.hpp
1// Copyright Take Vos 2021.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
7#include "utility/module.hpp"
8#include "concurrency/module.hpp"
9#include "chrono.hpp"
10#include <array>
11#include <atomic>
12#include <thread>
13
14namespace hi::inline v1 {
15class time_stamp_count;
16
23 [[nodiscard]] static utc_nanoseconds now(time_stamp_count &tsc) noexcept;
24
33 [[nodiscard]] static utc_nanoseconds make(time_stamp_count const &tsc) noexcept;
34
37 static bool start_subsystem() noexcept;
38
41 static void stop_subsystem() noexcept;
42
49 static void adjust_for_drift() noexcept;
50
51private:
52 static inline std::jthread subsystem_thread;
53 static inline unfair_mutex mutex;
54 static inline std::array<std::atomic<utc_nanoseconds>, maximum_num_cpus> tsc_epochs = {};
55
56 static void subsystem_proc_frequency_calibration(std::stop_token stop_token) noexcept;
57 static void subsystem_proc(std::stop_token stop_token) noexcept;
58
61 static bool init_subsystem() noexcept;
62
65 static void deinit_subsystem() noexcept;
66
67 [[nodiscard]] static std::size_t find_cpu_id(uint32_t cpu_id) noexcept;
68};
69
70std::string format_engineering(std::chrono::nanoseconds duration);
71
72} // namespace hi::inline v1
STL namespace.
DOXYGEN BUG.
Definition algorithm.hpp:13
Since Window's 10 QueryPerformanceCounter() counts at only 10MHz which is too low to measure performa...
Definition time_stamp_count.hpp:28
Timestamp.
Definition time_stamp_utc.hpp:19
static bool start_subsystem() noexcept
This will start the calibration subsystem.
static utc_nanoseconds make(time_stamp_count const &tsc) noexcept
Make a time point from a time stamp count.
static utc_nanoseconds now(time_stamp_count &tsc) noexcept
Get the current time and TSC value.