[gnome-builder/gnome-builder-3-28] ctags: backport IdeTask integration
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/gnome-builder-3-28] ctags: backport IdeTask integration
- Date: Tue, 10 Apr 2018 21:40:23 +0000 (UTC)
commit b57a5d50fa80876b0462068d02ed3a5e87507d83
Author: Christian Hergert <chergert redhat com>
Date: Tue Apr 10 14:35:51 2018 -0700
ctags: backport IdeTask integration
This changes the ctags plugin to use IdeTask which ensures that we're using
the appropriate thread pool for operations as well and helps to guarantee
that any associated UI objects are finalized in the proper thread.
src/plugins/ctags/ide-ctags-builder.c | 25 +++---
src/plugins/ctags/ide-ctags-index.c | 38 ++++-----
src/plugins/ctags/ide-ctags-symbol-node.c | 24 +++---
src/plugins/ctags/ide-ctags-symbol-resolver.c | 114 +++++++++++++-------------
4 files changed, 101 insertions(+), 100 deletions(-)
---
diff --git a/src/plugins/ctags/ide-ctags-builder.c b/src/plugins/ctags/ide-ctags-builder.c
index 7008aa958..148ac0be4 100644
--- a/src/plugins/ctags/ide-ctags-builder.c
+++ b/src/plugins/ctags/ide-ctags-builder.c
@@ -1,6 +1,6 @@
/* ide-ctags-builder.c
*
- * Copyright © 2017 Christian Hergert <chergert redhat com>
+ * Copyright 2017 Christian Hergert <chergert redhat com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -253,7 +253,7 @@ finish_subprocess:
}
static void
-ide_ctags_builder_build_worker (GTask *task,
+ide_ctags_builder_build_worker (IdeTask *task,
gpointer source_object,
gpointer task_data_ptr,
GCancellable *cancellable)
@@ -265,7 +265,7 @@ ide_ctags_builder_build_worker (GTask *task,
IDE_ENTRY;
- g_assert (G_IS_TASK (task));
+ g_assert (IDE_IS_TASK (task));
g_assert (IDE_IS_CTAGS_BUILDER (source_object));
g_assert (G_IS_FILE (task_data->directory));
@@ -281,7 +281,7 @@ ide_ctags_builder_build_worker (GTask *task,
task_data->recursive,
cancellable);
- g_task_return_boolean (task, TRUE);
+ ide_task_return_boolean (task, TRUE);
IDE_EXIT;
}
@@ -295,7 +295,7 @@ ide_ctags_builder_build_async (IdeTagsBuilder *builder,
gpointer user_data)
{
IdeCtagsBuilder *self = (IdeCtagsBuilder *)builder;
- g_autoptr(GTask) task = NULL;
+ g_autoptr(IdeTask) task = NULL;
g_autoptr(GSettings) settings = NULL;
g_autofree gchar *destination_path = NULL;
g_autofree gchar *relative_path = NULL;
@@ -328,11 +328,12 @@ ide_ctags_builder_build_async (IdeTagsBuilder *builder,
destination_path = ide_context_cache_filename (context, "ctags", relative_path, NULL);
task_data->destination = g_file_new_for_path (destination_path);
- task = g_task_new (self, cancellable, callback, user_data);
- g_task_set_source_tag (task, ide_ctags_builder_build_async);
- g_task_set_priority (task, G_PRIORITY_LOW);
- g_task_set_task_data (task, task_data, build_task_data_free);
- ide_thread_pool_push_task (IDE_THREAD_POOL_INDEXER, task, ide_ctags_builder_build_worker);
+ task = ide_task_new (self, cancellable, callback, user_data);
+ ide_task_set_source_tag (task, ide_ctags_builder_build_async);
+ ide_task_set_priority (task, G_PRIORITY_LOW + 200);
+ ide_task_set_task_data (task, task_data, build_task_data_free);
+ ide_task_set_kind (task, IDE_TASK_KIND_INDEXER);
+ ide_task_run_in_thread (task, ide_ctags_builder_build_worker);
IDE_EXIT;
}
@@ -347,9 +348,9 @@ ide_ctags_builder_build_finish (IdeTagsBuilder *builder,
IDE_ENTRY;
g_return_val_if_fail (IDE_IS_CTAGS_BUILDER (builder), FALSE);
- g_return_val_if_fail (G_IS_TASK (result), FALSE);
+ g_return_val_if_fail (IDE_IS_TASK (result), FALSE);
- ret = g_task_propagate_boolean (G_TASK (result), error);
+ ret = ide_task_propagate_boolean (IDE_TASK (result), error);
IDE_RETURN (ret);
}
diff --git a/src/plugins/ctags/ide-ctags-index.c b/src/plugins/ctags/ide-ctags-index.c
index 929a2508d..31ec2a71e 100644
--- a/src/plugins/ctags/ide-ctags-index.c
+++ b/src/plugins/ctags/ide-ctags-index.c
@@ -1,6 +1,6 @@
/* ide-ctags-index.c
*
- * Copyright © 2015 Christian Hergert <christian hergert me>
+ * Copyright 2015 Christian Hergert <christian hergert me>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -185,7 +185,7 @@ ide_ctags_index_parse_line (gchar *line,
}
static void
-ide_ctags_index_build_index (GTask *task,
+ide_ctags_index_build_index (IdeTask *task,
gpointer source_object,
gpointer task_data,
GCancellable *cancellable)
@@ -201,7 +201,7 @@ ide_ctags_index_build_index (GTask *task,
IDE_ENTRY;
- g_assert (G_IS_TASK (task));
+ g_assert (IDE_IS_TASK (task));
g_assert (IDE_IS_CTAGS_INDEX (self));
g_assert (G_IS_FILE (self->file));
@@ -246,7 +246,7 @@ ide_ctags_index_build_index (GTask *task,
DZL_COUNTER_ADD (index_entries, (gint64)index->len);
DZL_COUNTER_ADD (heap_size, (gint64)length);
- g_task_return_boolean (task, TRUE);
+ ide_task_return_boolean (task, TRUE);
IDE_EXIT;
@@ -255,12 +255,12 @@ failure:
g_clear_pointer (&index, g_array_unref);
if (error != NULL)
- g_task_return_error (task, g_steal_pointer (&error));
+ ide_task_return_error (task, g_steal_pointer (&error));
else
- g_task_return_new_error (task,
- G_IO_ERROR,
- G_IO_ERROR_FAILED,
- "Failed to parse ctags file.");
+ ide_task_return_new_error (task,
+ G_IO_ERROR,
+ G_IO_ERROR_FAILED,
+ "Failed to parse ctags file.");
IDE_EXIT;
}
@@ -430,23 +430,23 @@ ide_ctags_index_init_async (GAsyncInitable *initable,
gpointer user_data)
{
IdeCtagsIndex *self = (IdeCtagsIndex *)initable;
- g_autoptr(GTask) task = NULL;
+ g_autoptr(IdeTask) task = NULL;
g_assert (IDE_IS_CTAGS_INDEX (self));
g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
- task = g_task_new (self, cancellable, callback, user_data);
+ task = ide_task_new (self, cancellable, callback, user_data);
+ ide_task_set_priority (task, G_PRIORITY_LOW + 100);
+ ide_task_set_source_tag (task, ide_ctags_index_init_async);
+ ide_task_set_kind (task, IDE_TASK_KIND_INDEXER);
if (self->file == NULL)
- {
- g_task_return_new_error (task,
+ ide_task_return_new_error (task,
G_IO_ERROR,
G_IO_ERROR_FAILED,
"You must set IdeCtagsIndex:file before async initialization");
- return;
- }
-
- ide_thread_pool_push_task (IDE_THREAD_POOL_INDEXER, task, ide_ctags_index_build_index);
+ else
+ ide_task_run_in_thread (task, ide_ctags_index_build_index);
}
static gboolean
@@ -455,9 +455,9 @@ ide_ctags_index_init_finish (GAsyncInitable *initable,
GError **error)
{
g_assert (IDE_IS_CTAGS_INDEX (initable));
- g_assert (G_IS_TASK (result));
+ g_assert (IDE_IS_TASK (result));
- return g_task_propagate_boolean (G_TASK (result), error);
+ return ide_task_propagate_boolean (IDE_TASK (result), error);
}
static void
diff --git a/src/plugins/ctags/ide-ctags-symbol-node.c b/src/plugins/ctags/ide-ctags-symbol-node.c
index 1d2eddfbb..ca0342112 100644
--- a/src/plugins/ctags/ide-ctags-symbol-node.c
+++ b/src/plugins/ctags/ide-ctags-symbol-node.c
@@ -1,6 +1,6 @@
/* ide-ctags-symbol-node.c
*
- * Copyright © 2016 Christian Hergert <chergert redhat com>
+ * Copyright 2016 Christian Hergert <chergert redhat com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -38,20 +38,20 @@ ide_ctags_symbol_node_get_location_cb (GObject *object,
{
IdeCtagsSymbolResolver *resolver = (IdeCtagsSymbolResolver *)object;
g_autoptr(IdeSourceLocation) location = NULL;
- g_autoptr(GTask) task = user_data;
+ g_autoptr(IdeTask) task = user_data;
g_autoptr(GError) error = NULL;
g_assert (IDE_IS_CTAGS_SYMBOL_RESOLVER (resolver));
- g_assert (G_IS_TASK (task));
+ g_assert (IDE_IS_TASK (task));
location = ide_ctags_symbol_resolver_get_location_finish (resolver, result, &error);
if (location == NULL)
- g_task_return_error (task, g_steal_pointer (&error));
+ ide_task_return_error (task, g_steal_pointer (&error));
else
- g_task_return_pointer (task,
- g_steal_pointer (&location),
- (GDestroyNotify)ide_source_location_unref);
+ ide_task_return_pointer (task,
+ g_steal_pointer (&location),
+ (GDestroyNotify)ide_source_location_unref);
}
static void
@@ -61,12 +61,12 @@ ide_ctags_symbol_node_get_location_async (IdeSymbolNode *node,
gpointer user_data)
{
IdeCtagsSymbolNode *self = (IdeCtagsSymbolNode *)node;
- g_autoptr(GTask) task = NULL;
+ g_autoptr(IdeTask) task = NULL;
g_return_if_fail (IDE_IS_CTAGS_SYMBOL_NODE (self));
- task = g_task_new (self, cancellable, callback, user_data);
- g_task_set_source_tag (task, ide_ctags_symbol_node_get_location_async);
+ task = ide_task_new (self, cancellable, callback, user_data);
+ ide_task_set_source_tag (task, ide_ctags_symbol_node_get_location_async);
ide_ctags_symbol_resolver_get_location_async (self->resolver,
self->index,
@@ -82,9 +82,9 @@ ide_ctags_symbol_node_get_location_finish (IdeSymbolNode *node,
GError **error)
{
g_return_val_if_fail (IDE_IS_CTAGS_SYMBOL_NODE (node), NULL);
- g_return_val_if_fail (G_IS_TASK (result), NULL);
+ g_return_val_if_fail (IDE_IS_TASK (result), NULL);
- return g_task_propagate_pointer (G_TASK (result), error);
+ return ide_task_propagate_pointer (IDE_TASK (result), error);
}
static void
diff --git a/src/plugins/ctags/ide-ctags-symbol-resolver.c b/src/plugins/ctags/ide-ctags-symbol-resolver.c
index bfc655466..e46a9fc7b 100644
--- a/src/plugins/ctags/ide-ctags-symbol-resolver.c
+++ b/src/plugins/ctags/ide-ctags-symbol-resolver.c
@@ -1,6 +1,6 @@
/* ide-ctags-symbol-resolver.c
*
- * Copyright © 2015 Christian Hergert <christian hergert me>
+ * Copyright 2015 Christian Hergert <christian hergert me>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -180,7 +180,7 @@ calculate_offset (const gchar *data,
}
static void
-regex_worker (GTask *task,
+regex_worker (IdeTask *task,
gpointer source_object,
gpointer task_data,
GCancellable *cancellable)
@@ -194,7 +194,7 @@ regex_worker (GTask *task,
const gchar *data;
gsize length;
- g_assert (G_IS_TASK (task));
+ g_assert (IDE_IS_TASK (task));
g_assert (lookup != NULL);
if (lookup->buffer_text == NULL)
@@ -203,7 +203,7 @@ regex_worker (GTask *task,
if (lookup->mapped == NULL)
{
- g_task_return_error (task, g_steal_pointer (&error));
+ ide_task_return_error (task, g_steal_pointer (&error));
return;
}
@@ -222,7 +222,7 @@ regex_worker (GTask *task,
if (!(regex = g_regex_new (pattern, G_REGEX_MULTILINE, 0, &error)))
{
- g_task_return_error (task, g_steal_pointer (&error));
+ ide_task_return_error (task, g_steal_pointer (&error));
return;
}
@@ -242,22 +242,22 @@ regex_worker (GTask *task,
calculate_offset (data, length, begin, &line, &line_offset);
symbol = create_symbol (self, lookup->entry, line, line_offset, begin);
- g_task_return_pointer (task,
- g_steal_pointer (&symbol),
- (GDestroyNotify)ide_symbol_unref);
+ ide_task_return_pointer (task,
+ g_steal_pointer (&symbol),
+ (GDestroyNotify)ide_symbol_unref);
return;
}
}
if (error != NULL)
- g_task_return_error (task, g_steal_pointer (&error));
+ ide_task_return_error (task, g_steal_pointer (&error));
else
- g_task_return_new_error (task,
- G_IO_ERROR,
- G_IO_ERROR_NOT_FOUND,
- "Failed to locate symbol \"%s\"",
- lookup->entry->name);
+ ide_task_return_new_error (task,
+ G_IO_ERROR,
+ G_IO_ERROR_NOT_FOUND,
+ "Failed to locate symbol \"%s\"",
+ lookup->entry->name);
}
static gboolean
@@ -281,7 +281,7 @@ ide_ctags_symbol_resolver_lookup_symbol_async (IdeSymbolResolver *resolver,
IdeBufferManager *bufmgr;
IdeCtagsService *service;
g_autofree gchar *keyword = NULL;
- g_autoptr(GTask) task = NULL;
+ g_autoptr(IdeTask) task = NULL;
g_autoptr(GPtrArray) indexes = NULL;
IdeFile *ifile;
const gchar * const *allowed;
@@ -298,7 +298,7 @@ ide_ctags_symbol_resolver_lookup_symbol_async (IdeSymbolResolver *resolver,
g_assert (location != NULL);
g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
- task = g_task_new (self, cancellable, callback, user_data);
+ task = ide_task_new (self, cancellable, callback, user_data);
ifile = ide_source_location_get_file (location);
file = ide_file_get_file (ifile);
@@ -314,10 +314,10 @@ ide_ctags_symbol_resolver_lookup_symbol_async (IdeSymbolResolver *resolver,
if (!buffer)
{
- g_task_return_new_error (task,
- G_IO_ERROR,
- G_IO_ERROR_NOT_FOUND,
- "The document buffer was not available.");
+ ide_task_return_new_error (task,
+ G_IO_ERROR,
+ G_IO_ERROR_NOT_FOUND,
+ "The document buffer was not available.");
return;
}
@@ -378,11 +378,11 @@ ide_ctags_symbol_resolver_lookup_symbol_async (IdeSymbolResolver *resolver,
* the target file and run a GRegex. Best to do that
* on a worker thread.
*/
- g_task_set_task_data (task, lookup, lookup_symbol_free);
+ ide_task_set_task_data (task, lookup, lookup_symbol_free);
if (is_regex (entry->pattern))
{
- g_task_run_in_thread (task, regex_worker);
+ ide_task_run_in_thread (task, regex_worker);
return;
}
else if (is_linenum (entry->pattern))
@@ -396,18 +396,18 @@ ide_ctags_symbol_resolver_lookup_symbol_async (IdeSymbolResolver *resolver,
goto failure;
symbol = create_symbol (self, entry, parsed, 0, 0);
- g_task_return_pointer (task, symbol, (GDestroyNotify)ide_symbol_unref);
+ ide_task_return_pointer (task, symbol, (GDestroyNotify)ide_symbol_unref);
return;
}
}
}
failure:
- g_task_return_new_error (task,
- G_IO_ERROR,
- G_IO_ERROR_NOT_FOUND,
- "Failed to locate symbol \"%s\"",
- keyword);
+ ide_task_return_new_error (task,
+ G_IO_ERROR,
+ G_IO_ERROR_NOT_FOUND,
+ "Failed to locate symbol \"%s\"",
+ keyword);
}
static IdeSymbol *
@@ -415,12 +415,12 @@ ide_ctags_symbol_resolver_lookup_symbol_finish (IdeSymbolResolver *resolver,
GAsyncResult *result,
GError **error)
{
- GTask *task = (GTask *)result;
+ IdeTask *task = (IdeTask *)result;
g_assert (IDE_IS_CTAGS_SYMBOL_RESOLVER (resolver));
- g_assert (G_IS_TASK (task));
+ g_assert (IDE_IS_TASK (task));
- return g_task_propagate_pointer (task, error);
+ return ide_task_propagate_pointer (task, error);
}
typedef struct
@@ -518,7 +518,7 @@ make_parent_key (const IdeCtagsIndexEntry *entry)
}
static void
-ide_ctags_symbol_resolver_get_symbol_tree_worker (GTask *task,
+ide_ctags_symbol_resolver_get_symbol_tree_worker (IdeTask *task,
gpointer source_object,
gpointer task_data,
GCancellable *cancellable)
@@ -532,7 +532,7 @@ ide_ctags_symbol_resolver_get_symbol_tree_worker (GTask *task,
IDE_ENTRY;
g_assert (IDE_IS_CTAGS_SYMBOL_RESOLVER (self));
- g_assert (G_IS_TASK (task));
+ g_assert (IDE_IS_TASK (task));
g_assert (state != NULL);
g_assert (G_IS_FILE (state->file));
g_assert (state->indexes != NULL);
@@ -630,7 +630,7 @@ ide_ctags_symbol_resolver_get_symbol_tree_worker (GTask *task,
}
}
- g_task_return_pointer (task, ide_ctags_symbol_tree_new (g_steal_pointer (&ar)), g_object_unref);
+ ide_task_return_pointer (task, ide_ctags_symbol_tree_new (g_steal_pointer (&ar)), g_object_unref);
IDE_EXIT;
}
@@ -645,7 +645,7 @@ ide_ctags_symbol_resolver_get_symbol_tree_async (IdeSymbolResolver *resolver,
{
IdeCtagsSymbolResolver *self = (IdeCtagsSymbolResolver *)resolver;
TreeResolverState *state;
- g_autoptr(GTask) task = NULL;
+ g_autoptr(IdeTask) task = NULL;
g_autoptr(GPtrArray) indexes = NULL;
IdeCtagsService *service;
IdeContext *context;
@@ -656,8 +656,8 @@ ide_ctags_symbol_resolver_get_symbol_tree_async (IdeSymbolResolver *resolver,
g_assert (G_IS_FILE (file));
g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
- task = g_task_new (self, cancellable, callback, user_data);
- g_task_set_source_tag (task, ide_ctags_symbol_resolver_get_symbol_tree_async);
+ task = ide_task_new (self, cancellable, callback, user_data);
+ ide_task_set_source_tag (task, ide_ctags_symbol_resolver_get_symbol_tree_async);
context = ide_object_get_context (IDE_OBJECT (self));
service = ide_context_get_service_typed (context, IDE_TYPE_CTAGS_SERVICE);
@@ -665,10 +665,10 @@ ide_ctags_symbol_resolver_get_symbol_tree_async (IdeSymbolResolver *resolver,
if (indexes == NULL || indexes->len == 0)
{
- g_task_return_new_error (task,
- G_IO_ERROR,
- G_IO_ERROR_NOT_SUPPORTED,
- "No ctags indexes are loaded");
+ ide_task_return_new_error (task,
+ G_IO_ERROR,
+ G_IO_ERROR_NOT_SUPPORTED,
+ "No ctags indexes are loaded");
IDE_EXIT;
}
@@ -688,8 +688,8 @@ ide_ctags_symbol_resolver_get_symbol_tree_async (IdeSymbolResolver *resolver,
g_ptr_array_add (state->indexes, g_object_ref (index));
}
- g_task_set_task_data (task, state, tree_resolver_state_free);
- g_task_run_in_thread (task, ide_ctags_symbol_resolver_get_symbol_tree_worker);
+ ide_task_set_task_data (task, state, tree_resolver_state_free);
+ ide_task_run_in_thread (task, ide_ctags_symbol_resolver_get_symbol_tree_worker);
IDE_EXIT;
}
@@ -704,9 +704,9 @@ ide_ctags_symbol_resolver_get_symbol_tree_finish (IdeSymbolResolver *resolver,
IDE_ENTRY;
g_assert (IDE_IS_CTAGS_SYMBOL_RESOLVER (resolver));
- g_assert (G_IS_TASK (result));
+ g_assert (IDE_IS_TASK (result));
- ret = g_task_propagate_pointer (G_TASK (result), error);
+ ret = ide_task_propagate_pointer (IDE_TASK (result), error);
IDE_RETURN (ret);
}
@@ -749,7 +749,7 @@ ide_ctags_symbol_resolver_get_location_async (IdeCtagsSymbolResolver *self,
GAsyncReadyCallback callback,
gpointer user_data)
{
- g_autoptr(GTask) task = NULL;
+ g_autoptr(IdeTask) task = NULL;
g_autoptr(GFile) other_file = NULL;
IdeBuffer *other_buffer = NULL;
IdeCtagsIndexEntry *copy;
@@ -766,8 +766,8 @@ ide_ctags_symbol_resolver_get_location_async (IdeCtagsSymbolResolver *self,
context = ide_object_get_context (IDE_OBJECT (self));
bufmgr = ide_context_get_buffer_manager (context);
- task = g_task_new (self, cancellable, callback, user_data);
- g_task_set_source_tag (task, ide_ctags_symbol_resolver_get_location_async);
+ task = ide_task_new (self, cancellable, callback, user_data);
+ ide_task_set_source_tag (task, ide_ctags_symbol_resolver_get_location_async);
if (is_linenum (entry->pattern))
{
@@ -780,7 +780,7 @@ ide_ctags_symbol_resolver_get_location_async (IdeCtagsSymbolResolver *self,
goto not_a_number;
symbol = create_symbol (self, entry, parsed, 0, 0);
- g_task_return_pointer (task, symbol, (GDestroyNotify)ide_symbol_unref);
+ ide_task_return_pointer (task, symbol, (GDestroyNotify)ide_symbol_unref);
IDE_EXIT;
}
@@ -789,10 +789,10 @@ not_a_number:
if (!is_regex (entry->pattern))
{
- g_task_return_new_error (task,
- G_IO_ERROR,
- G_IO_ERROR_NOT_SUPPORTED,
- "Failed to decode jump in ctag entry");
+ ide_task_return_new_error (task,
+ G_IO_ERROR,
+ G_IO_ERROR_NOT_SUPPORTED,
+ "Failed to decode jump in ctag entry");
IDE_EXIT;
}
@@ -818,8 +818,8 @@ not_a_number:
lookup->buffer_text = gtk_text_iter_get_slice (&begin, &end);
}
- g_task_set_task_data (task, lookup, lookup_symbol_free);
- g_task_run_in_thread (task, regex_worker);
+ ide_task_set_task_data (task, lookup, lookup_symbol_free);
+ ide_task_run_in_thread (task, regex_worker);
IDE_EXIT;
}
@@ -833,9 +833,9 @@ ide_ctags_symbol_resolver_get_location_finish (IdeCtagsSymbolResolver *self,
IdeSourceLocation *ret = NULL;
g_return_val_if_fail (IDE_IS_CTAGS_SYMBOL_RESOLVER (self), NULL);
- g_return_val_if_fail (G_IS_TASK (result), NULL);
+ g_return_val_if_fail (IDE_IS_TASK (result), NULL);
- symbol = g_task_propagate_pointer (G_TASK (result), error);
+ symbol = ide_task_propagate_pointer (IDE_TASK (result), error);
if (symbol != NULL)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]