Event-Driven Programming in C++ 1.0
A case study on event-driven programming in C++
Loading...
Searching...
No Matches
event_queue.hpp
Go to the documentation of this file.
1#ifndef EVENT_QUEUE_HPP
2#define EVENT_QUEUE_HPP
3
14#include <queue>
15#include <functional>
16#include <mutex>
17
30namespace event_queue {
31
40public:
46 using Event = std::function<void()>;
47
55 void pushEvent(const Event &event);
56
63 void processEvents();
64
70 bool isEmpty() const;
71
72private:
73 std::queue<Event> events_;
74 mutable std::mutex mutex_;
75};
76
77} // namespace event_queue
78
79#endif // EVENT_QUEUE_HPP
A thread-safe event queue.
Definition event_queue.hpp:39
std::mutex mutex_
Mutex to protect access to the event queue.
Definition event_queue.hpp:74
std::queue< Event > events_
The underlying queue storing events.
Definition event_queue.hpp:73
bool isEmpty() const
Checks whether the event queue is empty.
Definition event_queue.cpp:44
std::function< void()> Event
Type alias for an event.
Definition event_queue.hpp:46
void pushEvent(const Event &event)
Enqueues an event.
Definition event_queue.cpp:18
void processEvents()
Processes all events in the queue.
Definition event_queue.cpp:24
Contains the implementation of a thread-safe event queue.
Definition event_queue.cpp:16