Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
event_loop.hpp
Go to the documentation of this file.
1#pragma once
2
4#include <functional>
5#include <chrono>
6#include <vector>
7#include <mutex>
8#include <atomic>
9#include <thread>
10#include <condition_variable>
11#include <memory>
12
13namespace pulp::events {
14
15using Clock = std::chrono::steady_clock;
16using TimePoint = Clock::time_point;
17using Duration = Clock::duration;
18using Task = std::function<void()>;
19
20// Non-singleton event loop. Create as many as you need.
21// Each EventLoop owns a thread for dispatching work.
22class EventLoop {
23public:
26
27 EventLoop(const EventLoop&) = delete;
28 EventLoop& operator=(const EventLoop&) = delete;
29
30 // Dispatch a task to be executed on this event loop's thread.
31 // Tasks submitted after stop() are ignored.
32 void dispatch(Task task);
33
34 // Schedule a one-shot task after a delay. Tasks submitted after stop()
35 // are ignored.
36 void dispatch_after(Duration delay, Task task);
37
38 // Check if the calling thread is this event loop's thread
39 bool is_current_thread() const;
40 std::thread::id thread_id() const;
41
42 // Stop the event loop (called automatically by destructor)
43 void stop();
44
45 // Is the loop running?
46 bool running() const;
47
48private:
49 struct State;
50
51 static void run(std::shared_ptr<State> state);
52
53 std::shared_ptr<State> state_;
54 std::thread thread_;
55};
56
57} // namespace pulp::events
bool is_current_thread() const
std::thread::id thread_id() const
void dispatch_after(Duration delay, Task task)
EventLoop & operator=(const EventLoop &)=delete
EventLoop(const EventLoop &)=delete
void dispatch(Task task)
Definition child_process_manager.hpp:18
Clock::duration Duration
Definition event_loop.hpp:17
Clock::time_point TimePoint
Definition event_loop.hpp:16
std::chrono::steady_clock Clock
Definition event_loop.hpp:15
std::function< void()> Task
Definition event_loop.hpp:18
SequencerStateChannel is the audio-safe transport for a plugin's structured NON-parameter state: the ...
Definition audio_device_manager.hpp:48