inotify: process all inotify events in one batch
authorNicolas Dumazet <nicdumz.commits@gmail.com>
Thu, 21 May 2009 19:26:15 +0900
changeset 8609 aeaa0bd9dc24
parent 8608 228db070bfc4
child 8610 8ef1f63e554c
inotify: process all inotify events in one batch When several inotify events happen, we don't have to process each event separately, calling everytime repowatcher.read_events() to fetch events from the underlying watcher: it is sufficient to call once read_events, to fetch all the events from the watcher.
hgext/inotify/server.py
--- a/hgext/inotify/server.py	Thu May 21 19:22:29 2009 +0900
+++ b/hgext/inotify/server.py	Thu May 21 19:26:15 2009 +0900
@@ -500,7 +500,7 @@
                      evt.fullpath)
         sys.exit(0)
 
-    def handle_pollevent(self):
+    def handle_pollevents(self, events):
         if self.ui.debugflag:
             self.ui.note(_('%s readable: %d bytes\n') %
                          (self.event_time(), self.threshold.readable()))
@@ -640,6 +640,10 @@
     def answer_dbug_query(self):
         return ['\0'.join(self.repowatcher.debug())]
 
+    def handle_pollevents(self, events):
+        for e in events:
+            self.handle_pollevent()
+
     def handle_pollevent(self):
         sock, addr = self.sock.accept()
 
@@ -728,8 +732,13 @@
                     continue
                 raise
             if events:
+                by_fd = {}
                 for fd, event in events:
-                    self.table[fd].handle_pollevent()
+                    by_fd.setdefault(fd, []).append(event)
+
+                for fd, events in by_fd.iteritems():
+                    self.table[fd].handle_pollevents(events)
+
             elif timeobj:
                 timeobj.handle_timeout()