ecore-file: use hash for finding monitors
authorMike Blumenkrantz <zmike@osg.samsung.com>
Thu, 9 Apr 2015 23:52:08 +0000 (19:52 -0400)
committerMike Blumenkrantz <zmike@osg.samsung.com>
Fri, 10 Apr 2015 00:01:18 +0000 (20:01 -0400)
this should hugely improve the speed of file monitor event processing;
in my test case, 800,000+ monitors were present and the application was
entirely unable to process them

src/lib/ecore_file/ecore_file_monitor_inotify.c

index b2104f3..e6847dd 100644 (file)
@@ -47,6 +47,8 @@ static int                 _ecore_file_monitor_inotify_monitor(Ecore_File_Monito
 static void                _ecore_file_monitor_inotify_print(char *file, int mask);
 #endif
 
+static Eina_Hash *monitor_hash;
+
 int
 ecore_file_monitor_backend_init(void)
 {
@@ -74,6 +76,7 @@ ecore_file_monitor_backend_init(void)
      }
 
    _inotify_fd_pid = getpid();
+   monitor_hash = eina_hash_int32_new(NULL);
    return 1;
 }
 
@@ -140,6 +143,8 @@ ecore_file_monitor_backend_del(Ecore_File_Monitor *em)
 
    if (_monitors)
      _monitors = ECORE_FILE_MONITOR(eina_inlist_remove(EINA_INLIST_GET(_monitors), EINA_INLIST_GET(em)));
+   if (ECORE_FILE_MONITOR_INOTIFY(em)->wd >= 0)
+     eina_hash_del_by_key(monitor_hash, &ECORE_FILE_MONITOR_INOTIFY(em)->wd);
 
    fd = ecore_main_fd_handler_fd_get(_fdh);
    if (ECORE_FILE_MONITOR_INOTIFY(em)->wd)
@@ -181,14 +186,7 @@ _ecore_file_monitor_inotify_handler(void *data EINA_UNUSED, Ecore_Fd_Handler *fd
 static Ecore_File_Monitor *
 _ecore_file_monitor_inotify_monitor_find(int wd)
 {
-   Ecore_File_Monitor *l;
-
-   EINA_INLIST_FOREACH(_monitors, l)
-     {
-        if (ECORE_FILE_MONITOR_INOTIFY(l)->wd == wd)
-          return l;
-     }
-   return NULL;
+   return eina_hash_find(monitor_hash, &wd);
 }
 
 static void
@@ -295,6 +293,7 @@ _ecore_file_monitor_inotify_monitor(Ecore_File_Monitor *em, const char *path)
         ecore_file_monitor_backend_del(em);
         return 0;
      }
+   eina_hash_add(monitor_hash, &ECORE_FILE_MONITOR_INOTIFY(em)->wd, em);
    return 1;
 }