gio: port GAsyncInitable from GSimpleAsyncResult to GTask

https://bugzilla.gnome.org/show_bug.cgi?id=661767
This commit is contained in:
Dan Winship 2012-08-02 15:51:37 -04:00
parent 55e7ca6e1b
commit 130d0fdac0

View File

@ -24,6 +24,7 @@
#include "gasyncinitable.h" #include "gasyncinitable.h"
#include "gasyncresult.h" #include "gasyncresult.h"
#include "gsimpleasyncresult.h" #include "gsimpleasyncresult.h"
#include "gtask.h"
#include "glibintl.h" #include "glibintl.h"
@ -249,14 +250,17 @@ g_async_initable_init_finish (GAsyncInitable *initable,
} }
static void static void
async_init_thread (GSimpleAsyncResult *res, async_init_thread (GTask *task,
GObject *object, gpointer source_object,
gpointer task_data,
GCancellable *cancellable) GCancellable *cancellable)
{ {
GError *error = NULL; GError *error = NULL;
if (!g_initable_init (G_INITABLE (object), cancellable, &error)) if (g_initable_init (G_INITABLE (source_object), cancellable, &error))
g_simple_async_result_take_error (res, error); g_task_return_boolean (task, TRUE);
else
g_task_return_error (task, error);
} }
static void static void
@ -266,15 +270,14 @@ g_async_initable_real_init_async (GAsyncInitable *initable,
GAsyncReadyCallback callback, GAsyncReadyCallback callback,
gpointer user_data) gpointer user_data)
{ {
GSimpleAsyncResult *res; GTask *task;
g_return_if_fail (G_IS_INITABLE (initable)); g_return_if_fail (G_IS_INITABLE (initable));
res = g_simple_async_result_new (G_OBJECT (initable), callback, user_data, task = g_task_new (initable, cancellable, callback, user_data);
g_async_initable_real_init_async); g_task_set_priority (task, io_priority);
g_simple_async_result_run_in_thread (res, async_init_thread, g_task_run_in_thread (task, async_init_thread);
io_priority, cancellable); g_object_unref (task);
g_object_unref (res);
} }
static gboolean static gboolean
@ -283,16 +286,21 @@ g_async_initable_real_init_finish (GAsyncInitable *initable,
GError **error) GError **error)
{ {
/* For backward compatibility we have to process GSimpleAsyncResults /* For backward compatibility we have to process GSimpleAsyncResults
* even if they aren't tagged from g_async_initable_real_init_async. * even though g_async_initable_real_init_async doesn't generate
* them any more.
*/ */
if (G_IS_SIMPLE_ASYNC_RESULT (res)) if (G_IS_SIMPLE_ASYNC_RESULT (res))
{ {
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res); GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
if (g_simple_async_result_propagate_error (simple, error)) if (g_simple_async_result_propagate_error (simple, error))
return FALSE; return FALSE;
else
return TRUE;
} }
return TRUE; g_return_val_if_fail (g_task_is_valid (res, initable), FALSE);
return g_task_propagate_boolean (G_TASK (res), error);
} }
/** /**