Commit dea8b39a authored by Christian Hergert's avatar Christian Hergert

code-index: port to IdeTask

This ports the rest of the code-index to using IdeTask. The goal behind
this change (and many more upcoming) is to have more control over where
data is finalized.
parent 9d84ba50
Pipeline #6683 failed with stage
in 60 minutes and 8 seconds
......@@ -286,7 +286,7 @@ ide_code_index_index_query_cb (GObject *object,
gpointer user_data)
{
DzlFuzzyIndex *index = (DzlFuzzyIndex *)object;
g_autoptr(GTask) task = (GTask *)user_data;
g_autoptr(IdeTask) task = (IdeTask *)user_data;
g_autoptr(GListModel) list = NULL;
g_autoptr(GMutexLocker) locker = NULL;
g_autoptr(GError) error = NULL;
......@@ -296,14 +296,14 @@ ide_code_index_index_query_cb (GObject *object,
g_assert (IDE_IS_MAIN_THREAD ());
g_assert (DZL_IS_FUZZY_INDEX (index));
g_assert (G_IS_ASYNC_RESULT (result));
g_assert (G_IS_TASK (task));
g_assert (IDE_IS_TASK (task));
self = g_task_get_source_object (task);
self = ide_task_get_source_object (task);
g_assert (IDE_IS_CODE_INDEX_INDEX (self));
locker = g_mutex_locker_new (&self->mutex);
data = g_task_get_task_data (task);
data = ide_task_get_task_data (task);
g_assert (data != NULL);
list = dzl_fuzzy_index_query_finish (index, result, &error);
......@@ -336,7 +336,7 @@ ide_code_index_index_query_cb (GObject *object,
GCancellable *cancellable;
dir_index = g_ptr_array_index (self->indexes, data->curr_index);
cancellable = g_task_get_cancellable (task);
cancellable = ide_task_get_cancellable (task);
dzl_fuzzy_index_query_async (dir_index->symbol_names,
data->query,
......@@ -382,9 +382,9 @@ ide_code_index_index_query_cb (GObject *object,
}
}
g_task_return_pointer (task,
g_steal_pointer (&results),
(GDestroyNotify)g_ptr_array_unref);
ide_task_return_pointer (task,
g_steal_pointer (&results),
(GDestroyNotify)g_ptr_array_unref);
}
}
......@@ -397,7 +397,7 @@ ide_code_index_index_populate_async (IdeCodeIndexIndex *self,
gpointer user_data)
{
g_autoptr(GMutexLocker) locker = NULL;
g_autoptr(GTask) task = NULL;
g_autoptr(IdeTask) task = NULL;
g_auto(GStrv) str = NULL;
PopulateTaskData *data;
......@@ -406,9 +406,9 @@ ide_code_index_index_populate_async (IdeCodeIndexIndex *self,
g_return_if_fail (query != NULL);
g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
task = g_task_new (self, cancellable, callback, user_data);
g_task_set_source_tag (task, ide_code_index_index_populate_async);
g_task_set_priority (task, G_PRIORITY_LOW);
task = ide_task_new (self, cancellable, callback, user_data);
ide_task_set_source_tag (task, ide_code_index_index_populate_async);
ide_task_set_priority (task, G_PRIORITY_LOW);
data = g_slice_new0 (PopulateTaskData);
data->max_results = max_results;
......@@ -448,7 +448,7 @@ ide_code_index_index_populate_async (IdeCodeIndexIndex *self,
data->query = g_strconcat (prefix, "\x1F", str[1], NULL);
}
g_task_set_task_data (task, data, (GDestroyNotify)populate_task_data_free);
ide_task_set_task_data (task, data, (GDestroyNotify)populate_task_data_free);
locker = g_mutex_locker_new (&self->mutex);
......@@ -465,9 +465,9 @@ ide_code_index_index_populate_async (IdeCodeIndexIndex *self,
}
else
{
g_task_return_pointer (task,
g_ptr_array_new_with_free_func (g_object_unref),
(GDestroyNotify) g_ptr_array_unref);
ide_task_return_pointer (task,
g_ptr_array_new_with_free_func (g_object_unref),
(GDestroyNotify) g_ptr_array_unref);
}
}
......@@ -478,9 +478,9 @@ ide_code_index_index_populate_finish (IdeCodeIndexIndex *self,
{
g_return_val_if_fail (IDE_IS_MAIN_THREAD (), NULL);
g_return_val_if_fail (IDE_IS_CODE_INDEX_INDEX (self), 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);
}
IdeSymbol *
......
......@@ -28,22 +28,22 @@ populate_cb (GObject *object,
gpointer user_data)
{
IdeCodeIndexIndex *index = (IdeCodeIndexIndex *)object;
g_autoptr(GTask) task = user_data;
g_autoptr(IdeTask) task = user_data;
g_autoptr(GPtrArray) results = NULL;
g_autoptr(GError) error = NULL;
g_assert (IDE_IS_CODE_INDEX_INDEX (index));
g_assert (G_IS_ASYNC_RESULT (result));
g_assert (G_IS_TASK (task));
g_assert (IDE_IS_TASK (task));
results = ide_code_index_index_populate_finish (index, result, &error);
if (results != NULL)
g_task_return_pointer (task,
g_steal_pointer (&results),
(GDestroyNotify)g_ptr_array_unref);
ide_task_return_pointer (task,
g_steal_pointer (&results),
(GDestroyNotify)g_ptr_array_unref);
else
g_task_return_error (task, g_steal_pointer (&error));
ide_task_return_error (task, g_steal_pointer (&error));
}
static void
......@@ -55,7 +55,7 @@ ide_code_index_search_provider_search_async (IdeSearchProvider *provider,
gpointer user_data)
{
IdeCodeIndexSearchProvider *self = (IdeCodeIndexSearchProvider *)provider;
g_autoptr(GTask) task = NULL;
g_autoptr(IdeTask) task = NULL;
IdeCodeIndexService *service;
IdeCodeIndexIndex *index;
IdeContext *context;
......@@ -76,9 +76,9 @@ ide_code_index_search_provider_search_async (IdeSearchProvider *provider,
index = ide_code_index_service_get_index (service);
g_assert (IDE_IS_CODE_INDEX_INDEX (index));
task = g_task_new (self, cancellable, callback, user_data);
g_task_set_source_tag (task, ide_code_index_search_provider_search_async);
g_task_set_priority (task, G_PRIORITY_LOW);
task = ide_task_new (self, cancellable, callback, user_data);
ide_task_set_source_tag (task, ide_code_index_search_provider_search_async);
ide_task_set_priority (task, G_PRIORITY_LOW);
ide_code_index_index_populate_async (index,
search_terms,
......@@ -101,9 +101,9 @@ ide_code_index_search_provider_search_finish (IdeSearchProvider *provider,
g_return_val_if_fail (IDE_IS_MAIN_THREAD (), NULL);
g_return_val_if_fail (IDE_IS_CODE_INDEX_SEARCH_PROVIDER (provider), NULL);
g_return_val_if_fail (G_IS_TASK (result), NULL);
g_return_val_if_fail (IDE_IS_TASK (result), NULL);
ar = g_task_propagate_pointer (G_TASK (result), error);
ar = ide_task_propagate_pointer (IDE_TASK (result), error);
IDE_RETURN (ar);
}
......
......@@ -27,7 +27,7 @@ ide_code_index_symbol_resolver_lookup_cb (GObject *object,
gpointer user_data)
{
IdeCodeIndexer *code_indexer = (IdeCodeIndexer *)object;
g_autoptr(GTask) task = user_data;
g_autoptr(IdeTask) task = user_data;
g_autoptr(IdeSymbol) symbol = NULL;
g_autoptr(GError) error = NULL;
g_autofree gchar *key = NULL;
......@@ -39,14 +39,14 @@ ide_code_index_symbol_resolver_lookup_cb (GObject *object,
g_assert (IDE_IS_MAIN_THREAD ());
g_assert (IDE_IS_CODE_INDEXER (code_indexer));
g_assert (G_IS_ASYNC_RESULT (result));
g_assert (G_IS_TASK (task));
g_assert (IDE_IS_TASK (task));
self = g_task_get_source_object (task);
self = ide_task_get_source_object (task);
g_assert (IDE_IS_CODE_INDEX_SYMBOL_RESOLVER (self));
if (!(key = ide_code_indexer_generate_key_finish (code_indexer, result, &error)))
{
g_task_return_error (task, g_steal_pointer (&error));
ide_task_return_error (task, g_steal_pointer (&error));
return;
}
......@@ -62,14 +62,14 @@ ide_code_index_symbol_resolver_lookup_cb (GObject *object,
symbol = ide_code_index_index_lookup_symbol (index, key);
if (symbol != NULL)
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);
else
g_task_return_new_error (task,
G_IO_ERROR,
G_IO_ERROR_NOT_FOUND,
"Failed to locate symbol \"%s\"", key);
ide_task_return_new_error (task,
G_IO_ERROR,
G_IO_ERROR_NOT_FOUND,
"Failed to locate symbol \"%s\"", key);
}
static void
......@@ -80,7 +80,7 @@ ide_code_index_symbol_resolver_lookup_symbol_async (IdeSymbolResolver *resolve
gpointer user_data)
{
IdeCodeIndexSymbolResolver *self = (IdeCodeIndexSymbolResolver *)resolver;
g_autoptr(GTask) task = NULL;
g_autoptr(IdeTask) task = NULL;
IdeCodeIndexService *service;
IdeCodeIndexer *code_indexer;
const gchar *path;
......@@ -91,9 +91,9 @@ ide_code_index_symbol_resolver_lookup_symbol_async (IdeSymbolResolver *resolve
g_assert (location != NULL);
g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
task = g_task_new (self, cancellable, callback, user_data);
g_task_set_source_tag (task, ide_code_index_symbol_resolver_lookup_symbol_async);
g_task_set_priority (task, G_PRIORITY_LOW);
task = ide_task_new (self, cancellable, callback, user_data);
ide_task_set_source_tag (task, ide_code_index_symbol_resolver_lookup_symbol_async);
ide_task_set_priority (task, G_PRIORITY_LOW);
context = ide_object_get_context (IDE_OBJECT (self));
g_assert (IDE_IS_CONTEXT (context));
......@@ -108,10 +108,10 @@ ide_code_index_symbol_resolver_lookup_symbol_async (IdeSymbolResolver *resolve
g_assert (!code_indexer || IDE_IS_CODE_INDEXER (code_indexer));
if (code_indexer == NULL)
g_task_return_new_error (task,
G_IO_ERROR,
G_IO_ERROR_NOT_SUPPORTED,
"Failed to lcoate code indexer");
ide_task_return_new_error (task,
G_IO_ERROR,
G_IO_ERROR_NOT_SUPPORTED,
"Failed to lcoate code indexer");
else
ide_code_indexer_generate_key_async (code_indexer,
location,
......@@ -125,9 +125,9 @@ ide_code_index_symbol_resolver_lookup_symbol_finish (IdeSymbolResolver *resolve
GError **error)
{
g_assert (IDE_IS_CODE_INDEX_SYMBOL_RESOLVER (resolver));
g_assert (G_IS_TASK (result));
g_assert (IDE_IS_TASK (result));
return g_task_propagate_pointer (G_TASK (result), error);
return ide_task_propagate_pointer (IDE_TASK (result), error);
}
static void
......
......@@ -154,7 +154,7 @@ compare_keys (KVPair *a,
}
void
ide_persistent_map_builder_write_worker (GTask *task,
ide_persistent_map_builder_write_worker (IdeTask *task,
gpointer source_object,
gpointer task_data,
GCancellable *cancellable)
......@@ -168,7 +168,7 @@ ide_persistent_map_builder_write_worker (GTask *task,
GVariant *kvpairs;
GVariant *metadata;
g_assert (G_IS_TASK (task));
g_assert (IDE_IS_TASK (task));
g_assert (IDE_IS_PERSISTENT_MAP_BUILDER (source_object));
g_assert (state != NULL);
g_assert (state->keys != NULL);
......@@ -179,18 +179,18 @@ ide_persistent_map_builder_write_worker (GTask *task,
g_assert (G_IS_FILE (state->destination));
g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
if (g_task_return_error_if_cancelled (task))
if (ide_task_return_error_if_cancelled (task))
return;
if (state->keys->len == 0)
{
g_autofree gchar *path = g_file_get_path (state->destination);
g_task_return_new_error (task,
G_IO_ERROR,
G_IO_ERROR_INVALID_DATA,
"No entries to write for \"%s\"",
path);
ide_task_return_new_error (task,
G_IO_ERROR,
G_IO_ERROR_INVALID_DATA,
"No entries to write for \"%s\"",
path);
return;
}
......@@ -225,7 +225,7 @@ ide_persistent_map_builder_write_worker (GTask *task,
data = g_variant_take_ref (g_variant_dict_end (&dict));
if (g_task_return_error_if_cancelled (task))
if (ide_task_return_error_if_cancelled (task))
return;
if (g_file_replace_contents (state->destination,
......@@ -237,9 +237,9 @@ ide_persistent_map_builder_write_worker (GTask *task,
NULL,
cancellable,
&error))
g_task_return_boolean (task, TRUE);
ide_task_return_boolean (task, TRUE);
else
g_task_return_error (task, g_steal_pointer (&error));
ide_task_return_error (task, g_steal_pointer (&error));
}
gboolean
......@@ -249,7 +249,8 @@ ide_persistent_map_builder_write (IdePersistentMapBuilder *self,
GCancellable *cancellable,
GError **error)
{
g_autoptr(GTask) task = NULL;
g_autoptr(IdeTask) task = NULL;
BuildState *state;
g_return_val_if_fail (IDE_IS_PERSISTENT_MAP_BUILDER (self), FALSE);
g_return_val_if_fail (G_IS_FILE (destination), FALSE);
......@@ -257,15 +258,17 @@ ide_persistent_map_builder_write (IdePersistentMapBuilder *self,
g_return_val_if_fail (self->state != NULL, FALSE);
g_return_val_if_fail (self->state->destination == NULL, FALSE);
self->state->destination = g_object_ref (destination);
state = g_steal_pointer (&self->state);
state->destination = g_object_ref (destination);
task = ide_task_new (self, cancellable, NULL, NULL);
ide_task_set_source_tag (task, ide_persistent_map_builder_write);
ide_task_set_priority (task, io_priority);
ide_persistent_map_builder_write_worker (task, self, state, cancellable);
task = g_task_new (self, cancellable, NULL, NULL);
g_task_set_source_tag (task, ide_persistent_map_builder_write);
g_task_set_priority (task, io_priority);
g_task_set_task_data (task, g_steal_pointer (&self->state), build_state_free);
g_task_run_in_thread_sync (task, ide_persistent_map_builder_write_worker);
build_state_free (state);
return g_task_propagate_boolean (task, error);
return ide_task_propagate_boolean (task, error);
}
void
......@@ -276,7 +279,7 @@ ide_persistent_map_builder_write_async (IdePersistentMapBuilder *self,
GAsyncReadyCallback callback,
gpointer user_data)
{
g_autoptr(GTask) task = NULL;
g_autoptr(IdeTask) task = NULL;
g_return_if_fail (IDE_IS_PERSISTENT_MAP_BUILDER (self));
g_return_if_fail (G_IS_FILE (destination));
......@@ -286,11 +289,11 @@ ide_persistent_map_builder_write_async (IdePersistentMapBuilder *self,
self->state->destination = g_object_ref (destination);
task = g_task_new (self, cancellable, callback, user_data);
g_task_set_priority (task, io_priority);
g_task_set_source_tag (task, ide_persistent_map_builder_write_async);
g_task_set_task_data (task, g_steal_pointer (&self->state), build_state_free);
g_task_run_in_thread (task, ide_persistent_map_builder_write_worker);
task = ide_task_new (self, cancellable, callback, user_data);
ide_task_set_priority (task, io_priority);
ide_task_set_source_tag (task, ide_persistent_map_builder_write_async);
ide_task_set_task_data (task, g_steal_pointer (&self->state), build_state_free);
ide_task_run_in_thread (task, ide_persistent_map_builder_write_worker);
}
/**
......@@ -308,9 +311,9 @@ ide_persistent_map_builder_write_finish (IdePersistentMapBuilder *self,
GError **error)
{
g_return_val_if_fail (IDE_IS_PERSISTENT_MAP_BUILDER (self), FALSE);
g_return_val_if_fail (G_IS_TASK (result), FALSE);
g_return_val_if_fail (IDE_IS_TASK (result), FALSE);
return g_task_propagate_boolean (G_TASK (result), error);
return ide_task_propagate_boolean (IDE_TASK (result), error);
}
static void
......
......@@ -59,7 +59,7 @@ G_STATIC_ASSERT (sizeof (KVPair) == 8);
G_DEFINE_TYPE (IdePersistentMap, ide_persistent_map, G_TYPE_OBJECT)
static void
ide_persistent_map_load_file_worker (GTask *task,
ide_persistent_map_load_file_worker (IdeTask *task,
gpointer source_object,
gpointer task_data,
GCancellable *cancellable)
......@@ -78,7 +78,7 @@ ide_persistent_map_load_file_worker (GTask *task,
gint32 version;
gsize n_elements;
g_assert (G_IS_TASK (task));
g_assert (IDE_IS_TASK (task));
g_assert (IDE_IS_PERSISTENT_MAP (self));
g_assert (G_IS_FILE (file));
g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
......@@ -88,10 +88,10 @@ ide_persistent_map_load_file_worker (GTask *task,
if (!g_file_is_native (file) || NULL == (path = g_file_get_path (file)))
{
g_task_return_new_error (task,
G_IO_ERROR,
G_IO_ERROR_INVALID_FILENAME,
"Index must be a local file");
ide_task_return_new_error (task,
G_IO_ERROR,
G_IO_ERROR_INVALID_FILENAME,
"Index must be a local file");
return;
}
......@@ -99,7 +99,7 @@ ide_persistent_map_load_file_worker (GTask *task,
if (mapped_file == NULL)
{
g_task_return_error (task, g_steal_pointer (&error));
ide_task_return_error (task, g_steal_pointer (&error));
return;
}
......@@ -110,10 +110,10 @@ ide_persistent_map_load_file_worker (GTask *task,
if (data == NULL)
{
g_task_return_new_error (task,
G_IO_ERROR,
G_IO_ERROR_INVAL,
"Failed to parse GVariant");
ide_task_return_new_error (task,
G_IO_ERROR,
G_IO_ERROR_INVAL,
"Failed to parse GVariant");
return;
}
......@@ -123,11 +123,11 @@ ide_persistent_map_load_file_worker (GTask *task,
if (!g_variant_dict_lookup (dict, "version", "i", &version) || version != 2)
{
g_task_return_new_error (task,
G_IO_ERROR,
G_IO_ERROR_INVAL,
"Version mismatch in gvariant. Got %d, expected 1",
version);
ide_task_return_new_error (task,
G_IO_ERROR,
G_IO_ERROR_INVAL,
"Version mismatch in gvariant. Got %d, expected 1",
version);
return;
}
......@@ -141,10 +141,10 @@ ide_persistent_map_load_file_worker (GTask *task,
if (keys == NULL || values == NULL || kvpairs == NULL || metadata == NULL || !self->byte_order)
{
g_task_return_new_error (task,
G_IO_ERROR,
G_IO_ERROR_INVAL,
"Invalid GVariant index");
ide_task_return_new_error (task,
G_IO_ERROR,
G_IO_ERROR_INVAL,
"Invalid GVariant index");
return;
}
......@@ -166,7 +166,7 @@ ide_persistent_map_load_file_worker (GTask *task,
g_assert (self->kvpairs != NULL);
g_assert (self->metadata != NULL);
g_task_return_boolean (task, TRUE);
ide_task_return_boolean (task, TRUE);
}
gboolean
......@@ -175,7 +175,7 @@ ide_persistent_map_load_file (IdePersistentMap *self,
GCancellable *cancellable,
GError **error)
{
g_autoptr(GTask) task = NULL;
g_autoptr(IdeTask) task = NULL;
g_return_val_if_fail (IDE_IS_PERSISTENT_MAP (self), FALSE);
g_return_val_if_fail (self->load_called == FALSE, FALSE);
......@@ -184,13 +184,12 @@ ide_persistent_map_load_file (IdePersistentMap *self,
self->load_called = TRUE;
task = g_task_new (self, cancellable, NULL, NULL);
g_task_set_source_tag (task, ide_persistent_map_load_file);
g_task_set_priority (task, G_PRIORITY_LOW);
g_task_set_task_data (task, g_object_ref (file), g_object_unref);
g_task_run_in_thread_sync (task, ide_persistent_map_load_file_worker);
task = ide_task_new (self, cancellable, NULL, NULL);
ide_task_set_source_tag (task, ide_persistent_map_load_file);
ide_task_set_priority (task, G_PRIORITY_LOW);
ide_persistent_map_load_file_worker (task, self, file, cancellable);
return g_task_propagate_boolean (task, error);
return ide_task_propagate_boolean (task, error);
}
void
......@@ -200,7 +199,7 @@ ide_persistent_map_load_file_async (IdePersistentMap *self,
GAsyncReadyCallback callback,
gpointer user_data)
{
g_autoptr(GTask) task = NULL;
g_autoptr(IdeTask) task = NULL;
g_return_if_fail (IDE_IS_PERSISTENT_MAP (self));
g_return_if_fail (self->load_called == FALSE);
......@@ -209,11 +208,11 @@ ide_persistent_map_load_file_async (IdePersistentMap *self,
self->load_called = TRUE;
task = g_task_new (self, cancellable, callback, user_data);
g_task_set_source_tag (task, ide_persistent_map_load_file_async);
g_task_set_priority (task, G_PRIORITY_LOW);
g_task_set_task_data (task, g_object_ref (file), g_object_unref);
g_task_run_in_thread (task, ide_persistent_map_load_file_worker);
task = ide_task_new (self, cancellable, callback, user_data);
ide_task_set_source_tag (task, ide_persistent_map_load_file_async);
ide_task_set_priority (task, G_PRIORITY_LOW);
ide_task_set_task_data (task, g_object_ref (file), g_object_unref);
ide_task_run_in_thread (task, ide_persistent_map_load_file_worker);
}
/**
......@@ -230,9 +229,9 @@ ide_persistent_map_load_file_finish (IdePersistentMap *self,
GError **error)
{
g_return_val_if_fail (IDE_IS_PERSISTENT_MAP (self), FALSE);
g_return_val_if_fail (G_IS_TASK (result), FALSE);
g_return_val_if_fail (IDE_IS_TASK (result), FALSE);
return g_task_propagate_boolean (G_TASK (result), error);
return ide_task_propagate_boolean (IDE_TASK (result), error);
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment