EventManager: fix forced event processing
previous implementation could drop some forced events.
This commit is contained in:
parent
658e008785
commit
9e3c1c74c5
|
@ -5,6 +5,11 @@
|
||||||
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(),
|
||||||
|
@ -35,16 +40,16 @@ void EventManager::handle_next_events()
|
||||||
{
|
{
|
||||||
const int timeout_ms = 100;
|
const int timeout_ms = 100;
|
||||||
poll(m_events.data(), m_events.size(), timeout_ms);
|
poll(m_events.data(), m_events.size(), timeout_ms);
|
||||||
|
std::vector<int> forced = m_forced;
|
||||||
|
m_forced.clear();
|
||||||
for (size_t i = 0; i < m_events.size(); ++i)
|
for (size_t i = 0; i < m_events.size(); ++i)
|
||||||
{
|
{
|
||||||
auto& event = m_events[i];
|
auto& event = m_events[i];
|
||||||
const int fd = event.fd;
|
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[i])(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_handlers_trash.clear();
|
m_handlers_trash.clear();
|
||||||
m_forced.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventManager::force_signal(int fd)
|
void EventManager::force_signal(int fd)
|
||||||
|
|
|
@ -19,6 +19,7 @@ using EventHandler = std::function<void (int fd)>;
|
||||||
class EventManager : public Singleton<EventManager>
|
class EventManager : public Singleton<EventManager>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
EventManager();
|
||||||
// Watch the given file descriptor, when data becomes
|
// Watch the given file descriptor, when data becomes
|
||||||
// ready, handler will be called with fd as parameter.
|
// ready, handler will be called with fd as parameter.
|
||||||
// It is an error to register multiple handlers on the
|
// It is an error to register multiple handlers on the
|
||||||
|
|
Loading…
Reference in New Issue
Block a user