1#ifndef LIBFILEZILLA_EVENT_LOOP_HEADER
2#define LIBFILEZILLA_EVENT_LOOP_HEADER
73 void stop(
bool join =
false);
80 void resend_current_event() {
87 void FZ_PRIVATE_SYMBOL remove_handler(
event_handler* handler);
90 void FZ_PRIVATE_SYMBOL stop_timer(timer_id
id);
99 bool FZ_PRIVATE_SYMBOL process_timers(
scoped_lock & l);
101 void FZ_PRIVATE_SYMBOL entry();
102 void FZ_PRIVATE_SYMBOL timer_entry();
104 struct FZ_PRIVATE_SYMBOL timer_data final
108 monotonic_clock deadline_;
109 duration interval_{};
112 timer_id FZ_PRIVATE_SYMBOL setup_timer(scoped_lock &lock, timer_data &d, event_handler* handler, monotonic_clock
const& deadline, duration
const& interval);
114 typedef std::vector<timer_data> Timers;
116 typedef std::deque<std::tuple<event_handler*, event_base*, bool>> Events;
117 Events pending_events_;
123 condition timer_cond_;
126 event_handler * active_handler_{};
128 monotonic_clock deadline_;
130 timer_id next_timer_id_{};
132 thread::id thread_id_{};
134 std::unique_ptr<thread> thread_;
135 std::unique_ptr<async_task> task_;
137 thread_pool* pool_{};
138 std::unique_ptr<thread> timer_thread_;
139 std::unique_ptr<async_task> timer_task_;
Template helper to call a function with its arguments extracted from a tuple.
Handle for asynchronous tasks.
Definition thread_pool.hpp:24
The duration class represents a time interval in milliseconds.
Definition time.hpp:291
Common base class for all events.
Definition event.hpp:23
Simple handler for asynchronous event processing.
Definition event_handler.hpp:55
A threaded event loop that supports sending events and timers.
Definition event_loop.hpp:34
~event_loop()
Stops the thread.
void run()
Starts the loop in the caller's thread.
event_loop(thread_pool &pool)
Takes a thread from the pool and starts the loop.
void filter_events(std::function< bool(event_handler *&, event_base &)> const &filter)
Allows filtering of queued events.
void stop(bool join=false)
Stops the loop.
event_loop()
Spawns a thread and starts the loop.
A monotonic clock (aka steady clock) is independent from walltime.
Definition time.hpp:403
A simple scoped lock.
Definition mutex.hpp:98
A dumb thread-pool for asynchronous tasks.
Definition thread_pool.hpp:64
Declares event_base and simple_event<>
Thread synchronization primitives: mutex, scoped_lock and condition.
The namespace used by libfilezilla.
Definition apply.hpp:17
simple_event< process_event_type, process *, process_event_flag > process_event
Definition process.hpp:52
Assorted classes dealing with time.