[tracker/clientapi] Added cancellable (squasme)
- From: Philip Van Hoof <pvanhoof src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [tracker/clientapi] Added cancellable (squasme)
- Date: Thu, 14 Jan 2010 11:00:26 +0000 (UTC)
commit 73eb28316e1925b48101838773e0b4800a8560cc
Author: Philip Van Hoof <philip codeminded be>
Date: Thu Jan 14 11:59:05 2010 +0100
Added cancellable (squasme)
src/plugins/evolution/tracker-evolution-plugin.c | 62 +++++++++++++++++-----
1 files changed, 49 insertions(+), 13 deletions(-)
---
diff --git a/src/plugins/evolution/tracker-evolution-plugin.c b/src/plugins/evolution/tracker-evolution-plugin.c
index 4670d45..1f4373c 100644
--- a/src/plugins/evolution/tracker-evolution-plugin.c
+++ b/src/plugins/evolution/tracker-evolution-plugin.c
@@ -34,6 +34,9 @@
#include <time.h>
#include <inttypes.h>
+#include <glib-object.h>
+#include <gio/gio.h>
+
#include <sqlite3.h>
#include <camel/camel-mime-message.h>
@@ -128,6 +131,7 @@ typedef struct {
GMutex *mutex;
GFunc func, freeup;
gboolean dying;
+ GCancellable *cancel;
} ThreadPool;
typedef struct {
@@ -334,9 +338,9 @@ thread_pool_exec (gpointer data, gpointer user_data)
g_mutex_unlock (pool->mutex);
if (!dying)
- pool->func (data, NULL);
+ pool->func (data, pool->cancel);
- pool->freeup (data, NULL);
+ pool->freeup (data, pool->cancel);
}
static void
@@ -344,6 +348,10 @@ exec_update (gpointer data, gpointer user_data)
{
PoolItem *item = data;
GError *error = NULL;
+ GCancellable *cancel = user_data;
+
+ if (g_cancellable_is_cancelled (cancel))
+ return;
if (item->commit) {
tracker_resources_batch_commit (item->client, &error);
@@ -352,9 +360,10 @@ exec_update (gpointer data, gpointer user_data)
}
if (error) {
- /* g_warning ("Error updating data: %s\n", error->message); */
+ g_debug ("Tracker plugin: Error updating data: %s\n", error->message);
g_error_free (error);
}
+
/* Don't hammer DBus too much, else Evolution's UI sometimes becomes slugish
* due to a dbus_watch_handle call on its mainloop */
@@ -385,6 +394,7 @@ thread_pool_new (GFunc func, GFunc freeup, GCompareDataFunc sorter)
wrap->func = func;
wrap->freeup = freeup;
wrap->mutex = g_mutex_new ();
+ wrap->cancel = g_cancellable_new ();
return wrap;
}
@@ -393,13 +403,15 @@ static void
thread_pool_push (ThreadPool *pool, gpointer item, gpointer user_data)
{
pool->items = g_list_prepend (pool->items, item);
- g_thread_pool_push (pool->pool, item, user_data);
+ if (!pool->dying)
+ g_thread_pool_push (pool->pool, item, user_data);
}
static void
thread_pool_destroy (ThreadPool *pool)
{
g_mutex_lock (pool->mutex);
+ g_cancellable_cancel (pool->cancel);
pool->dying = TRUE;
g_mutex_unlock (pool->mutex);
@@ -408,6 +420,7 @@ thread_pool_destroy (ThreadPool *pool)
g_list_foreach (pool->items, pool->freeup, NULL);
g_mutex_unlock (pool->mutex);
+ g_object_unref (pool->cancel);
g_free (pool);
}
@@ -868,10 +881,17 @@ introduce_walk_folders_in_folder (TrackerEvolutionPlugin *self,
CamelFolderInfo *iter,
CamelStore *store, CamelDB *cdb_r,
gchar *account_uri,
- ClientRegistry *info)
+ ClientRegistry *info,
+ GCancellable *cancel)
{
TrackerEvolutionPluginPrivate *priv = TRACKER_EVOLUTION_PLUGIN_GET_PRIVATE (self);
- gchar *em_uri = em_uri_from_camel (account_uri);
+ gchar *em_uri;
+
+ if (g_cancellable_is_cancelled (cancel)) {
+ return;
+ }
+
+ em_uri = em_uri_from_camel (account_uri);
while (iter) {
guint count = 0;
@@ -918,6 +938,10 @@ introduce_walk_folders_in_folder (TrackerEvolutionPlugin *self,
gchar *part, *label, *p;
guint flags;
+ if (g_cancellable_is_cancelled (cancel)) {
+ break;
+ }
+
ret = sqlite3_step (stmt);
if (ret == SQLITE_BUSY) {
@@ -1047,7 +1071,8 @@ introduce_walk_folders_in_folder (TrackerEvolutionPlugin *self,
if (iter->child) {
introduce_walk_folders_in_folder (self, iter->child,
store, cdb_r,
- account_uri, info);
+ account_uri, info,
+ cancel);
}
iter = iter->next;
@@ -1447,7 +1472,8 @@ folder_worker (gpointer data, gpointer user_data)
winfo->store,
winfo->cdb_r,
winfo->intro_info->account_uri,
- winfo->intro_info->info);
+ winfo->intro_info->info,
+ user_data);
return;
}
@@ -1945,11 +1971,6 @@ on_account_changed (EAccountList *list,
static void
disable_plugin (void)
{
- if (manager) {
- g_object_unref (manager);
- manager = NULL;
- }
-
if (sparql_pool) {
thread_pool_destroy (sparql_pool);
sparql_pool = NULL;
@@ -1959,6 +1980,11 @@ disable_plugin (void)
thread_pool_destroy (folder_pool);
folder_pool = NULL;
}
+
+ if (manager) {
+ g_object_unref (manager);
+ manager = NULL;
+ }
}
@@ -2041,6 +2067,16 @@ enable_plugin (void)
g_object_unref (manager);
}
+ if (sparql_pool) {
+ thread_pool_destroy (sparql_pool);
+ sparql_pool = NULL;
+ }
+
+ if (folder_pool) {
+ thread_pool_destroy (folder_pool);
+ folder_pool = NULL;
+ }
+
manager = g_object_new (TRACKER_TYPE_EVOLUTION_PLUGIN,
"name", "Emails", NULL);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]