From ecfaf019fd6f0ce2929610fcb41c501bea90a80b Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Tue, 2 Feb 2016 09:52:23 +0100 Subject: [PATCH] Avoid unnecessary pollfd updates refs #11014 --- lib/base/socketevents.cpp | 19 ++++++++++++------- lib/base/socketevents.hpp | 5 +++++ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/lib/base/socketevents.cpp b/lib/base/socketevents.cpp index fb739011e..5466bdfc4 100644 --- a/lib/base/socketevents.cpp +++ b/lib/base/socketevents.cpp @@ -24,10 +24,6 @@ #include #include -#ifndef _WIN32 -# include -#endif /* _WIN32 */ - using namespace icinga; struct SocketEventDescriptor @@ -55,6 +51,7 @@ static boost::mutex l_SocketIOMutex; static boost::condition_variable l_SocketIOCV; static bool l_SocketIOFDChanged; static std::map l_SocketIOSockets; +static std::map l_SocketIOEventChanges; void SocketEvents::InitializeThread(void) { @@ -88,6 +85,8 @@ void SocketEvents::ThreadProc(void) boost::mutex::scoped_lock lock(l_SocketIOMutex); if (l_SocketIOFDChanged) { + Log(LogWarning, "SocketEvents", "Updated event FDs"); + pfds.resize(l_SocketIOSockets.size()); descriptors.resize(l_SocketIOSockets.size()); @@ -96,9 +95,11 @@ void SocketEvents::ThreadProc(void) typedef std::map::value_type kv_pair; BOOST_FOREACH(const kv_pair& desc, l_SocketIOSockets) { + if (desc.second.EventInterface) + desc.second.EventInterface->m_PFD = &pfds[i]; + pfds[i].fd = desc.first; pfds[i].events = desc.second.Events; - pfds[i].revents = 0; descriptors[i] = desc.second; i++; @@ -186,7 +187,7 @@ void SocketEvents::WakeUpThread(bool wait) * Constructor for the SocketEvents class. */ SocketEvents::SocketEvents(const Socket::Ptr& socket, Object *lifesupportObject) - : m_FD(socket->GetFD()) + : m_FD(socket->GetFD()), m_PFD(NULL) { boost::call_once(l_SocketIOOnceFlag, &SocketEvents::InitializeThread); @@ -257,7 +258,11 @@ void SocketEvents::ChangeEvents(int events) return; it->second.Events = events; - l_SocketIOFDChanged = true; + + if (m_PFD && boost::this_thread::get_id() == l_SocketIOThread.get_id()) + m_PFD->events = events; + else + l_SocketIOFDChanged = true; } WakeUpThread(); diff --git a/lib/base/socketevents.hpp b/lib/base/socketevents.hpp index 9372dffea..01e1feb8b 100644 --- a/lib/base/socketevents.hpp +++ b/lib/base/socketevents.hpp @@ -23,6 +23,10 @@ #include "base/i2-base.hpp" #include "base/socket.hpp" +#ifndef _WIN32 +# include +#endif /* _WIN32 */ + namespace icinga { @@ -50,6 +54,7 @@ protected: private: SOCKET m_FD; bool m_Events; + pollfd *m_PFD; static void InitializeThread(void); static void ThreadProc(void); -- 2.40.0