Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
high_resolution_timer.hpp
Go to the documentation of this file.
1#pragma once
2
3// High-resolution periodic timer for sub-millisecond callbacks.
4// Uses platform-specific high-precision timer APIs.
5
6#include <atomic>
7#include <functional>
8#include <memory>
9#include <mutex>
10#include <thread>
11#include <chrono>
12
13namespace pulp::runtime {
14
31
33public:
36
38 void start(std::chrono::microseconds interval, std::function<void()> callback);
39
43 void start(std::chrono::microseconds interval,
44 std::function<void()> callback,
45 TimerMode mode);
46
48 void stop();
49
51 bool is_running() const { return running_.load(std::memory_order_relaxed); }
52
55 TimerMode active_mode() const { return active_mode_; }
56
57 // No copy or move
60
61private:
62 struct TimerState;
63
64 std::atomic<bool> running_{false};
65 std::mutex mutex_;
66 std::thread thread_;
67 std::shared_ptr<TimerState> state_;
69 void* dispatch_source_ = nullptr;
70};
71
72} // namespace pulp::runtime
TimerMode active_mode() const
The backend actually in use for the current run (may differ from the requested mode when the platform...
Definition high_resolution_timer.hpp:55
HighResolutionTimer(const HighResolutionTimer &)=delete
bool is_running() const
Whether the timer is currently running.
Definition high_resolution_timer.hpp:51
void start(std::chrono::microseconds interval, std::function< void()> callback)
Start the timer with the given interval. Callback runs on a dedicated thread.
HighResolutionTimer & operator=(const HighResolutionTimer &)=delete
void start(std::chrono::microseconds interval, std::function< void()> callback, TimerMode mode)
Start the timer in the requested mode.
Definition generated_event_source.hpp:33
TimerMode
Backend selection for the high-resolution timer.
Definition high_resolution_timer.hpp:27
@ OsTimerQueue
Definition high_resolution_timer.hpp:29
@ DedicatedThread
Definition high_resolution_timer.hpp:28