Skip to content
  • Allison Karlitskaya's avatar
    glocalfile: add private worker monitor APIs · 33762a41
    Allison Karlitskaya authored
    Add a convenient and race-free method of watching local files from the
    GLib worker thread.
    
    Without this, the race-free way to create a monitor that dispatches
    events to the worker thread looked something like this:
    
     - dispatch an idle to the worker thread
     - from the idle, create the monitor and connect signals
     - from the original thread, wait (on a cond?) until the worker thread
       has finished setting up the monitor
     - read the file that you were monitoring
    
    which is just ridiculously complicated...
    
    To use the new API:
    
      monitor = g_local_file_monitor_new_in_worker ("/path/to/some/file",
                                                    G_FILE_MONITOR_NONE,
                                                    &error);
      g_assert_no_error (error);
    
      g_signal_connect (monitor, "changed", G_CALLBACK (callback), NULL);
    
      g_local_file_monitor_start (monitor);
    
    'callback' will run from the GLib worker thread.
    
    This is the reason that the start() call was introduced ...
    33762a41