5#if defined(USE_TIMER) && defined(USE_CPP_TASK) && (defined(IS_DESKTOP) || defined(IS_DESKTOP_WITH_TIME_ONLY)|| defined(IS_MIN_DESKTOP))
30class AudioTimerDriverLinux :
public AudioTimerDriverBase {
32 AudioTimerDriverLinux() =
default;
33 ~AudioTimerDriverLinux() {
end(); }
35 bool begin(repeating_timer_callback_t callback_f, uint32_t time,
36 TimeUnit unit = MS)
override {
39 if (callback_f ==
nullptr || time == 0)
return false;
40 callback = callback_f;
41 period_us = toMicroseconds(time, unit);
43 worker = std::thread([
this]() { this->runLoop(); });
50 if (worker.joinable()) worker.join();
57 std::atomic<bool> running{
false};
59 uint64_t period_us = 0;
61 static uint64_t toMicroseconds(uint32_t value, TimeUnit unit) {
66 return static_cast<uint64_t
>(value) * 1000ULL;
68 return static_cast<uint64_t
>(value) * 1000ULL;
73 auto next = std::chrono::steady_clock::now();
74 while (running.load()) {
75 next += std::chrono::microseconds(period_us);
78 callback(callbackParameter());
80 std::this_thread::sleep_until(next);
@ US
Definition AudioTypes.h:44
@ MS
Definition AudioTypes.h:44
constexpr const _Ep * end(initializer_list< _Ep > __il) noexcept
Definition InitializerList.h:63
constexpr const _Ep * begin(initializer_list< _Ep > __il) noexcept
Definition InitializerList.h:55