[tracker/extraction-improvements: 6/8] tracker-extract: Implement watchdog for stale tasks.
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/extraction-improvements: 6/8] tracker-extract: Implement watchdog for stale tasks.
- Date: Tue, 10 May 2011 16:04:32 +0000 (UTC)
commit 62e771d8be26b48eaa6f732c1898ae6ea58f7314
Author: Carlos Garnacho <carlosg gnome org>
Date: Fri May 6 16:03:04 2011 +0200
tracker-extract: Implement watchdog for stale tasks.
This forces extraction exit if some task takes more than 20 seconds
to be finished.
src/tracker-extract/tracker-controller.c | 50 +++++++++++++++++++++++++-----
1 files changed, 42 insertions(+), 8 deletions(-)
---
diff --git a/src/tracker-extract/tracker-controller.c b/src/tracker-extract/tracker-controller.c
index 2bd235e..f5c5b29 100644
--- a/src/tracker-extract/tracker-controller.c
+++ b/src/tracker-extract/tracker-controller.c
@@ -37,6 +37,8 @@
#warning Controller thread traces enabled
#endif /* THREAD_ENABLE_TRACE */
+#define WATCHDOG_TIMEOUT 20
+
typedef struct TrackerControllerPrivate TrackerControllerPrivate;
typedef struct GetMetadataData GetMetadataData;
@@ -72,6 +74,8 @@ struct GetMetadataData {
gchar *uri;
gchar *mimetype;
gint fd; /* Only for fast queries */
+
+ GSource *watchdog_source;
};
#define TRACKER_EXTRACT_SERVICE "org.freedesktop.Tracker1.Extract"
@@ -225,6 +229,37 @@ tracker_controller_class_init (TrackerControllerClass *klass)
g_type_class_add_private (object_class, sizeof (TrackerControllerPrivate));
}
+static GSource *
+controller_timeout_source_new (guint interval,
+ GSourceFunc func,
+ gpointer user_data)
+{
+ GMainContext *context;
+ GSource *source;
+
+ context = g_main_context_get_thread_default ();
+
+ source = g_timeout_source_new_seconds (interval);
+ g_source_set_callback (source, func, user_data, NULL);
+ g_source_attach (source, context);
+
+ return source;
+}
+
+static gboolean
+watchdog_timeout_cb (gpointer user_data)
+{
+ GetMetadataData *data = user_data;
+ TrackerControllerPrivate *priv = data->controller->priv;
+
+ g_critical ("Extraction task for '%s' went rogue and took more than %d seconds. Forcing exit.",
+ data->uri, WATCHDOG_TIMEOUT);
+
+ g_main_loop_quit (priv->main_loop);
+
+ return FALSE;
+}
+
static GetMetadataData *
metadata_data_new (TrackerController *controller,
const gchar *uri,
@@ -242,6 +277,9 @@ metadata_data_new (TrackerController *controller,
data->invocation = invocation;
data->request = request;
+ data->watchdog_source = controller_timeout_source_new (WATCHDOG_TIMEOUT,
+ watchdog_timeout_cb,
+ data);
return data;
}
@@ -254,6 +292,7 @@ metadata_data_free (GetMetadataData *data)
g_free (data->uri);
g_free (data->mimetype);
g_object_unref (data->cancellable);
+ g_source_destroy (data->watchdog_source);
g_slice_free (GetMetadataData, data);
}
@@ -321,7 +360,6 @@ static void
reset_shutdown_timeout (TrackerController *controller)
{
TrackerControllerPrivate *priv;
- GSource *source;
priv = controller->priv;
@@ -338,13 +376,9 @@ reset_shutdown_timeout (TrackerController *controller)
priv->shutdown_source = NULL;
}
- source = g_timeout_source_new_seconds (priv->shutdown_timeout);
- g_source_set_callback (source,
- reset_shutdown_timeout_cb,
- controller, NULL);
-
- g_source_attach (source, priv->context);
- priv->shutdown_source = source;
+ priv->shutdown_source = controller_timeout_source_new (priv->shutdown_timeout,
+ reset_shutdown_timeout_cb,
+ controller);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]