EventManager: add force_signal method to force event execution
This commit is contained in:
parent
24b43f91c8
commit
70cdb7a811
|
@ -5,6 +5,8 @@
|
||||||
namespace Kakoune
|
namespace Kakoune
|
||||||
{
|
{
|
||||||
|
|
||||||
|
EventManager::EventManager() { m_forced.reserve(4); }
|
||||||
|
|
||||||
void EventManager::watch(int fd, EventHandler handler)
|
void EventManager::watch(int fd, EventHandler handler)
|
||||||
{
|
{
|
||||||
auto event = std::find_if(m_events.begin(), m_events.end(),
|
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()
|
void EventManager::handle_next_events()
|
||||||
{
|
{
|
||||||
int res = poll(m_events.data(), m_events.size(), -1);
|
const int timeout_ms = 100;
|
||||||
if (res > 0)
|
int res = poll(m_events.data(), m_events.size(), timeout_ms);
|
||||||
|
if (res >= 0)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < m_events.size(); ++i)
|
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_handlers[i](m_events[i].fd);
|
||||||
}
|
}
|
||||||
|
m_forced.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EventManager::force_signal(int fd)
|
||||||
|
{
|
||||||
|
m_forced.push_back(fd);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,14 +13,19 @@ using EventHandler = std::function<void (int fd)>;
|
||||||
class EventManager : public Singleton<EventManager>
|
class EventManager : public Singleton<EventManager>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
EventManager();
|
||||||
|
|
||||||
void watch(int fd, EventHandler handler);
|
void watch(int fd, EventHandler handler);
|
||||||
void unwatch(int fd);
|
void unwatch(int fd);
|
||||||
|
|
||||||
void handle_next_events();
|
void handle_next_events();
|
||||||
|
|
||||||
|
void force_signal(int fd);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<pollfd> m_events;
|
std::vector<pollfd> m_events;
|
||||||
std::vector<EventHandler> m_handlers;
|
std::vector<EventHandler> m_handlers;
|
||||||
|
std::vector<int> m_forced;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user