1#ifndef LIBFILEZILLA_EVENT_LOOP_HEADER
2#define LIBFILEZILLA_EVENT_LOOP_HEADER
79 void stop(
bool join =
false);
96 void FZ_PRIVATE_SYMBOL remove_handler(
event_handler* handler);
99 void FZ_PRIVATE_SYMBOL stop_timer(timer_id
id);
108 bool FZ_PRIVATE_SYMBOL process_timers(
scoped_lock & l);
110 void FZ_PRIVATE_SYMBOL entry();
111 void FZ_PRIVATE_SYMBOL timer_entry();
113 struct FZ_PRIVATE_SYMBOL timer_data final
117 monotonic_clock deadline_;
118 duration interval_{};
121 timer_id FZ_PRIVATE_SYMBOL setup_timer(scoped_lock &lock, timer_data &d, event_handler* handler, monotonic_clock
const& deadline, duration
const& interval);
123 typedef std::vector<timer_data> Timers;
125 typedef std::deque<std::tuple<event_handler*, event_base*, bool>> Events;
126 Events pending_events_;
132 condition timer_cond_;
135 bool active_handler_removed_{};
136 event_handler * active_handler_{};
138 monotonic_clock deadline_;
139 size_t deadline_index_{};
141 timer_id next_timer_id_{};
143 thread::id thread_id_{};
145 std::unique_ptr<thread> thread_;
146 std::unique_ptr<async_task> task_;
148 thread_pool* pool_{};
149 std::unique_ptr<thread> timer_thread_;
150 std::unique_ptr<async_task> timer_task_;
Template helper to call a function with its arguments extracted from a tuple.
The duration class represents a time interval in milliseconds.
Definition time.hpp:298
Common base class for all events.
Definition event.hpp:23
Definition event_handler.hpp:63
A threaded event loop that supports sending events and timers.
Definition event_loop.hpp:35
~event_loop()
Stops the thread.
void run()
Starts the loop in the caller's thread.
void remove_events(event_source const *const source)
Removes all events of event_with_source type with the given source on this loop.
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.
void resend_current_event()
event_loop()
Spawns a thread and starts the loop.
A monotonic clock (aka steady clock) is independent from walltime.
Definition time.hpp:414
A simple scoped lock.
Definition mutex.hpp:117
This is the recommended event class.
Definition event.hpp:68
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
Assorted classes dealing with time.