ecore-file: use hash for finding monitors

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
This commit is contained in:
Mike Blumenkrantz 2015-04-09 19:52:08 -04:00
parent c1c471de9c
commit ce15918593
1 changed files with 7 additions and 8 deletions

View 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;
}