forked from enlightenment/efl
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:
parent
c1c471de9c
commit
ce15918593
|
@ -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);
|
static void _ecore_file_monitor_inotify_print(char *file, int mask);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static Eina_Hash *monitor_hash;
|
||||||
|
|
||||||
int
|
int
|
||||||
ecore_file_monitor_backend_init(void)
|
ecore_file_monitor_backend_init(void)
|
||||||
{
|
{
|
||||||
|
@ -74,6 +76,7 @@ ecore_file_monitor_backend_init(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
_inotify_fd_pid = getpid();
|
_inotify_fd_pid = getpid();
|
||||||
|
monitor_hash = eina_hash_int32_new(NULL);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,6 +143,8 @@ ecore_file_monitor_backend_del(Ecore_File_Monitor *em)
|
||||||
|
|
||||||
if (_monitors)
|
if (_monitors)
|
||||||
_monitors = ECORE_FILE_MONITOR(eina_inlist_remove(EINA_INLIST_GET(_monitors), EINA_INLIST_GET(em)));
|
_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);
|
fd = ecore_main_fd_handler_fd_get(_fdh);
|
||||||
if (ECORE_FILE_MONITOR_INOTIFY(em)->wd)
|
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 *
|
static Ecore_File_Monitor *
|
||||||
_ecore_file_monitor_inotify_monitor_find(int wd)
|
_ecore_file_monitor_inotify_monitor_find(int wd)
|
||||||
{
|
{
|
||||||
Ecore_File_Monitor *l;
|
return eina_hash_find(monitor_hash, &wd);
|
||||||
|
|
||||||
EINA_INLIST_FOREACH(_monitors, l)
|
|
||||||
{
|
|
||||||
if (ECORE_FILE_MONITOR_INOTIFY(l)->wd == wd)
|
|
||||||
return l;
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -295,6 +293,7 @@ _ecore_file_monitor_inotify_monitor(Ecore_File_Monitor *em, const char *path)
|
||||||
ecore_file_monitor_backend_del(em);
|
ecore_file_monitor_backend_del(em);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
eina_hash_add(monitor_hash, &ECORE_FILE_MONITOR_INOTIFY(em)->wd, em);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue