Avoid updating the file descriptor list for poll() unless we really need to

refs #11014
This commit is contained in:
Gunnar Beutner 2016-01-28 07:19:32 +01:00
parent fa7d0448f9
commit 3c76e70fe2
1 changed files with 31 additions and 27 deletions

View File

@ -73,15 +73,16 @@ void SocketEvents::ThreadProc(void)
{ {
Utility::SetThreadName("SocketIO"); Utility::SetThreadName("SocketIO");
for (;;) { pollfd *pfds = NULL;
pollfd *pfds;
int pfdcount; int pfdcount;
typedef std::map<SOCKET, SocketEventDescriptor>::value_type SocketDesc; for (;;) {
{ {
boost::mutex::scoped_lock lock(l_SocketIOMutex); boost::mutex::scoped_lock lock(l_SocketIOMutex);
if (pfds == NULL) {
typedef std::map<SOCKET, SocketEventDescriptor>::value_type SocketDesc;
pfdcount = l_SocketIOSockets.size(); pfdcount = l_SocketIOSockets.size();
pfds = new pollfd[pfdcount]; pfds = new pollfd[pfdcount];
@ -94,6 +95,10 @@ void SocketEvents::ThreadProc(void)
i++; i++;
} }
l_SocketIOFDChanged = false;
l_SocketIOCV.notify_all();
}
} }
#ifdef _WIN32 #ifdef _WIN32
@ -106,9 +111,8 @@ void SocketEvents::ThreadProc(void)
boost::mutex::scoped_lock lock(l_SocketIOMutex); boost::mutex::scoped_lock lock(l_SocketIOMutex);
if (l_SocketIOFDChanged) { if (l_SocketIOFDChanged) {
l_SocketIOFDChanged = false;
l_SocketIOCV.notify_all();
delete [] pfds; delete [] pfds;
pfds = NULL;
continue; continue;
} }
} }
@ -153,8 +157,6 @@ void SocketEvents::ThreadProc(void)
Log(LogCritical, "SocketEvents", "Exception of unknown type thrown in socket I/O handler."); Log(LogCritical, "SocketEvents", "Exception of unknown type thrown in socket I/O handler.");
} }
} }
delete [] pfds;
} }
} }
@ -196,6 +198,7 @@ SocketEvents::~SocketEvents(void)
void SocketEvents::Register(Object *lifesupportObject) void SocketEvents::Register(Object *lifesupportObject)
{ {
{
boost::mutex::scoped_lock lock(l_SocketIOMutex); boost::mutex::scoped_lock lock(l_SocketIOMutex);
VERIFY(m_FD != INVALID_SOCKET); VERIFY(m_FD != INVALID_SOCKET);
@ -210,8 +213,9 @@ void SocketEvents::Register(Object *lifesupportObject)
l_SocketIOSockets[m_FD] = desc; l_SocketIOSockets[m_FD] = desc;
m_Events = true; m_Events = true;
}
/* There's no need to wake up the I/O thread here. */ WakeUpThread(true);
} }
void SocketEvents::Unregister(void) void SocketEvents::Unregister(void)