HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
src
TTauri
Foundation
timer.hpp
1
// Copyright 2020 Pokitec
2
// All rights reserved.
3
4
5
#pragma once
6
7
#include "hires_utc_clock.hpp"
8
#include <mutex>
9
#include <vector>
10
#include <functional>
11
#include <tuple>
12
#include <thread>
13
14
namespace
tt {
15
19
class
timer
{
20
public
:
21
using
duration
=
hires_utc_clock::duration
;
22
using
time_point
=
hires_utc_clock::time_point
;
23
28
using
callback_type
=
std::function
<void(
time_point
,
bool
)>;
29
30
private
:
31
struct
callback_entry {
32
size_t
id;
33
duration
interval;
34
time_point
next_wakeup;
35
callback_type
callback;
36
37
callback_entry(
size_t
id
,
duration
interval,
time_point
next_wakeup,
callback_type
callback) noexcept :
38
id(
id
), interval(interval), next_wakeup(next_wakeup), callback(
std::move
(callback)) {}
39
};
40
43
std::string
name;
44
45
mutable
std::mutex
mutex;
46
std::thread
thread;
47
std::vector<callback_entry>
callback_list;
48
size_t
callback_count = 0;
49
52
bool
stop_thread;
53
59
[[nodiscard]]
std::pair<std::vector<callback_type>
,
timer::time_point
> find_triggered_callbacks(
60
timer::time_point
current_time
61
)
noexcept
;
62
65
void
loop() noexcept;
66
71
void
start_with_lock_held() noexcept;
72
77
void
stop_with_lock_held() noexcept;
78
79
public:
80
timer
(
std
::
string
name) noexcept;
81
~
timer
();
82
87
void
start
() noexcept;
88
93
void
stop
() noexcept;
94
105
[[nodiscard]]
size_t
add_callback
(
duration
interval,
callback_type
callback) noexcept;
106
109
void
remove_callback
(
size_t
callback_id) noexcept;
110
111
};
112
115
inline
timer
maintenance_timer = {
"MaintenanceThread"
};
116
117
}
std
STL namespace.
tt::timer
The maintence thread.
Definition
timer.hpp:19
tt::timer::stop
void stop() noexcept
Stop the timer thread.
tt::timer::remove_callback
void remove_callback(size_t callback_id) noexcept
Remove the callback function.
tt::timer::start
void start() noexcept
Start the timer thread.
tt::timer::add_callback
size_t add_callback(duration interval, callback_type callback) noexcept
Add a callback function to be executed each interval.
std::string
std::chrono::duration
std::function< void(time_point, bool)>
std::move
T move(T... args)
std::mutex
std::pair
std::thread
std::chrono::time_point
std::vector
Generated on Mon Apr 22 2024 12:53:56 for HikoGUI by
1.10.0