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.
This commit is contained in:
Ryan Lortie 2015-01-15 15:39:43 -05:00
parent 3d2d4b8efe
commit 9adf948a2b
2 changed files with 24 additions and 13 deletions

View File

@ -177,7 +177,7 @@ g_file_monitor_source_add_pending_change (GFileMonitorSource *fms,
g_hash_table_insert (fms->pending_changes_table, change->child, iter); 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, g_file_monitor_source_set_pending_change_dirty (GFileMonitorSource *fms,
GSequenceIter *iter) GSequenceIter *iter)
{ {
@ -185,12 +185,15 @@ g_file_monitor_source_set_pending_change_dirty (GFileMonitorSource *fms,
change = g_sequence_get (iter); change = g_sequence_get (iter);
if (!change->dirty) /* if it was already dirty then this change is 'uninteresting' */
{ if (change->dirty)
return FALSE;
change->dirty = TRUE; change->dirty = TRUE;
g_sequence_sort_changed (iter, pending_change_compare_ready_time, fms); g_sequence_sort_changed (iter, pending_change_compare_ready_time, fms);
}
return TRUE;
} }
static gboolean static gboolean
@ -239,12 +242,13 @@ g_file_monitor_source_queue_event (GFileMonitorSource *fms,
g_queue_push_tail (&fms->event_queue, event); g_queue_push_tail (&fms->event_queue, event);
} }
static void static gboolean
g_file_monitor_source_file_changed (GFileMonitorSource *fms, g_file_monitor_source_file_changed (GFileMonitorSource *fms,
const gchar *child, const gchar *child,
gint64 now) gint64 now)
{ {
GSequenceIter *pending; GSequenceIter *pending;
gboolean interesting;
pending = g_file_monitor_source_find_pending_change (fms, child); pending = g_file_monitor_source_find_pending_change (fms, child);
@ -255,11 +259,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_queue_event (fms, G_FILE_MONITOR_EVENT_CHANGED, child, NULL);
g_file_monitor_source_add_pending_change (fms, child, now); g_file_monitor_source_add_pending_change (fms, child, now);
interesting = TRUE;
} }
else 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); g_file_monitor_source_update_ready_time (fms);
return interesting;
} }
static void static void
@ -324,7 +331,7 @@ is_basename (const gchar *name)
return !strchr (name, '/'); return !strchr (name, '/');
} }
void gboolean
g_file_monitor_source_handle_event (GFileMonitorSource *fms, g_file_monitor_source_handle_event (GFileMonitorSource *fms,
GFileMonitorEvent event_type, GFileMonitorEvent event_type,
const gchar *child, const gchar *child,
@ -332,11 +339,13 @@ g_file_monitor_source_handle_event (GFileMonitorSource *fms,
GFile *other, GFile *other,
gint64 event_time) gint64 event_time)
{ {
gboolean interesting = TRUE;
g_assert (!child || is_basename (child)); g_assert (!child || is_basename (child));
g_assert (!rename_to || is_basename (rename_to)); g_assert (!rename_to || is_basename (rename_to));
if (fms->basename && (!child || !g_str_equal (child, fms->basename))) if (fms->basename && (!child || !g_str_equal (child, fms->basename)))
return; return TRUE;
g_mutex_lock (&fms->lock); g_mutex_lock (&fms->lock);
@ -344,7 +353,7 @@ g_file_monitor_source_handle_event (GFileMonitorSource *fms,
if (!fms->instance) if (!fms->instance)
{ {
g_mutex_unlock (&fms->lock); g_mutex_unlock (&fms->lock);
return; return TRUE;
} }
switch (event_type) switch (event_type)
@ -356,7 +365,7 @@ g_file_monitor_source_handle_event (GFileMonitorSource *fms,
case G_FILE_MONITOR_EVENT_CHANGED: case G_FILE_MONITOR_EVENT_CHANGED:
g_assert (!other && !rename_to); 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; break;
case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT: case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT:
@ -426,6 +435,8 @@ g_file_monitor_source_handle_event (GFileMonitorSource *fms,
g_file_monitor_source_update_ready_time (fms); g_file_monitor_source_update_ready_time (fms);
g_mutex_unlock (&fms->lock); g_mutex_unlock (&fms->lock);
return interesting;
} }
static gint64 static gint64

View File

@ -91,7 +91,7 @@ g_local_file_monitor_new_in_worker (const gchar *pathname,
/* for implementations of GLocalFileMonitor */ /* for implementations of GLocalFileMonitor */
GLIB_AVAILABLE_IN_2_44 GLIB_AVAILABLE_IN_2_44
void gboolean
g_file_monitor_source_handle_event (GFileMonitorSource *fms, g_file_monitor_source_handle_event (GFileMonitorSource *fms,
GFileMonitorEvent event_type, GFileMonitorEvent event_type,
const gchar *child, const gchar *child,