]> granicus.if.org Git - icinga2/commitdiff
Avoid unnecessary pollfd updates
authorGunnar Beutner <gunnar@beutner.name>
Tue, 2 Feb 2016 08:52:23 +0000 (09:52 +0100)
committerGunnar Beutner <gunnar@beutner.name>
Tue, 2 Feb 2016 08:52:23 +0000 (09:52 +0100)
refs #11014

lib/base/socketevents.cpp
lib/base/socketevents.hpp

index fb739011e46dfeba67d531ecf2806091201371e5..5466bdfc48c5c99b36efe054c60e4f1de3ad4f30 100644 (file)
 #include <boost/foreach.hpp>
 #include <map>
 
-#ifndef _WIN32
-#      include <poll.h>
-#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<SOCKET, SocketEventDescriptor> l_SocketIOSockets;
+static std::map<SOCKET, int> 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<SOCKET, SocketEventDescriptor>::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();
index 9372dffeafeeb9b7749a599142b048fda03393be..01e1feb8b7de6ecb506352fd36e1172f2ddfb9a5 100644 (file)
 #include "base/i2-base.hpp"
 #include "base/socket.hpp"
 
+#ifndef _WIN32
+#      include <poll.h>
+#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);