[gnome-builder] libide-threading: remove use of private instance data
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] libide-threading: remove use of private instance data
- Date: Tue, 12 Jul 2022 06:39:10 +0000 (UTC)
commit 86dcc20af6410f97236f7945d7e9f81fc4750279
Author: Christian Hergert <chergert redhat com>
Date: Mon Jul 11 17:52:31 2022 -0700
libide-threading: remove use of private instance data
We never used this because we don't subclass tasks in Builder. Also update
the availability macros.
src/libide/threading/ide-gtask.c | 4 -
src/libide/threading/ide-task.c | 584 ++++++++++++++-------------------
src/libide/threading/ide-task.h | 98 +++---
src/libide/threading/ide-thread-pool.c | 6 -
src/libide/threading/ide-thread-pool.h | 7 +-
5 files changed, 295 insertions(+), 404 deletions(-)
---
diff --git a/src/libide/threading/ide-gtask.c b/src/libide/threading/ide-gtask.c
index 4373ab0fa..d6efd4e5a 100644
--- a/src/libide/threading/ide-gtask.c
+++ b/src/libide/threading/ide-gtask.c
@@ -100,8 +100,6 @@ task_state_attach (TaskState *state)
* This is just like g_task_return_boolean() except that it enforces
* that the current stack return to the main context before dispatching
* the callback.
- *
- * Since: 3.32
*/
void
ide_g_task_return_boolean_from_main (GTask *task,
@@ -160,8 +158,6 @@ ide_g_task_return_pointer_from_main (GTask *task,
*
* Like g_task_return_error() but ensures we return to the main loop before
* dispatching the result.
- *
- * Since: 3.32
*/
void
ide_g_task_return_error_from_main (GTask *task,
diff --git a/src/libide/threading/ide-task.c b/src/libide/threading/ide-task.c
index e7b1bb512..940822ab0 100644
--- a/src/libide/threading/ide-task.c
+++ b/src/libide/threading/ide-task.c
@@ -65,8 +65,6 @@
* to copy the result to another task. Additionally, ide_task_return_object()
* provides a simplified API over ide_task_return_pointer() which also allows
* copying the result to chained tasks.
- *
- * Since: 3.32
*/
typedef struct
@@ -147,8 +145,10 @@ typedef struct
gint priority;
} IdeTaskCancel;
-typedef struct
+struct _IdeTask
{
+ GObject parent_instance;
+
/*
* @global_link is used to store a pointer to the task in the global
* queue during the lifetime of the task. This is a debugging feature
@@ -319,8 +319,7 @@ typedef struct
* If we have dispatched to a thread already.
*/
guint thread_called : 1;
-
-} IdeTaskPrivate;
+};
static void async_result_init_iface (GAsyncResultIface *iface);
static void ide_task_data_free (IdeTaskData *task_data);
@@ -332,9 +331,8 @@ static void ide_task_release (IdeTask *self,
G_DEFINE_AUTOPTR_CLEANUP_FUNC (IdeTaskData, ide_task_data_free);
G_DEFINE_AUTOPTR_CLEANUP_FUNC (IdeTaskResult, ide_task_result_free);
-G_DEFINE_TYPE_WITH_CODE (IdeTask, ide_task, G_TYPE_OBJECT,
- G_ADD_PRIVATE (IdeTask)
- G_IMPLEMENT_INTERFACE (G_TYPE_ASYNC_RESULT, async_result_init_iface))
+G_DEFINE_FINAL_TYPE_WITH_CODE (IdeTask, ide_task, G_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (G_TYPE_ASYNC_RESULT, async_result_init_iface))
enum {
PROP_0,
@@ -519,20 +517,20 @@ ide_task_thread_func (gpointer data)
g_autoptr(GObject) source_object = NULL;
g_autoptr(GCancellable) cancellable = NULL;
g_autoptr(IdeTask) task = data;
- IdeTaskPrivate *priv = ide_task_get_instance_private (task);
+ IdeTask *self = task;
gpointer task_data = NULL;
IdeTaskThreadFunc thread_func;
g_assert (IDE_IS_TASK (task));
- g_mutex_lock (&priv->mutex);
- source_object = priv->source_object ? g_object_ref (priv->source_object) : NULL;
- cancellable = priv->cancellable ? g_object_ref (priv->cancellable) : NULL;
- if (priv->task_data)
- task_data = priv->task_data->data;
- thread_func = priv->thread_func;
- priv->thread_func = NULL;
- g_mutex_unlock (&priv->mutex);
+ g_mutex_lock (&self->mutex);
+ source_object = self->source_object ? g_object_ref (self->source_object) : NULL;
+ cancellable = self->cancellable ? g_object_ref (self->cancellable) : NULL;
+ if (self->task_data)
+ task_data = self->task_data->data;
+ thread_func = self->thread_func;
+ self->thread_func = NULL;
+ g_mutex_unlock (&self->mutex);
g_assert (thread_func != NULL);
@@ -541,22 +539,22 @@ ide_task_thread_func (gpointer data)
g_clear_object (&source_object);
g_clear_object (&cancellable);
- g_mutex_lock (&priv->mutex);
+ g_mutex_lock (&self->mutex);
/*
* We've delayed our ide_task_return() until we reach here, so now
* we can steal our object instance and complete the task along with
* ensuring the object wont be finalized from this thread.
*/
- if (priv->thread_result)
+ if (self->thread_result)
{
- IdeTaskResult *result = g_steal_pointer (&priv->thread_result);
+ IdeTaskResult *result = g_steal_pointer (&self->thread_result);
g_assert (result->task == task);
g_clear_object (&result->task);
result->task = g_steal_pointer (&task);
- priv->return_source = ide_task_complete (g_steal_pointer (&result));
+ self->return_source = ide_task_complete (g_steal_pointer (&result));
g_assert (source_object == NULL);
g_assert (cancellable == NULL);
@@ -571,7 +569,7 @@ ide_task_thread_func (gpointer data)
*/
}
- g_mutex_unlock (&priv->mutex);
+ g_mutex_unlock (&self->mutex);
g_assert (source_object == NULL);
g_assert (cancellable == NULL);
@@ -581,15 +579,14 @@ static void
ide_task_dispose (GObject *object)
{
IdeTask *self = (IdeTask *)object;
- IdeTaskPrivate *priv = ide_task_get_instance_private (self);
g_assert (IDE_IS_TASK (self));
ide_task_release (self, TRUE);
- g_mutex_lock (&priv->mutex);
- g_clear_pointer (&priv->result, ide_task_result_free);
- g_mutex_unlock (&priv->mutex);
+ g_mutex_lock (&self->mutex);
+ g_clear_pointer (&self->result, ide_task_result_free);
+ g_mutex_unlock (&self->mutex);
G_OBJECT_CLASS (ide_task_parent_class)->dispose (object);
}
@@ -598,39 +595,38 @@ static void
ide_task_finalize (GObject *object)
{
IdeTask *self = (IdeTask *)object;
- IdeTaskPrivate *priv = ide_task_get_instance_private (self);
G_LOCK (global_task_list);
- g_queue_unlink (&global_task_list, &priv->global_link);
+ g_queue_unlink (&global_task_list, &self->global_link);
G_UNLOCK (global_task_list);
- if (!priv->return_called)
+ if (!self->return_called)
g_critical ("%s [%s] finalized before completing",
G_OBJECT_TYPE_NAME (self),
- priv->name ?: "unnamed");
- else if (priv->chained && priv->chained->len)
+ self->name ?: "unnamed");
+ else if (self->chained && self->chained->len)
g_critical ("%s [%s] finalized before dependents were notified",
G_OBJECT_TYPE_NAME (self),
- priv->name ?: "unnamed");
- else if (priv->thread_func)
+ self->name ?: "unnamed");
+ else if (self->thread_func)
g_critical ("%s [%s] finalized while thread_func is active",
G_OBJECT_TYPE_NAME (self),
- priv->name ?: "unnamed");
- else if (!priv->completed)
+ self->name ?: "unnamed");
+ else if (!self->completed)
g_critical ("%s [%s] finalized before completion",
G_OBJECT_TYPE_NAME (self),
- priv->name ?: "unnamed");
+ self->name ?: "unnamed");
- g_assert (priv->return_source == 0);
- g_assert (priv->result == NULL);
- g_assert (priv->task_data == NULL);
- g_assert (priv->source_object == NULL);
- g_assert (priv->chained == NULL);
- g_assert (priv->thread_result == NULL);
+ g_assert (self->return_source == 0);
+ g_assert (self->result == NULL);
+ g_assert (self->task_data == NULL);
+ g_assert (self->source_object == NULL);
+ g_assert (self->chained == NULL);
+ g_assert (self->thread_result == NULL);
- g_clear_pointer (&priv->main_context, g_main_context_unref);
- g_clear_object (&priv->cancellable);
- g_mutex_clear (&priv->mutex);
+ g_clear_pointer (&self->main_context, g_main_context_unref);
+ g_clear_object (&self->cancellable);
+ g_mutex_clear (&self->mutex);
G_OBJECT_CLASS (ide_task_parent_class)->finalize (object);
}
@@ -682,19 +678,17 @@ ide_task_class_init (IdeTaskClass *klass)
static void
ide_task_init (IdeTask *self)
{
- IdeTaskPrivate *priv = ide_task_get_instance_private (self);
-
- g_mutex_init (&priv->mutex);
+ g_mutex_init (&self->mutex);
- priv->check_cancellable = TRUE;
- priv->release_on_propagate = TRUE;
- priv->priority = G_PRIORITY_DEFAULT;
- priv->complete_priority = PRIORITY_REDRAW + 1;
- priv->main_context = g_main_context_ref_thread_default ();
- priv->global_link.data = self;
+ self->check_cancellable = TRUE;
+ self->release_on_propagate = TRUE;
+ self->priority = G_PRIORITY_DEFAULT;
+ self->complete_priority = PRIORITY_REDRAW + 1;
+ self->main_context = g_main_context_ref_thread_default ();
+ self->global_link.data = self;
G_LOCK (global_task_list);
- g_queue_push_tail_link (&global_task_list, &priv->global_link);
+ g_queue_push_tail_link (&global_task_list, &self->global_link);
G_UNLOCK (global_task_list);
}
@@ -715,20 +709,17 @@ ide_task_init (IdeTask *self)
* release the object in a manner that is unsafe for the source object.
*
* Returns: (transfer none) (nullable) (type GObject.Object): a #GObject or %NULL
- *
- * Since: 3.32
*/
gpointer
ide_task_get_source_object (IdeTask *self)
{
- IdeTaskPrivate *priv = ide_task_get_instance_private (self);
gpointer ret;
g_return_val_if_fail (IDE_IS_TASK (self), NULL);
- g_mutex_lock (&priv->mutex);
- ret = priv->source_object;
- g_mutex_unlock (&priv->mutex);
+ g_mutex_lock (&self->mutex);
+ ret = self->source_object;
+ g_mutex_unlock (&self->mutex);
return ret;
}
@@ -748,8 +739,6 @@ ide_task_get_source_object (IdeTask *self)
* the task itself.
*
* Returns: (transfer full): an #IdeTask
- *
- * Since: 3.32
*/
IdeTask *
(ide_task_new) (gpointer source_object,
@@ -758,20 +747,18 @@ IdeTask *
gpointer user_data)
{
g_autoptr(IdeTask) self = NULL;
- IdeTaskPrivate *priv;
g_return_val_if_fail (!source_object || G_IS_OBJECT (source_object), NULL);
g_return_val_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable), NULL);
self = g_object_new (IDE_TYPE_TASK, NULL);
- priv = ide_task_get_instance_private (self);
- priv->source_object = source_object ? g_object_ref (source_object) : NULL;
- priv->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
- priv->callback = callback;
- priv->user_data = user_data;
+ self->source_object = source_object ? g_object_ref (source_object) : NULL;
+ self->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
+ self->callback = callback;
+ self->user_data = user_data;
#ifdef ENABLE_TIME_CHART
- priv->begin_time = g_get_monotonic_time ();
+ self->begin_time = g_get_monotonic_time ();
#endif
return g_steal_pointer (&self);
@@ -785,16 +772,12 @@ IdeTask *
* Checks if @source_object matches the object the task was created with.
*
* Returns: %TRUE is source_object matches
- *
- * Since: 3.32
*/
gboolean
ide_task_is_valid (gpointer self,
gpointer source_object)
{
- IdeTaskPrivate *priv = ide_task_get_instance_private (self);
-
- return IDE_IS_TASK (self) && priv->source_object == source_object;
+ return IDE_IS_TASK (self) && IDE_TASK (self)->source_object == source_object;
}
/**
@@ -808,20 +791,17 @@ ide_task_is_valid (gpointer self,
* same #GMainContext as the callback.
*
* Returns: %TRUE if the task has completed
- *
- * Since: 3.32
*/
gboolean
ide_task_get_completed (IdeTask *self)
{
- IdeTaskPrivate *priv = ide_task_get_instance_private (self);
gboolean ret;
g_return_val_if_fail (IDE_IS_TASK (self), FALSE);
- g_mutex_lock (&priv->mutex);
- ret = priv->completed;
- g_mutex_unlock (&priv->mutex);
+ g_mutex_lock (&self->mutex);
+ ret = self->completed;
+ g_mutex_unlock (&self->mutex);
return ret;
}
@@ -829,14 +809,13 @@ ide_task_get_completed (IdeTask *self)
gint
ide_task_get_priority (IdeTask *self)
{
- IdeTaskPrivate *priv = ide_task_get_instance_private (self);
gint ret;
g_return_val_if_fail (IDE_IS_TASK (self), 0);
- g_mutex_lock (&priv->mutex);
- ret = priv->priority;
- g_mutex_unlock (&priv->mutex);
+ g_mutex_lock (&self->mutex);
+ ret = self->priority;
+ g_mutex_unlock (&self->mutex);
return ret;
}
@@ -845,26 +824,23 @@ void
ide_task_set_priority (IdeTask *self,
gint priority)
{
- IdeTaskPrivate *priv = ide_task_get_instance_private (self);
-
g_return_if_fail (IDE_IS_TASK (self));
- g_mutex_lock (&priv->mutex);
- priv->priority = priority;
- g_mutex_unlock (&priv->mutex);
+ g_mutex_lock (&self->mutex);
+ self->priority = priority;
+ g_mutex_unlock (&self->mutex);
}
gint
ide_task_get_complete_priority (IdeTask *self)
{
- IdeTaskPrivate *priv = ide_task_get_instance_private (self);
gint ret;
g_return_val_if_fail (IDE_IS_TASK (self), 0);
- g_mutex_lock (&priv->mutex);
- ret = priv->complete_priority;
- g_mutex_unlock (&priv->mutex);
+ g_mutex_lock (&self->mutex);
+ ret = self->complete_priority;
+ g_mutex_unlock (&self->mutex);
return ret;
}
@@ -873,13 +849,11 @@ void
ide_task_set_complete_priority (IdeTask *self,
gint complete_priority)
{
- IdeTaskPrivate *priv = ide_task_get_instance_private (self);
-
g_return_if_fail (IDE_IS_TASK (self));
- g_mutex_lock (&priv->mutex);
- priv->complete_priority = complete_priority;
- g_mutex_unlock (&priv->mutex);
+ g_mutex_lock (&self->mutex);
+ self->complete_priority = complete_priority;
+ g_mutex_unlock (&self->mutex);
}
/**
@@ -889,25 +863,19 @@ ide_task_set_complete_priority (IdeTask *self,
* Gets the #GCancellable for the task.
*
* Returns: (transfer none) (nullable): a #GCancellable or %NULL
- *
- * Since: 3.32
*/
GCancellable *
ide_task_get_cancellable (IdeTask *self)
{
- IdeTaskPrivate *priv = ide_task_get_instance_private (self);
-
g_return_val_if_fail (IDE_IS_TASK (self), NULL);
- return priv->cancellable;
+ return self->cancellable;
}
static void
ide_task_deliver_result (IdeTask *self,
IdeTaskResult *result)
{
- IdeTaskPrivate *priv = ide_task_get_instance_private (self);
-
g_assert (IDE_IS_TASK (self));
g_assert (result != NULL);
g_assert (result->task == NULL);
@@ -920,36 +888,35 @@ ide_task_deliver_result (IdeTask *self,
*/
result->task = g_object_ref (self);
- result->main_context = g_main_context_ref (priv->main_context);
- result->complete_priority = priv->complete_priority;
+ result->main_context = g_main_context_ref (self->main_context);
+ result->complete_priority = self->complete_priority;
- g_mutex_lock (&priv->mutex);
+ g_mutex_lock (&self->mutex);
- priv->return_called = TRUE;
- priv->return_source = ide_task_complete (g_steal_pointer (&result));
+ self->return_called = TRUE;
+ self->return_source = ide_task_complete (g_steal_pointer (&result));
- g_mutex_unlock (&priv->mutex);
+ g_mutex_unlock (&self->mutex);
}
static void
ide_task_release (IdeTask *self,
gboolean force)
{
- IdeTaskPrivate *priv = ide_task_get_instance_private (self);
g_autoptr(IdeTaskData) task_data = NULL;
g_autoptr(GObject) source_object = NULL;
g_autoptr(GPtrArray) chained = NULL;
g_assert (IDE_IS_TASK (self));
- g_mutex_lock (&priv->mutex);
- if (force || priv->release_on_propagate)
+ g_mutex_lock (&self->mutex);
+ if (force || self->release_on_propagate)
{
- source_object = g_steal_pointer (&priv->source_object);
- task_data = g_steal_pointer (&priv->task_data);
- chained = g_steal_pointer (&priv->chained);
+ source_object = g_steal_pointer (&self->source_object);
+ task_data = g_steal_pointer (&self->task_data);
+ chained = g_steal_pointer (&self->chained);
}
- g_mutex_unlock (&priv->mutex);
+ g_mutex_unlock (&self->mutex);
if (chained)
{
@@ -976,7 +943,6 @@ ide_task_return_cb (gpointer user_data)
g_autoptr(GPtrArray) chained = NULL;
GAsyncReadyCallback callback = NULL;
gpointer callback_data = NULL;
- IdeTaskPrivate *priv;
g_assert (result != NULL);
g_assert (IDE_IS_TASK (result->task));
@@ -986,54 +952,53 @@ ide_task_return_cb (gpointer user_data)
* a reference cycle.
*/
self = g_steal_pointer (&result->task);
- priv = ide_task_get_instance_private (self);
#ifdef ENABLE_TIME_CHART
g_message ("TASK-END: %s: duration=%lf",
- priv->name,
- (g_get_monotonic_time () - priv->begin_time) / (gdouble)G_USEC_PER_SEC);
+ self->name,
+ (g_get_monotonic_time () - self->begin_time) / (gdouble)G_USEC_PER_SEC);
#endif
- g_mutex_lock (&priv->mutex);
+ g_mutex_lock (&self->mutex);
- g_assert (priv->return_source != 0);
+ g_assert (self->return_source != 0);
- priv->return_source = 0;
+ self->return_source = 0;
- if (priv->got_cancel && priv->result != NULL)
+ if (self->got_cancel && self->result != NULL)
{
/* We can discard this since we already handled a result for the
* task. We delivered this here just so that we could finalize
* any objects back inside them main context.
*/
- g_mutex_unlock (&priv->mutex);
+ g_mutex_unlock (&self->mutex);
return G_SOURCE_REMOVE;
}
- g_assert (priv->result == NULL);
- g_assert (priv->return_called == TRUE);
+ g_assert (self->result == NULL);
+ g_assert (self->return_called == TRUE);
- priv->result = g_steal_pointer (&result);
+ self->result = g_steal_pointer (&result);
- callback = priv->callback;
- callback_data = priv->user_data;
+ callback = self->callback;
+ callback_data = self->user_data;
- priv->callback = NULL;
- priv->user_data = NULL;
+ self->callback = NULL;
+ self->user_data = NULL;
- source_object = priv->source_object ? g_object_ref (priv->source_object) : NULL;
- cancellable = priv->cancellable ? g_object_ref (priv->cancellable) : NULL;
+ source_object = self->source_object ? g_object_ref (self->source_object) : NULL;
+ cancellable = self->cancellable ? g_object_ref (self->cancellable) : NULL;
- chained = g_steal_pointer (&priv->chained);
+ chained = g_steal_pointer (&self->chained);
/* Make a private copy of the result data if we're going to need to notify
* other tasks of our result. We can't guarantee the result in @task will
* stay alive during our dispatch callbacks, so we need to have a copy.
*/
if (chained != NULL && chained->len > 0)
- result_copy = ide_task_result_copy (priv->result);
+ result_copy = ide_task_result_copy (self->result);
- g_mutex_unlock (&priv->mutex);
+ g_mutex_unlock (&self->mutex);
if (callback)
callback (source_object, G_ASYNC_RESULT (self), callback_data);
@@ -1049,9 +1014,9 @@ ide_task_return_cb (gpointer user_data)
}
}
- g_mutex_lock (&priv->mutex);
- priv->completed = TRUE;
- g_mutex_unlock (&priv->mutex);
+ g_mutex_lock (&self->mutex);
+ self->completed = TRUE;
+ g_mutex_unlock (&self->mutex);
g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_COMPLETED]);
@@ -1070,22 +1035,21 @@ static void
ide_task_return (IdeTask *self,
IdeTaskResult *result)
{
- IdeTaskPrivate *priv = ide_task_get_instance_private (self);
g_autoptr(GMutexLocker) locker = NULL;
g_assert (IDE_IS_TASK (self));
g_assert (result != NULL);
g_assert (result->task == NULL);
- locker = g_mutex_locker_new (&priv->mutex);
+ locker = g_mutex_locker_new (&self->mutex);
- if (priv->cancel_handler && priv->cancellable)
+ if (self->cancel_handler && self->cancellable)
{
- g_cancellable_disconnect (priv->cancellable, priv->cancel_handler);
- priv->cancel_handler = 0;
+ g_cancellable_disconnect (self->cancellable, self->cancel_handler);
+ self->cancel_handler = 0;
}
- if (priv->return_called)
+ if (self->return_called)
{
GSource *source;
@@ -1102,8 +1066,8 @@ ide_task_return (IdeTask *self,
/* If we haven't been cancelled, then we reached this path multiple
* times by programmer error.
*/
- if (!priv->got_cancel)
- g_critical ("Attempted to set result on task [%s] multiple times", priv->name);
+ if (!self->got_cancel)
+ g_critical ("Attempted to set result on task [%s] multiple times", self->name);
/*
* This task has already returned, but we need to ensure that we pass
@@ -1117,32 +1081,32 @@ ide_task_return (IdeTask *self,
ide_task_return_dummy_cb,
result,
(GDestroyNotify)ide_task_result_free);
- g_source_attach (source, priv->main_context);
+ g_source_attach (source, self->main_context);
g_source_unref (source);
return;
}
- priv->return_called = TRUE;
+ self->return_called = TRUE;
if (result->type == IDE_TASK_RESULT_CANCELLED)
- priv->got_cancel = TRUE;
+ self->got_cancel = TRUE;
result->task = g_object_ref (self);
- result->main_context = g_main_context_ref (priv->main_context);
- result->complete_priority = priv->complete_priority;
+ result->main_context = g_main_context_ref (self->main_context);
+ result->complete_priority = self->complete_priority;
/* We can queue the result immediately if we're not being called
* while we're inside of a ide_task_run_in_thread() callback. Otherwise,
* that thread cleanup must complete this to ensure objects cannot
* be finalized in that thread.
*/
- if (!priv->thread_called || IDE_IS_MAIN_THREAD ())
- priv->return_source = ide_task_complete (result);
- else if (priv->return_on_cancel && result->type == IDE_TASK_RESULT_CANCELLED)
- priv->return_source = ide_task_complete (result);
+ if (!self->thread_called || IDE_IS_MAIN_THREAD ())
+ self->return_source = ide_task_complete (result);
+ else if (self->return_on_cancel && result->type == IDE_TASK_RESULT_CANCELLED)
+ self->return_source = ide_task_complete (result);
else
- priv->thread_result = result;
+ self->thread_result = result;
}
/**
@@ -1154,8 +1118,6 @@ ide_task_return (IdeTask *self,
*
* Other tasks depending on the result will be notified after returning
* to the #GMainContext of the task.
- *
- * Since: 3.32
*/
void
ide_task_return_int (IdeTask *self,
@@ -1181,8 +1143,6 @@ ide_task_return_int (IdeTask *self,
*
* Other tasks depending on the result will be notified after returning
* to the #GMainContext of the task.
- *
- * Since: 3.32
*/
void
ide_task_return_boolean (IdeTask *self,
@@ -1208,8 +1168,6 @@ ide_task_return_boolean (IdeTask *self,
* This is similar to ide_task_return_pointer(), but allows the task to
* know the boxed #GType so that the result may be propagated to chained
* tasks.
- *
- * Since: 3.32
*/
void
ide_task_return_boxed (IdeTask *self,
@@ -1239,8 +1197,6 @@ ide_task_return_boxed (IdeTask *self,
*
* Takes ownership of @instance to allow saving a reference increment and
* decrement by the caller.
- *
- * Since: 3.32
*/
void
ide_task_return_object (IdeTask *self,
@@ -1273,8 +1229,6 @@ ide_task_return_object (IdeTask *self,
*
* If you need task chaining with pointers, see ide_task_return_boxed()
* or ide_task_return_object().
- *
- * Since: 3.32
*/
void
(ide_task_return_pointer) (IdeTask *self,
@@ -1299,8 +1253,6 @@ void
* @error: (transfer full): a #GError
*
* Sets @error as the result of the #IdeTask
- *
- * Since: 3.32
*/
void
ide_task_return_error (IdeTask *self,
@@ -1325,8 +1277,6 @@ ide_task_return_error (IdeTask *self,
* @format: the printf-style format string
*
* Creates a new #GError and sets it as the result for the task.
- *
- * Since: 3.32
*/
void
ide_task_return_new_error (IdeTask *self,
@@ -1359,28 +1309,31 @@ ide_task_return_new_error (IdeTask *self,
* a cancellation state.
*
* Returns: %TRUE if the task was cancelled and error returned.
- *
- * Since: 3.32
*/
gboolean
ide_task_return_error_if_cancelled (IdeTask *self)
{
- IdeTaskPrivate *priv = ide_task_get_instance_private (self);
+ GError *error = NULL;
gboolean failed;
g_return_val_if_fail (IDE_IS_TASK (self), FALSE);
- g_mutex_lock (&priv->mutex);
- failed = g_cancellable_is_cancelled (priv->cancellable) ||
- (IDE_IS_OBJECT (priv->source_object) &&
- ide_object_in_destruction (IDE_OBJECT (priv->source_object)));
- g_mutex_unlock (&priv->mutex);
+ g_mutex_lock (&self->mutex);
+ failed = g_cancellable_is_cancelled (self->cancellable) ||
+ (IDE_IS_OBJECT (self->source_object) &&
+ !ide_object_check_ready (IDE_OBJECT (self->source_object), &error));
+ g_mutex_unlock (&self->mutex);
if (failed)
- ide_task_return_new_error (self,
- G_IO_ERROR,
- G_IO_ERROR_CANCELLED,
- "The task was cancelled");
+ {
+ if (error != NULL)
+ ide_task_return_error (self, g_steal_pointer (&error));
+ else
+ ide_task_return_new_error (self,
+ G_IO_ERROR,
+ G_IO_ERROR_CANCELLED,
+ "The task was cancelled");
+ }
return failed;
}
@@ -1397,22 +1350,18 @@ ide_task_return_error_if_cancelled (IdeTask *self)
*
* Generally, you want to leave this as %TRUE to ensure thread-safety on the
* dependent objects and task data.
- *
- * Since: 3.32
*/
void
ide_task_set_release_on_propagate (IdeTask *self,
gboolean release_on_propagate)
{
- IdeTaskPrivate *priv = ide_task_get_instance_private (self);
-
g_return_if_fail (IDE_IS_TASK (self));
release_on_propagate = !!release_on_propagate;
- g_mutex_lock (&priv->mutex);
- priv->release_on_propagate = release_on_propagate;
- g_mutex_unlock (&priv->mutex);
+ g_mutex_lock (&self->mutex);
+ self->release_on_propagate = release_on_propagate;
+ g_mutex_unlock (&self->mutex);
}
/**
@@ -1422,20 +1371,16 @@ ide_task_set_release_on_propagate (IdeTask *self,
*
* Sets the source tag for the task. Generally this is a function pointer
* of the function that created the task.
- *
- * Since: 3.32
*/
void
ide_task_set_source_tag (IdeTask *self,
gpointer source_tag)
{
- IdeTaskPrivate *priv = ide_task_get_instance_private (self);
-
g_return_if_fail (IDE_IS_TASK (self));
- g_mutex_lock (&priv->mutex);
- priv->source_tag = source_tag;
- g_mutex_unlock (&priv->mutex);
+ g_mutex_lock (&self->mutex);
+ self->source_tag = source_tag;
+ g_mutex_unlock (&self->mutex);
}
/**
@@ -1447,22 +1392,18 @@ ide_task_set_source_tag (IdeTask *self,
* #GCancellable used when creating the #IdeTask is checked for cancellation
* before propagating a result. If cancelled, an error will be returned
* instead of the result.
- *
- * Since: 3.32
*/
void
ide_task_set_check_cancellable (IdeTask *self,
gboolean check_cancellable)
{
- IdeTaskPrivate *priv = ide_task_get_instance_private (self);
-
g_return_if_fail (IDE_IS_TASK (self));
check_cancellable = !!check_cancellable;
- g_mutex_lock (&priv->mutex);
- priv->check_cancellable = check_cancellable;
- g_mutex_unlock (&priv->mutex);
+ g_mutex_lock (&self->mutex);
+ self->check_cancellable = check_cancellable;
+ g_mutex_unlock (&self->mutex);
}
/**
@@ -1475,43 +1416,40 @@ ide_task_set_check_cancellable (IdeTask *self,
* @thread_func must complete the task from the worker thread using one of
* ide_task_return_boolean(), ide_task_return_int(), or
* ide_task_return_pointer().
- *
- * Since: 3.32
*/
void
ide_task_run_in_thread (IdeTask *self,
IdeTaskThreadFunc thread_func)
{
- IdeTaskPrivate *priv = ide_task_get_instance_private (self);
g_autoptr(GError) error = NULL;
g_return_if_fail (IDE_IS_TASK (self));
g_return_if_fail (thread_func != NULL);
- g_mutex_lock (&priv->mutex);
+ g_mutex_lock (&self->mutex);
- if (priv->completed == TRUE)
+ if (self->completed == TRUE)
{
g_critical ("Task already completed, cannot run in thread");
goto unlock;
}
- if (priv->thread_called)
+ if (self->thread_called)
{
g_critical ("Run in thread already called, cannot run again");
goto unlock;
}
- priv->thread_called = TRUE;
- priv->thread_func = thread_func;
+ self->thread_called = TRUE;
+ self->thread_func = thread_func;
- ide_thread_pool_push_with_priority ((IdeThreadPoolKind)priv->kind,
- priv->priority,
+ ide_thread_pool_push_with_priority ((IdeThreadPoolKind)self->kind,
+ self->priority,
ide_task_thread_func,
g_object_ref (self));
unlock:
- g_mutex_unlock (&priv->mutex);
+ g_mutex_unlock (&self->mutex);
if (error != NULL)
ide_task_return_error (self, g_steal_pointer (&error));
@@ -1522,72 +1460,71 @@ ide_task_propagate_locked (IdeTask *self,
IdeTaskResultType expected_type,
GError **error)
{
- IdeTaskPrivate *priv = ide_task_get_instance_private (self);
IdeTaskResult *ret = NULL;
g_assert (IDE_IS_TASK (self));
g_assert (expected_type > IDE_TASK_RESULT_NONE);
- if (priv->result == NULL)
+ if (self->result == NULL)
{
- g_autoptr(GMainContext) context = g_main_context_ref (priv->main_context);
+ g_autoptr(GMainContext) context = g_main_context_ref (self->main_context);
- while (priv->return_source)
+ while (self->return_source)
{
- g_mutex_unlock (&priv->mutex);
+ g_mutex_unlock (&self->mutex);
g_main_context_iteration (context, FALSE);
- g_mutex_lock (&priv->mutex);
+ g_mutex_lock (&self->mutex);
}
}
- if (priv->result == NULL)
+ if (self->result == NULL)
{
g_set_error_literal (error,
G_IO_ERROR,
G_IO_ERROR_FAILED,
"No result available for task");
}
- else if (priv->result->type == IDE_TASK_RESULT_ERROR)
+ else if (self->result->type == IDE_TASK_RESULT_ERROR)
{
if (error != NULL)
- *error = g_error_copy (priv->result->u.v_error);
+ *error = g_error_copy (self->result->u.v_error);
}
- else if ((priv->check_cancellable && g_cancellable_is_cancelled (priv->cancellable)) ||
- priv->result->type == IDE_TASK_RESULT_CANCELLED)
+ else if ((self->check_cancellable && g_cancellable_is_cancelled (self->cancellable)) ||
+ self->result->type == IDE_TASK_RESULT_CANCELLED)
{
g_set_error (error,
G_IO_ERROR,
G_IO_ERROR_CANCELLED,
"The operation was cancelled");
}
- else if (IDE_IS_OBJECT (priv->source_object) &&
- ide_object_in_destruction (IDE_OBJECT (priv->source_object)))
+ else if (IDE_IS_OBJECT (self->source_object) &&
+ ide_object_in_destruction (IDE_OBJECT (self->source_object)))
{
g_set_error (error,
G_IO_ERROR,
G_IO_ERROR_CANCELLED,
"The object was destroyed while the task executed");
}
- else if (priv->result->type != expected_type)
+ else if (self->result->type != expected_type)
{
g_set_error (error,
G_IO_ERROR,
G_IO_ERROR_FAILED,
"Task expected result of %s got %s",
result_type_name (expected_type),
- result_type_name (priv->result->type));
+ result_type_name (self->result->type));
}
else
{
- g_assert (priv->result != NULL);
- g_assert (priv->result->type == expected_type);
+ g_assert (self->result != NULL);
+ g_assert (self->result->type == expected_type);
- if (priv->release_on_propagate)
- ret = g_steal_pointer (&priv->result);
- else if (priv->result->type == IDE_TASK_RESULT_POINTER)
- ret = g_steal_pointer (&priv->result);
+ if (self->release_on_propagate)
+ ret = g_steal_pointer (&self->result);
+ else if (self->result->type == IDE_TASK_RESULT_POINTER)
+ ret = g_steal_pointer (&self->result);
else
- ret = ide_task_result_copy (priv->result);
+ ret = ide_task_result_copy (self->result);
g_assert (ret != NULL);
}
@@ -1599,13 +1536,12 @@ gboolean
ide_task_propagate_boolean (IdeTask *self,
GError **error)
{
- IdeTaskPrivate *priv = ide_task_get_instance_private (self);
g_autoptr(GMutexLocker) locker = NULL;
g_autoptr(IdeTaskResult) res = NULL;
g_return_val_if_fail (IDE_IS_TASK (self), FALSE);
- locker = g_mutex_locker_new (&priv->mutex);
+ locker = g_mutex_locker_new (&self->mutex);
if (!(res = ide_task_propagate_locked (self, IDE_TASK_RESULT_BOOLEAN, error)))
return FALSE;
@@ -1617,13 +1553,12 @@ gpointer
ide_task_propagate_boxed (IdeTask *self,
GError **error)
{
- IdeTaskPrivate *priv = ide_task_get_instance_private (self);
g_autoptr(GMutexLocker) locker = NULL;
g_autoptr(IdeTaskResult) res = NULL;
g_return_val_if_fail (IDE_IS_TASK (self), NULL);
- locker = g_mutex_locker_new (&priv->mutex);
+ locker = g_mutex_locker_new (&self->mutex);
if (!(res = ide_task_propagate_locked (self, IDE_TASK_RESULT_BOXED, error)))
return NULL;
@@ -1635,13 +1570,12 @@ gssize
ide_task_propagate_int (IdeTask *self,
GError **error)
{
- IdeTaskPrivate *priv = ide_task_get_instance_private (self);
g_autoptr(GMutexLocker) locker = NULL;
g_autoptr(IdeTaskResult) res = NULL;
g_return_val_if_fail (IDE_IS_TASK (self), 0);
- locker = g_mutex_locker_new (&priv->mutex);
+ locker = g_mutex_locker_new (&self->mutex);
if (!(res = ide_task_propagate_locked (self, IDE_TASK_RESULT_INT, error)))
return 0;
@@ -1661,20 +1595,17 @@ ide_task_propagate_int (IdeTask *self,
*
* Returns: (transfer full) (type GObject.Object): a #GObject or %NULL
* and @error may be set.
- *
- * Since: 3.32
*/
gpointer
ide_task_propagate_object (IdeTask *self,
GError **error)
{
- IdeTaskPrivate *priv = ide_task_get_instance_private (self);
g_autoptr(GMutexLocker) locker = NULL;
g_autoptr(IdeTaskResult) res = NULL;
g_return_val_if_fail (IDE_IS_TASK (self), NULL);
- locker = g_mutex_locker_new (&priv->mutex);
+ locker = g_mutex_locker_new (&self->mutex);
if (!(res = ide_task_propagate_locked (self, IDE_TASK_RESULT_OBJECT, error)))
return NULL;
@@ -1686,14 +1617,13 @@ gpointer
ide_task_propagate_pointer (IdeTask *self,
GError **error)
{
- IdeTaskPrivate *priv = ide_task_get_instance_private (self);
g_autoptr(GMutexLocker) locker = NULL;
g_autoptr(IdeTaskResult) res = NULL;
gpointer ret;
g_return_val_if_fail (IDE_IS_TASK (self), NULL);
- locker = g_mutex_locker_new (&priv->mutex);
+ locker = g_mutex_locker_new (&self->mutex);
if (!(res = ide_task_propagate_locked (self, IDE_TASK_RESULT_POINTER, error)))
return NULL;
@@ -1718,24 +1648,20 @@ ide_task_propagate_pointer (IdeTask *self,
* Users of this API must make sure one of two things is true. Either they
* have called ide_task_set_release_on_propagate() with @self and set
* release_on_propagate to %FALSE, or @self has not yet completed.
- *
- * Since: 3.32
*/
void
ide_task_chain (IdeTask *self,
IdeTask *other_task)
{
- IdeTaskPrivate *self_priv = ide_task_get_instance_private (self);
-
g_return_if_fail (IDE_IS_TASK (self));
g_return_if_fail (IDE_IS_TASK (other_task));
g_return_if_fail (self != other_task);
- g_mutex_lock (&self_priv->mutex);
+ g_mutex_lock (&self->mutex);
- if (self_priv->result)
+ if (self->result)
{
- IdeTaskResult *copy = ide_task_result_copy (self_priv->result);
+ IdeTaskResult *copy = ide_task_result_copy (self->result);
if (copy != NULL)
ide_task_deliver_result (other_task, g_steal_pointer (©));
@@ -1747,25 +1673,24 @@ ide_task_chain (IdeTask *self,
}
else
{
- if (self_priv->chained == NULL)
- self_priv->chained = g_ptr_array_new_with_free_func (g_object_unref);
- g_ptr_array_add (self_priv->chained, g_object_ref (other_task));
+ if (self->chained == NULL)
+ self->chained = g_ptr_array_new_with_free_func (g_object_unref);
+ g_ptr_array_add (self->chained, g_object_ref (other_task));
}
- g_mutex_unlock (&self_priv->mutex);
+ g_mutex_unlock (&self->mutex);
}
gpointer
ide_task_get_source_tag (IdeTask *self)
{
- IdeTaskPrivate *priv = ide_task_get_instance_private (self);
gpointer ret;
g_return_val_if_fail (IDE_IS_TASK (self), NULL);
- g_mutex_lock (&priv->mutex);
- ret = priv->source_tag;
- g_mutex_unlock (&priv->mutex);
+ g_mutex_lock (&self->mutex);
+ ret = self->source_tag;
+ g_mutex_unlock (&self->mutex);
return ret;
}
@@ -1773,14 +1698,13 @@ ide_task_get_source_tag (IdeTask *self)
IdeTaskKind
ide_task_get_kind (IdeTask *self)
{
- IdeTaskPrivate *priv = ide_task_get_instance_private (self);
IdeTaskKind kind;
g_return_val_if_fail (IDE_IS_TASK (self), 0);
- g_mutex_lock (&priv->mutex);
- kind = priv->kind;
- g_mutex_unlock (&priv->mutex);
+ g_mutex_lock (&self->mutex);
+ kind = self->kind;
+ g_mutex_unlock (&self->mutex);
return kind;
}
@@ -1789,15 +1713,13 @@ void
ide_task_set_kind (IdeTask *self,
IdeTaskKind kind)
{
- IdeTaskPrivate *priv = ide_task_get_instance_private (self);
-
g_return_if_fail (IDE_IS_TASK (self));
g_return_if_fail (kind >= IDE_TASK_KIND_DEFAULT);
g_return_if_fail (kind < IDE_TASK_KIND_LAST);
- g_mutex_lock (&priv->mutex);
- priv->kind = kind;
- g_mutex_unlock (&priv->mutex);
+ g_mutex_lock (&self->mutex);
+ self->kind = kind;
+ g_mutex_unlock (&self->mutex);
}
/**
@@ -1807,21 +1729,18 @@ ide_task_set_kind (IdeTask *self,
* Gets the task data previously set with ide_task_set_task_data().
*
* Returns: (transfer none): previously registered task data or %NULL
- *
- * Since: 3.32
*/
gpointer
ide_task_get_task_data (IdeTask *self)
{
- IdeTaskPrivate *priv = ide_task_get_instance_private (self);
gpointer task_data = NULL;
g_assert (IDE_IS_TASK (self));
- g_mutex_lock (&priv->mutex);
- if (priv->task_data)
- task_data = priv->task_data->data;
- g_mutex_unlock (&priv->mutex);
+ g_mutex_lock (&self->mutex);
+ if (self->task_data)
+ task_data = self->task_data->data;
+ g_mutex_unlock (&self->mutex);
return task_data;
}
@@ -1839,7 +1758,6 @@ void
gpointer task_data,
GDestroyNotify task_data_destroy)
{
- IdeTaskPrivate *priv = ide_task_get_instance_private (self);
g_autoptr(IdeTaskData) old_task_data = NULL;
g_autoptr(IdeTaskData) new_task_data = NULL;
@@ -1849,18 +1767,18 @@ void
new_task_data->data = task_data;
new_task_data->data_destroy = task_data_destroy;
- g_mutex_lock (&priv->mutex);
+ g_mutex_lock (&self->mutex);
- if (priv->return_called)
+ if (self->return_called)
{
g_critical ("Cannot set task data after returning value");
goto unlock;
}
- old_task_data = g_steal_pointer (&priv->task_data);
- priv->task_data = g_steal_pointer (&new_task_data);
+ old_task_data = g_steal_pointer (&self->task_data);
+ self->task_data = g_steal_pointer (&new_task_data);
- if (priv->thread_called && old_task_data)
+ if (self->thread_called && old_task_data)
{
GSource *source;
@@ -1870,13 +1788,13 @@ void
g_source_set_callback (source,
ide_task_set_task_data_cb,
NULL, NULL);
- g_source_set_priority (source, priv->priority);
- g_source_attach (source, priv->main_context);
+ g_source_set_priority (source, self->priority);
+ g_source_attach (source, self->main_context);
g_source_unref (source);
}
unlock:
- g_mutex_unlock (&priv->mutex);
+ g_mutex_unlock (&self->mutex);
}
static gboolean
@@ -1908,7 +1826,7 @@ ide_task_cancellable_cancelled_cb (GCancellable *cancellable,
/*
* This can be called synchronously from g_cancellable_connect(), which
- * could still be holding priv->mutex. So we need to queue the cancellation
+ * could still be holding self->mutex. So we need to queue the cancellation
* request back through the main context.
*/
@@ -1927,20 +1845,17 @@ ide_task_cancellable_cancelled_cb (GCancellable *cancellable,
*
* Gets the return_on_cancel value, which means the task will return
* immediately when the #GCancellable is cancelled.
- *
- * Since: 3.32
*/
gboolean
ide_task_get_return_on_cancel (IdeTask *self)
{
- IdeTaskPrivate *priv = ide_task_get_instance_private (self);
gboolean ret;
g_return_val_if_fail (IDE_IS_TASK (self), FALSE);
- g_mutex_lock (&priv->mutex);
- ret = priv->return_on_cancel;
- g_mutex_unlock (&priv->mutex);
+ g_mutex_lock (&self->mutex);
+ ret = self->return_on_cancel;
+ g_mutex_unlock (&self->mutex);
return ret;
}
@@ -1958,28 +1873,25 @@ ide_task_get_return_on_cancel (IdeTask *self)
* Setting this requires that the caller can ensure the configured #GMainContext
* will outlive the threaded worker so that task state can be freed in a delayed
* fashion.
- *
- * Since: 3.32
*/
void
ide_task_set_return_on_cancel (IdeTask *self,
gboolean return_on_cancel)
{
- IdeTaskPrivate *priv = ide_task_get_instance_private (self);
g_autoptr(GMutexLocker) locker = NULL;
g_return_if_fail (IDE_IS_TASK (self));
- locker = g_mutex_locker_new (&priv->mutex);
+ locker = g_mutex_locker_new (&self->mutex);
- if (priv->cancellable == NULL)
+ if (self->cancellable == NULL)
return;
return_on_cancel = !!return_on_cancel;
- if (priv->return_on_cancel != return_on_cancel)
+ if (self->return_on_cancel != return_on_cancel)
{
- priv->return_on_cancel = return_on_cancel;
+ self->return_on_cancel = return_on_cancel;
if (return_on_cancel)
{
@@ -1989,12 +1901,12 @@ ide_task_set_return_on_cancel (IdeTask *self,
* appropriate ide_task_return() API is called.
*/
cancel = g_slice_new0 (IdeTaskCancel);
- cancel->main_context = g_main_context_ref (priv->main_context);
+ cancel->main_context = g_main_context_ref (self->main_context);
cancel->task = g_object_ref (self);
- cancel->priority = priv->priority;
+ cancel->priority = self->priority;
- priv->cancel_handler =
- g_cancellable_connect (priv->cancellable,
+ self->cancel_handler =
+ g_cancellable_connect (self->cancellable,
G_CALLBACK (ide_task_cancellable_cancelled_cb),
g_steal_pointer (&cancel),
(GDestroyNotify)ide_task_cancel_free);
@@ -2002,10 +1914,10 @@ ide_task_set_return_on_cancel (IdeTask *self,
}
else
{
- if (priv->cancel_handler)
+ if (self->cancel_handler)
{
- g_cancellable_disconnect (priv->cancellable, priv->cancel_handler);
- priv->cancel_handler = 0;
+ g_cancellable_disconnect (self->cancellable, self->cancel_handler);
+ self->cancel_handler = 0;
}
}
}
@@ -2041,20 +1953,17 @@ ide_task_report_new_error (gpointer source_object,
* Gets the name assigned for the task.
*
* Returns: (nullable): a string or %NULL
- *
- * Since: 3.32
*/
const gchar *
ide_task_get_name (IdeTask *self)
{
- IdeTaskPrivate *priv = ide_task_get_instance_private (self);
const gchar *ret;
g_return_val_if_fail (IDE_IS_TASK (self), NULL);
- g_mutex_lock (&priv->mutex);
- ret = priv->name;
- g_mutex_unlock (&priv->mutex);
+ g_mutex_lock (&self->mutex);
+ ret = self->name;
+ g_mutex_unlock (&self->mutex);
return ret;
}
@@ -2074,22 +1983,18 @@ ide_task_get_name (IdeTask *self)
*
* If using #IdeTask from C, a default name is set using the source
* file name and line number.
- *
- * Since: 3.32
*/
void
ide_task_set_name (IdeTask *self,
const gchar *name)
{
- IdeTaskPrivate *priv = ide_task_get_instance_private (self);
-
g_return_if_fail (IDE_IS_TASK (self));
name = g_intern_string (name);
- g_mutex_lock (&priv->mutex);
- priv->name = name;
- g_mutex_unlock (&priv->mutex);
+ g_mutex_lock (&self->mutex);
+ self->name = name;
+ g_mutex_unlock (&self->mutex);
#ifdef ENABLE_TIME_CHART
g_message ("TASK-BEGIN: %s", name);
@@ -2103,21 +2008,18 @@ ide_task_set_name (IdeTask *self,
* Checks to see if the task had an error.
*
* Returns: %TRUE if an error has occurred
- *
- * Since: 3.32
*/
gboolean
ide_task_had_error (IdeTask *self)
{
- IdeTaskPrivate *priv = ide_task_get_instance_private (self);
gboolean ret;
g_return_val_if_fail (IDE_IS_TASK (self), FALSE);
- g_mutex_lock (&priv->mutex);
- ret = (priv->result != NULL && priv->result->type == IDE_TASK_RESULT_ERROR) ||
- (priv->thread_result != NULL && priv->thread_result->type == IDE_TASK_RESULT_ERROR);
- g_mutex_unlock (&priv->mutex);
+ g_mutex_lock (&self->mutex);
+ ret = (self->result != NULL && self->result->type == IDE_TASK_RESULT_ERROR) ||
+ (self->thread_result != NULL && self->thread_result->type == IDE_TASK_RESULT_ERROR);
+ g_mutex_unlock (&self->mutex);
return ret;
}
@@ -2126,22 +2028,20 @@ static gpointer
ide_task_get_user_data (GAsyncResult *result)
{
IdeTask *self = (IdeTask *)result;
- IdeTaskPrivate *priv = ide_task_get_instance_private (self);
g_assert (IDE_IS_TASK (self));
- return priv->user_data;
+ return self->user_data;
}
static GObject *
ide_task_get_source_object_full (GAsyncResult *result)
{
IdeTask *self = (IdeTask *)result;
- IdeTaskPrivate *priv = ide_task_get_instance_private (self);
g_assert (IDE_IS_TASK (self));
- return priv->source_object ? g_object_ref (priv->source_object) : NULL;
+ return self->source_object ? g_object_ref (self->source_object) : NULL;
}
static gboolean
@@ -2149,11 +2049,10 @@ ide_task_is_tagged (GAsyncResult *result,
gpointer source_tag)
{
IdeTask *self = (IdeTask *)result;
- IdeTaskPrivate *priv = ide_task_get_instance_private (self);
g_assert (IDE_IS_TASK (self));
- return source_tag == priv->source_tag;
+ return source_tag == self->source_tag;
}
static void
@@ -2174,10 +2073,9 @@ _ide_dump_tasks (void)
for (const GList *iter = global_task_list.head; iter; iter = iter->next)
{
IdeTask *self = iter->data;
- IdeTaskPrivate *priv = ide_task_get_instance_private (self);
- g_printerr ("[%02d]: %s %s\n", i++, priv->name,
- priv->completed ? "completed" : "");
+ g_printerr ("[%02d]: %s %s\n", i++, self->name,
+ self->completed ? "completed" : "");
}
G_UNLOCK (global_task_list);
diff --git a/src/libide/threading/ide-task.h b/src/libide/threading/ide-task.h
index 882ad883b..d534636cb 100644
--- a/src/libide/threading/ide-task.h
+++ b/src/libide/threading/ide-task.h
@@ -29,8 +29,8 @@ G_BEGIN_DECLS
#define IDE_TYPE_TASK (ide_task_get_type())
-IDE_AVAILABLE_IN_3_32
-G_DECLARE_DERIVABLE_TYPE (IdeTask, ide_task, IDE, TASK, GObject)
+IDE_AVAILABLE_IN_ALL
+G_DECLARE_FINAL_TYPE (IdeTask, ide_task, IDE, TASK, GObject)
typedef void (*IdeTaskThreadFunc) (IdeTask *task,
gpointer source_object,
@@ -46,121 +46,114 @@ typedef enum
IDE_TASK_KIND_LAST
} IdeTaskKind;
-struct _IdeTaskClass
-{
- GObjectClass parent;
-
- gpointer _reserved[16];
-};
-
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
IdeTask *ide_task_new (gpointer source_object,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
void ide_task_chain (IdeTask *self,
IdeTask *other_task);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
GCancellable *ide_task_get_cancellable (IdeTask *self);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
gboolean ide_task_get_completed (IdeTask *self);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
IdeTaskKind ide_task_get_kind (IdeTask *self);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
const gchar *ide_task_get_name (IdeTask *self);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
gint ide_task_get_priority (IdeTask *self);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
gint ide_task_get_complete_priority (IdeTask *self);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
gpointer ide_task_get_source_object (IdeTask *self);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
gpointer ide_task_get_source_tag (IdeTask *self);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
gpointer ide_task_get_task_data (IdeTask *self);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
gboolean ide_task_had_error (IdeTask *self);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
gboolean ide_task_is_valid (gpointer self,
gpointer source_object);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
gboolean ide_task_propagate_boolean (IdeTask *self,
GError **error);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
gpointer ide_task_propagate_boxed (IdeTask *self,
GError **error);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
gssize ide_task_propagate_int (IdeTask *self,
GError **error);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
gpointer ide_task_propagate_object (IdeTask *self,
GError **error);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
gpointer ide_task_propagate_pointer (IdeTask *self,
GError **error);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
void ide_task_return_boolean (IdeTask *self,
gboolean result);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
void ide_task_return_boxed (IdeTask *self,
GType result_type,
gpointer result);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
void ide_task_return_error (IdeTask *self,
GError *error);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
gboolean ide_task_return_error_if_cancelled (IdeTask *self);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
void ide_task_return_int (IdeTask *self,
gssize result);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
gboolean ide_task_get_return_on_cancel (IdeTask *self);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
void ide_task_return_new_error (IdeTask *self,
GQuark error_domain,
gint error_code,
const gchar *format,
...) G_GNUC_PRINTF (4, 5);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
void ide_task_return_object (IdeTask *self,
gpointer instance);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
void ide_task_return_pointer (IdeTask *self,
gpointer data,
GDestroyNotify destroy);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
void ide_task_run_in_thread (IdeTask *self,
IdeTaskThreadFunc thread_func);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
void ide_task_set_check_cancellable (IdeTask *self,
gboolean check_cancellable);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
void ide_task_set_kind (IdeTask *self,
IdeTaskKind kind);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
void ide_task_set_name (IdeTask *self,
const gchar *name);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
void ide_task_set_priority (IdeTask *self,
gint priority);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
void ide_task_set_complete_priority (IdeTask *self,
gint complete_priority);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
void ide_task_set_release_on_propagate (IdeTask *self,
gboolean release_on_propagate);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
void ide_task_set_return_on_cancel (IdeTask *self,
gboolean return_on_cancel);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
void ide_task_set_source_tag (IdeTask *self,
gpointer source_tag);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
void ide_task_set_task_data (IdeTask *self,
gpointer task_data,
GDestroyNotify task_data_destroy);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
void ide_task_report_new_error (gpointer source_object,
GAsyncReadyCallback callback,
gpointer callback_data,
@@ -170,6 +163,17 @@ void ide_task_report_new_error (gpointer source_o
const gchar *format,
...) G_GNUC_PRINTF (7, 8);
+static inline void
+ide_task_return_unsupported_error (IdeTask *task)
+{
+ g_assert (IDE_IS_TASK (task));
+
+ ide_task_return_error (task,
+ g_error_new_literal (G_IO_ERROR,
+ G_IO_ERROR_NOT_SUPPORTED,
+ "Not Supported"));
+}
+
#ifdef __GNUC__
# define ide_task_new(self, cancellable, callback, user_data) \
({ \
diff --git a/src/libide/threading/ide-thread-pool.c b/src/libide/threading/ide-thread-pool.c
index d21579b9d..54a380743 100644
--- a/src/libide/threading/ide-thread-pool.c
+++ b/src/libide/threading/ide-thread-pool.c
@@ -83,8 +83,6 @@ ide_thread_pool_get_pool (IdeThreadPoolKind kind)
*
* This pushes a task to be executed on a worker thread based on the task kind as denoted by
* @kind. Some tasks will be placed on special work queues or throttled based on priority.
- *
- * Since: 3.32
*/
void
ide_thread_pool_push_task (IdeThreadPoolKind kind,
@@ -129,8 +127,6 @@ ide_thread_pool_push_task (IdeThreadPoolKind kind,
* @func_data: user data for @func.
*
* Runs the callback on the thread pool thread.
- *
- * Since: 3.32
*/
void
ide_thread_pool_push (IdeThreadPoolKind kind,
@@ -148,8 +144,6 @@ ide_thread_pool_push (IdeThreadPoolKind kind,
* @func_data: user data for @func.
*
* Runs the callback on the thread pool thread.
- *
- * Since: 3.32
*/
void
ide_thread_pool_push_with_priority (IdeThreadPoolKind kind,
diff --git a/src/libide/threading/ide-thread-pool.h b/src/libide/threading/ide-thread-pool.h
index fa90da479..87f607e79 100644
--- a/src/libide/threading/ide-thread-pool.h
+++ b/src/libide/threading/ide-thread-pool.h
@@ -45,20 +45,19 @@ typedef enum
* @user_data: (closure) (transfer full): The closure for the callback.
*
*
- * Since: 3.32
*/
typedef void (*IdeThreadFunc) (gpointer user_data);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
void ide_thread_pool_push (IdeThreadPoolKind kind,
IdeThreadFunc func,
gpointer func_data);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
void ide_thread_pool_push_with_priority (IdeThreadPoolKind kind,
gint priority,
IdeThreadFunc func,
gpointer func_data);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
void ide_thread_pool_push_task (IdeThreadPoolKind kind,
GTask *task,
GTaskThreadFunc func);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]