From 70cdb7a811e59206b0164bda8f5cdfd33424ca3c Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sat, 27 Oct 2012 15:01:13 +0200 Subject: [PATCH] EventManager: add force_signal method to force event execution --- src/event_manager.cc | 15 ++++++++++++--- src/event_manager.hh | 5 +++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/event_manager.cc b/src/event_manager.cc index 3ac0ce3a..daa363f7 100644 --- a/src/event_manager.cc +++ b/src/event_manager.cc @@ -5,6 +5,8 @@ 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(), @@ -31,15 +33,22 @@ void EventManager::unwatch(int fd) void EventManager::handle_next_events() { - int res = poll(m_events.data(), m_events.size(), -1); - if (res > 0) + const int timeout_ms = 100; + int res = poll(m_events.data(), m_events.size(), timeout_ms); + if (res >= 0) { for (size_t i = 0; i < m_events.size(); ++i) { - if (m_events[i].revents) + if (m_events[i].revents or contains(m_forced, m_events[i].fd)) m_handlers[i](m_events[i].fd); } + m_forced.clear(); } } +void EventManager::force_signal(int fd) +{ + m_forced.push_back(fd); +} + } diff --git a/src/event_manager.hh b/src/event_manager.hh index c1795983..1e8d5a87 100644 --- a/src/event_manager.hh +++ b/src/event_manager.hh @@ -13,14 +13,19 @@ using EventHandler = std::function; class EventManager : public Singleton { public: + EventManager(); + void watch(int fd, EventHandler handler); void unwatch(int fd); void handle_next_events(); + void force_signal(int fd); + private: std::vector m_events; std::vector m_handlers; + std::vector m_forced; }; }