From 9e3c1c74c5b66b7ce487340dbbfb2600ab3c61e6 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 3 Dec 2012 18:49:09 +0100 Subject: [PATCH] EventManager: fix forced event processing previous implementation could drop some forced events. --- src/event_manager.cc | 11 ++++++++--- src/event_manager.hh | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/event_manager.cc b/src/event_manager.cc index d5d0fa2f..35c111b6 100644 --- a/src/event_manager.cc +++ b/src/event_manager.cc @@ -5,6 +5,11 @@ namespace Kakoune { +EventManager::EventManager() +{ + m_forced.reserve(4); +} + void EventManager::watch(int fd, EventHandler handler) { auto event = std::find_if(m_events.begin(), m_events.end(), @@ -35,16 +40,16 @@ void EventManager::handle_next_events() { const int timeout_ms = 100; poll(m_events.data(), m_events.size(), timeout_ms); + std::vector forced = m_forced; + m_forced.clear(); for (size_t i = 0; i < m_events.size(); ++i) { auto& event = m_events[i]; const int fd = event.fd; - if (event.revents or contains(m_forced, fd)) + if (event.revents or contains(forced, fd)) (*m_handlers[i])(fd); } - m_handlers_trash.clear(); - m_forced.clear(); } void EventManager::force_signal(int fd) diff --git a/src/event_manager.hh b/src/event_manager.hh index c3b2a92e..fc1e94da 100644 --- a/src/event_manager.hh +++ b/src/event_manager.hh @@ -19,6 +19,7 @@ using EventHandler = std::function; class EventManager : public Singleton { public: + EventManager(); // Watch the given file descriptor, when data becomes // ready, handler will be called with fd as parameter. // It is an error to register multiple handlers on the