After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 704873 - inotify: don't assume mainloop is running
inotify: don't assume mainloop is running
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: gio
unspecified
Other All
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2013-07-25 14:32 UTC by Allison Karlitskaya (desrt)
Modified: 2013-07-29 00:41 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
inotify: don't assume mainloop is running (4.13 KB, patch)
2013-07-25 14:32 UTC, Allison Karlitskaya (desrt)
reviewed Details | Review

Description Allison Karlitskaya (desrt) 2013-07-25 14:32:17 UTC
See patch.
Comment 1 Allison Karlitskaya (desrt) 2013-07-25 14:32:18 UTC
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.
Comment 2 Matthias Clasen 2013-07-25 23:54:29 UTC
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 ?
Comment 3 Allison Karlitskaya (desrt) 2013-07-29 00:41:50 UTC
Thanks for the push and following cleanup.