home/src/event_manager.hh
Maxime Coste d347223e42 EventManager: store event handlers in an unordered_map instead of a vector
If an event handler add or removes an event from the manager, it may then
be moved in the vector, and if after that it access any of it's members
(through this), it results in an invalid memory access.
2012-11-06 13:34:58 +01:00

36 lines
602 B
C++

#ifndef event_manager_hh_INCLUDED
#define event_manager_hh_INCLUDED
#include <poll.h>
#include <unordered_map>
#include "utils.hh"
namespace Kakoune
{
using EventHandler = std::function<void (int fd)>;
class EventManager : public Singleton<EventManager>
{
public:
EventManager();
void watch(int fd, EventHandler handler);
void unwatch(int fd);
void handle_next_events();
void force_signal(int fd);
private:
std::vector<pollfd> m_events;
std::unordered_map<int, EventHandler> m_handlers;
std::vector<int> m_forced;
};
}
#endif // event_manager_hh_INCLUDED