GNOME Bugzilla – Bug 704873
inotify: don't assume mainloop is running
Last modified: 2013-07-29 00:41:50 UTC
See patch.
Created attachment 250124 [details] [review] inotify: don't assume mainloop is running GFileMonitor takes great care to sample the thread-default main context at the time that it is created in order that events can be dispatched to the correct thread when they come in. The inotify GFileMonitor implementation uses a global file descriptor shared between all watches. It has to poll this file descriptor from somewhere so it arbitrarily picks the default main context. The problem with that is that the user might not be running it. Let's use the GLib worker thread for this instead. It's guaranteed to be running if you need it, and this is exactly the sort of problem it was meant to solve.
Review of attachment 250124 [details] [review]: ::: gio/inotify/inotify-kernel.c @@ +153,3 @@ + timeout_source = g_timeout_source_new (TIMEOUT_MILLISECONDS); + g_source_set_callback (timeout_source, ik_source_timeout, source, NULL); + g_source_attach (timeout_source, glib__private__ ()->g_get_worker_context ()); GLIB_PRIVATE_CALL ? @@ +219,3 @@ g_source_add_poll (source, &ik_poll_fd); g_source_set_callback (source, ik_read_callback, NULL, NULL); + g_source_attach (source, glib__private__ ()->g_get_worker_context ()); GLIB_PRIVATE_CALL ? @@ +372,3 @@ + timeout_source = g_timeout_source_new (PROCESS_EVENTS_TIME); + g_source_set_callback (timeout_source, ik_process_eq_callback, NULL, NULL); + g_source_attach (timeout_source, glib__private__ ()->g_get_worker_context ()); GLIB_PRIVATE_CALL ? ::: gio/inotify/inotify-missing.c @@ +77,3 @@ + source = g_timeout_source_new_seconds (SCAN_MISSING_TIME); + g_source_set_callback (source, im_scan_missing, NULL, NULL); + g_source_attach (source, glib__private__ ()->g_get_worker_context ()); GLIB_PRIVATE_CALL ?
Thanks for the push and following cleanup.