[glib/wip/mount-watcher] GFileMonitorSource: return "interesting" value



commit 1511f7a5de14bf6686a47419802f9d5cfa54c13e
Author: Ryan Lortie <desrt desrt ca>
Date:   Thu Jan 15 15:39:43 2015 -0500

    GFileMonitorSource: return "interesting" value
    
    Return an "interesting" boolean from the event handler function on
    GFileMonitorSource.
    
    An event was "interesting" if it will result in a signal actually being
    dispatched to the user.  It is "uninteresting" if it only hit an
    already-dirty rate limiter.
    
    We will use this information to do some backing off in the backends when
    faced with a flood of uninteresting events.

 gio/glocalfilemonitor.c |   33 ++++++++++++++++++++++-----------
 gio/glocalfilemonitor.h |    2 +-
 2 files changed, 23 insertions(+), 12 deletions(-)
---
diff --git a/gio/glocalfilemonitor.c b/gio/glocalfilemonitor.c
index e860167..cd5aa7a 100644
--- a/gio/glocalfilemonitor.c
+++ b/gio/glocalfilemonitor.c
@@ -177,7 +177,7 @@ g_file_monitor_source_add_pending_change (GFileMonitorSource *fms,
   g_hash_table_insert (fms->pending_changes_table, change->child, iter);
 }
 
-static void
+static gboolean
 g_file_monitor_source_set_pending_change_dirty (GFileMonitorSource *fms,
                                                 GSequenceIter      *iter)
 {
@@ -185,12 +185,15 @@ g_file_monitor_source_set_pending_change_dirty (GFileMonitorSource *fms,
 
   change = g_sequence_get (iter);
 
-  if (!change->dirty)
-    {
-      change->dirty = TRUE;
+  /* if it was already dirty then this change is 'uninteresting' */
+  if (change->dirty)
+    return FALSE;
 
-      g_sequence_sort_changed (iter, pending_change_compare_ready_time, fms);
-    }
+  change->dirty = TRUE;
+
+  g_sequence_sort_changed (iter, pending_change_compare_ready_time, fms);
+
+  return TRUE;
 }
 
 static gboolean
@@ -234,12 +237,13 @@ g_file_monitor_source_queue_event (GFileMonitorSource *fms,
   g_queue_push_tail (&fms->event_queue, event);
 }
 
-static void
+static gboolean
 g_file_monitor_source_file_changed (GFileMonitorSource *fms,
                                     const gchar        *child,
                                     gint64              now)
 {
   GSequenceIter *pending;
+  gboolean interesting;
 
   pending = g_file_monitor_source_find_pending_change (fms, child);
 
@@ -250,11 +254,14 @@ g_file_monitor_source_file_changed (GFileMonitorSource *fms,
     {
       g_file_monitor_source_queue_event (fms, G_FILE_MONITOR_EVENT_CHANGED, child, NULL);
       g_file_monitor_source_add_pending_change (fms, child, now);
+      interesting = TRUE;
     }
   else
-    g_file_monitor_source_set_pending_change_dirty (fms, pending);
+    interesting = g_file_monitor_source_set_pending_change_dirty (fms, pending);
 
   g_file_monitor_source_update_ready_time (fms);
+
+  return interesting;
 }
 
 static void
@@ -319,7 +326,7 @@ is_basename (const gchar *name)
   return !strchr (name, '/');
 }
 
-void
+gboolean
 g_file_monitor_source_handle_event (GFileMonitorSource *fms,
                                     GFileMonitorEvent   event_type,
                                     const gchar        *child,
@@ -327,6 +334,8 @@ g_file_monitor_source_handle_event (GFileMonitorSource *fms,
                                     GFile              *other,
                                     gint64              event_time)
 {
+  gboolean interesting = TRUE;
+
   g_assert (is_basename (child));
   g_assert (!rename_to || is_basename (rename_to));
 
@@ -336,7 +345,7 @@ g_file_monitor_source_handle_event (GFileMonitorSource *fms,
   if (!fms->instance)
     {
       g_mutex_unlock (&fms->lock);
-      return;
+      return TRUE;
     }
 
   switch (event_type)
@@ -348,7 +357,7 @@ g_file_monitor_source_handle_event (GFileMonitorSource *fms,
 
     case G_FILE_MONITOR_EVENT_CHANGED:
       g_assert (!other && !rename_to);
-      g_file_monitor_source_file_changed (fms, child, event_time);
+      interesting = g_file_monitor_source_file_changed (fms, child, event_time);
       break;
 
     case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT:
@@ -418,6 +427,8 @@ g_file_monitor_source_handle_event (GFileMonitorSource *fms,
   g_file_monitor_source_update_ready_time (fms);
 
   g_mutex_unlock (&fms->lock);
+
+  return interesting;
 }
 
 static gint64
diff --git a/gio/glocalfilemonitor.h b/gio/glocalfilemonitor.h
index a613867..3412d1a 100644
--- a/gio/glocalfilemonitor.h
+++ b/gio/glocalfilemonitor.h
@@ -85,7 +85,7 @@ g_local_file_monitor_new_in_worker (const gchar           *pathname,
                                     GError               **error);
 
 /* for implementations of GLocalFileMonitor */
-void
+gboolean
 g_file_monitor_source_handle_event (GFileMonitorSource *fms,
                                     GFileMonitorEvent   event_type,
                                     const gchar        *child,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]