[PATCH] SELECT1: Remove delay in select loop in SNMPProcessPendingEvents().

Dominik Vogt dvogt at ffm.tc.iot.dtag.de
Wed Jul 28 11:11:40 CEST 2010


The delay is not necessary, because the loop is broken as soon as none of the
file descriptors are busy.
---
 src/eventlistholder.cpp |   19 ++-----------------
 1 files changed, 2 insertions(+), 17 deletions(-)

diff --git a/src/eventlistholder.cpp b/src/eventlistholder.cpp
index 120907a..547a84e 100644
--- a/src/eventlistholder.cpp
+++ b/src/eventlistholder.cpp
@@ -91,15 +91,12 @@ int EventListHolder::SNMPProcessPendingEvents()
   int remaining;
   struct pollfd *pollfds = 0;
   int nfound = 0;
-  int timeout;
+  int timeout = 0;
   msec now(0, 0);
   int status;
 
   pevents_mutex.lock();
 
-  timeout = 1;  // chosen a very small timeout
-  // in order to avoid busy looping but keep overall performance
-
   do
   {
     do
@@ -120,11 +117,6 @@ int EventListHolder::SNMPProcessPendingEvents()
       status = m_eventList.HandleEvents(pollfds, fdcount);
       // TM should we do anything with bad status?
     }
-#ifdef WIN32
-    /* On Win32 select immediately returns -1 if all fd_sets are empty */
-    if (maxfds == 0)
-      Sleep(1); /* prevent 100% CPU utilization */
-#endif
   } while (nfound > 0);
 
   // go through the message queue and resend any messages
@@ -202,10 +194,8 @@ int EventListHolder::SNMPProcessPendingEvents()
   pevents_mutex.lock();
 
   do {
-    // do not allow select to block
     fd_timeout.tv_sec = 0;
-    fd_timeout.tv_usec = 10;  // chosen a very small timeout
-    // in order to avoid busy looping but keep overall performance
+    fd_timeout.tv_usec = 0;
 
     // Set up Select
     m_eventList.GetFdSets(maxfds, readfds, writefds, exceptfds);
@@ -219,11 +209,6 @@ int EventListHolder::SNMPProcessPendingEvents()
       status = m_eventList.HandleEvents(maxfds, readfds, writefds, exceptfds);
       // TM should we do anything with bad status?
     }
-#ifdef WIN32
-    /* On Win32 select immediately returns -1 if all fd_sets are empty */
-    if (maxfds == 0)
-      Sleep(1); /* prevent 100% CPU utilization */
-#endif
   } while (nfound > 0);
 
   // go through the message queue and resend any messages
-- 
1.5.5.6


--azLHFNyN32YCQGCU
Content-Type: text/plain; charset="us-ascii"
Content-Disposition: attachment;
	filename="0003-SELECT1-Do-not-block-in-EventListHolder-SNMPProces.patch"



More information about the AGENTPP mailing list