1 #ifndef LIBFILEZILLA_EVENT_LOOP_HEADER
2 #define LIBFILEZILLA_EVENT_LOOP_HEADER
36 typedef std::deque<std::pair<event_handler*, event_base*>> Events;
67 void filter_events(std::function<
bool (Events::value_type&)>
const& filter);
75 void stop(
bool join =
false);
83 void FZ_PRIVATE_SYMBOL remove_handler(
event_handler* handler);
85 timer_id FZ_PRIVATE_SYMBOL add_timer(
event_handler* handler,
duration const& interval,
bool one_shot);
86 void FZ_PRIVATE_SYMBOL stop_timer(timer_id
id);
91 bool FZ_PRIVATE_SYMBOL process_event(
scoped_lock & l);
96 void FZ_PRIVATE_SYMBOL entry();
98 struct FZ_PRIVATE_SYMBOL timer_data final
102 monotonic_clock deadline_;
103 duration interval_{};
106 typedef std::vector<timer_data> Timers;
108 Events pending_events_;
114 event_handler * active_handler_{};
116 monotonic_clock deadline_;
118 timer_id next_timer_id_{};
120 thread::id thread_id_{};
122 std::unique_ptr<thread> thread_;
123 std::unique_ptr<async_task> 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:286
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.
void filter_events(std::function< bool(Events::value_type &)> const &filter)
Allows filtering of queued events.
event_loop(thread_pool &pool)
Takes a thread from the pool and starts the loop.
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:383
A simple scoped lock.
Definition: mutex.hpp:65
A dumb thread-pool for asynchronous tasks.
Definition: thread_pool.hpp:63
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.