[gcr: 1/4] gck-call: Simplify the code by using GTask based implementation




commit ed23f8b97128fbd26faec1bff3da35d64afa305b
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date:   Mon Nov 16 16:56:14 2020 +0100

    gck-call: Simplify the code by using GTask based implementation
    
    GckCall uses its own implementation of threads pool to handle the async
    calls, now that we've GTask this code can be simplified by reusing
    GLib code.
    
    I didn't want to change the API in this commit, even if private not to
    mix changes together, so the functions still are used as they used to be
    
    The main difference is that the async_pre and async_ready prepare a
    GTask instance, while the async_go starts a thread using the gtask
    function.
    
    Callback functions needed to be adapted to the new GAsyncResult type.
    
    Tests needed also some tuning as the underneath task holding a reference
    to the source object might be finalized at later stage, when the
    thread-related data is removed, as per this we may wait a bit to check
    whether a source object gets finalized, this is due to GNOME/GLib#1346.

 gck/gck-call.c            | 326 +++++++++-------------------------------------
 gck/gck-enumerator.c      |   2 +-
 gck/gck-module.c          |   2 +-
 gck/gck-modules.c         |   2 +-
 gck/gck-object.c          |  22 ++--
 gck/gck-private.h         |  15 +--
 gck/gck-session.c         |  16 +--
 gck/test-gck-crypto.c     |   4 +
 gck/test-gck-enumerator.c |   3 +-
 gck/test-gck-module.c     |   1 +
 gck/test-gck-session.c    |   3 +
 gcr/test-gnupg-key.c      |   1 +
 12 files changed, 97 insertions(+), 300 deletions(-)
---
diff --git a/gck/gck-call.c b/gck/gck-call.c
index 8e1a276..9efce0e 100644
--- a/gck/gck-call.c
+++ b/gck/gck-call.c
@@ -2,6 +2,7 @@
 /* gck-call.c - the GObject PKCS#11 wrapper library
 
    Copyright (C) 2008, Stefan Walter
+   Copyright (C) 2020, Marco Trevisan
 
    The Gnome Keyring Library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public License as
@@ -26,39 +27,19 @@
 
 #include <string.h>
 
-typedef struct _GckCallSource GckCallSource;
-
-static gpointer _gck_call_parent_class = NULL;
-
 struct _GckCall {
        GObject parent;
+       GTask *task;
        GckModule *module;
 
        /* For making the call */
        GckPerformFunc perform;
        GckCompleteFunc complete;
        GckArguments *args;
-       GCancellable *cancellable;
        GDestroyNotify destroy;
-       CK_RV rv;
-
-       /* For result callback only */
-       gpointer object;
-       GAsyncReadyCallback callback;
-       gpointer user_data;
 };
 
-struct _GckCallClass {
-       GObjectClass parent;
-       GThreadPool *thread_pool;
-       GAsyncQueue *completed_queue;
-       guint completed_id;
-};
-
-struct _GckCallSource {
-       GSource source;
-       GckCallClass *klass;
-};
+G_DEFINE_TYPE (GckCall, _gck_call, G_TYPE_OBJECT)
 
 /* ----------------------------------------------------------------------------
  * HELPER FUNCTIONS
@@ -106,111 +87,54 @@ complete_call (GckCompleteFunc func, GckArguments *args, CK_RV result)
        return (func) (args, result);
 }
 
-
-static void
-process_async_call (gpointer data, GckCallClass *klass)
+static CK_RV
+perform_call_chain (GckPerformFunc perform, GckCompleteFunc complete,
+                   GCancellable *cancellable, GckArguments *args)
 {
-       GckCall *call = GCK_CALL (data);
-
-       g_assert (GCK_IS_CALL (call));
-
-       call->rv = perform_call (call->perform, call->cancellable, call->args);
+       CK_RV rv;
 
-       g_async_queue_push (klass->completed_queue, call);
+       do {
+               rv = perform_call (perform, cancellable, args);
+               if (rv == CKR_FUNCTION_CANCELED)
+                       break;
+       } while (!complete_call (complete, args, rv));
 
-       /* Wakeup main thread if on a separate thread */
-       g_main_context_wakeup (NULL);
+       return rv;
 }
 
-static void
-process_result (GckCall *call, gpointer unused)
-{
-       gboolean stop = FALSE;
-
-       /* Double check a few things */
-       g_assert (GCK_IS_CALL (call));
-
-       if (call->cancellable) {
-               /* Don't call the callback when cancelled */
-               if (g_cancellable_is_cancelled (call->cancellable)) {
-                       call->rv = CKR_FUNCTION_CANCELED;
-                       stop = TRUE;
-               }
-       }
 
-       /*
-        * Hmmm, does the function want to actually be done?
-        * If not, then queue this call again.
-        */
-       if (!stop && !complete_call (call->complete, call->args, call->rv)) {
-               g_object_ref (call);
-               g_thread_pool_push (GCK_CALL_GET_CLASS (call)->thread_pool, call, NULL);
-
-       /* All done, finish processing */
-       } else if (call->callback) {
-               (call->callback) (call->object, G_ASYNC_RESULT (call),
-                                 call->user_data);
-       }
-}
-
-static gboolean
-process_completed (GckCallClass *klass)
+static void
+_gck_task_return (GTask *task, CK_RV rv)
 {
-       gpointer call;
-
-       g_assert (klass->completed_queue);
-
-       call = g_async_queue_try_pop (klass->completed_queue);
-       if (call) {
-               process_result (call, NULL);
-               g_object_unref (call);
-               return TRUE;
+       if (rv == CKR_OK) {
+               g_task_return_boolean (task, TRUE);
+       } else if (rv == CKR_FUNCTION_CANCELED) {
+               g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_CANCELLED,
+                                        "Gck function call cancelled");
+       } else {
+               g_task_return_new_error (task, GCK_ERROR, rv, "%s",
+                                        gck_message_from_rv (rv));
        }
-
-       return FALSE;
-}
-
-static gboolean
-completed_prepare(GSource* base, gint *timeout)
-{
-       GckCallSource *source = (GckCallSource*)base;
-       gboolean have;
-
-       g_assert (source->klass->completed_queue);
-       have = g_async_queue_length (source->klass->completed_queue) > 0;
-       *timeout = have ? 0 : -1;
-       return have;
 }
 
-static gboolean
-completed_check(GSource* base)
+static void
+_gck_call_thread_func (GTask        *task,
+                      gpointer      source_object,
+                      gpointer      task_data,
+                      GCancellable *cancellable)
 {
-       GckCallSource *source = (GckCallSource*)base;
-       g_assert (source->klass->completed_queue);
-       return g_async_queue_length (source->klass->completed_queue) > 0;
-}
+       GckCall *call = task_data;
+       CK_RV rv;
 
-static gboolean
-completed_dispatch(GSource* base, GSourceFunc callback, gpointer user_data)
-{
-       GckCallSource *source = (GckCallSource*)base;
-       process_completed (source->klass);
-       return TRUE;
-}
+       /* Double check a few things */
+       g_assert (GCK_IS_CALL (call));
 
-static void
-completed_finalize(GSource* base)
-{
+       rv = perform_call_chain (call->perform, call->complete, cancellable,
+                                call->args);
 
+       _gck_task_return (task, rv);
 }
 
-static GSourceFuncs completed_functions = {
-       completed_prepare,
-       completed_check,
-       completed_dispatch,
-       completed_finalize
-};
-
 /* ----------------------------------------------------------------------------
  * OBJECT
  */
@@ -218,7 +142,6 @@ static GSourceFuncs completed_functions = {
 static void
 _gck_call_init (GckCall *call)
 {
-       call->rv = CKR_OK;
 }
 
 static void
@@ -230,13 +153,8 @@ _gck_call_finalize (GObject *obj)
                g_object_unref (call->module);
        call->module = NULL;
 
-       if (call->object)
-               g_object_unref (call->object);
-       call->object = NULL;
-
-       if (call->cancellable)
-               g_object_unref (call->cancellable);
-       call->cancellable = NULL;
+       g_clear_object (&call->task);
+       g_clear_object (&call->args->call);
 
        if (call->destroy)
                (call->destroy) (call->args);
@@ -246,129 +164,14 @@ _gck_call_finalize (GObject *obj)
        G_OBJECT_CLASS (_gck_call_parent_class)->finalize (obj);
 }
 
-static gpointer
-_gck_call_get_user_data (GAsyncResult *async_result)
-{
-       g_return_val_if_fail (GCK_IS_CALL (async_result), NULL);
-       return GCK_CALL (async_result)->user_data;
-}
-
-static GObject*
-_gck_call_get_source_object (GAsyncResult *async_result)
-{
-       GObject *source;
-
-       g_return_val_if_fail (GCK_IS_CALL (async_result), NULL);
-
-       source = GCK_CALL (async_result)->object;
-       return source ? g_object_ref (source): NULL;
-}
-
-static void
-_gck_call_implement_async_result (GAsyncResultIface *iface)
-{
-       iface->get_user_data = _gck_call_get_user_data;
-       iface->get_source_object = _gck_call_get_source_object;
-}
-
 static void
 _gck_call_class_init (GckCallClass *klass)
 {
        GObjectClass *gobject_class = (GObjectClass*)klass;
 
-       _gck_call_parent_class = g_type_class_peek_parent (klass);
        gobject_class->finalize = _gck_call_finalize;
 }
 
-static void
-_gck_call_base_init (GckCallClass *klass)
-{
-       GckCallSource *source;
-       GMainContext *context;
-       GError *err = NULL;
-
-       klass->thread_pool = g_thread_pool_new ((GFunc)process_async_call, klass, 16, FALSE, &err);
-       if (!klass->thread_pool) {
-               g_critical ("couldn't create thread pool: %s",
-                           err && err->message ? err->message : "");
-               return;
-       }
-
-       klass->completed_queue = g_async_queue_new_full (g_object_unref);
-       g_assert (klass->completed_queue);
-
-       context = g_main_context_default ();
-       g_assert (context);
-
-       /* Add our idle handler which processes other tasks */
-       source = (GckCallSource*)g_source_new (&completed_functions, sizeof (GckCallSource));
-       source->klass = klass;
-       klass->completed_id = g_source_attach ((GSource*)source, context);
-       g_source_set_callback ((GSource*)source, NULL, NULL, NULL);
-       g_source_unref ((GSource*)source);
-}
-
-static void
-_gck_call_base_finalize (GckCallClass *klass)
-{
-       GMainContext *context;
-       GSource *src;
-
-       if (klass->thread_pool) {
-               g_assert (g_thread_pool_unprocessed (klass->thread_pool) == 0);
-               g_thread_pool_free (klass->thread_pool, FALSE, TRUE);
-               klass->thread_pool = NULL;
-       }
-
-       if (klass->completed_id) {
-               context = g_main_context_default ();
-               g_return_if_fail (context);
-
-               src = g_main_context_find_source_by_id (context, klass->completed_id);
-               g_assert (src);
-               g_source_destroy (src);
-               klass->completed_id = 0;
-       }
-
-       if (klass->completed_queue) {
-               g_assert (g_async_queue_length (klass->completed_queue));
-               g_async_queue_unref (klass->completed_queue);
-               klass->completed_queue = NULL;
-       }
-}
-
-GType
-_gck_call_get_type (void)
-{
-       static volatile gsize type_id__volatile = 0;
-
-       if (g_once_init_enter (&type_id__volatile)) {
-
-               static const GTypeInfo type_info = {
-                       sizeof (GckCallClass),
-                       (GBaseInitFunc)_gck_call_base_init,
-                       (GBaseFinalizeFunc)_gck_call_base_finalize,
-                       (GClassInitFunc)_gck_call_class_init,
-                       (GClassFinalizeFunc)NULL,
-                       NULL,   // class_data
-                       sizeof (GckCall),
-                       0,      // n_preallocs
-                       (GInstanceInitFunc)_gck_call_init,
-               };
-
-               static const GInterfaceInfo interface_info = {
-                       (GInterfaceInitFunc)_gck_call_implement_async_result
-               };
-
-               GType type_id = g_type_register_static (G_TYPE_OBJECT, "_GckCall", &type_info, 0);
-               g_type_add_interface_static (type_id, G_TYPE_ASYNC_RESULT, &interface_info);
-
-               g_once_init_leave (&type_id__volatile, type_id);
-       }
-
-       return type_id__volatile;
-}
-
 /* ----------------------------------------------------------------------------
  * PUBLIC
  */
@@ -400,12 +203,7 @@ _gck_call_sync (gpointer object, gpointer perform, gpointer complete,
                g_assert (args->pkcs11);
        }
 
-       do {
-               rv = perform_call (perform, cancellable, args);
-               if (rv == CKR_FUNCTION_CANCELED)
-                       break;
-
-       } while (!complete_call (complete, args, rv));
+       rv = perform_call_chain (perform, complete, cancellable, args);
 
        if (module)
                g_object_unref (module);
@@ -437,10 +235,10 @@ _gck_call_async_prep (gpointer object, gpointer cb_object, gpointer perform,
 
        args = g_malloc0 (args_size);
        call = g_object_new (GCK_TYPE_CALL, NULL);
+       call->task = g_task_new (cb_object, NULL, NULL, NULL);
        call->destroy = (GDestroyNotify)destroy;
        call->perform = (GckPerformFunc)perform;
        call->complete = (GckCompleteFunc)complete;
-       call->object = cb_object ? g_object_ref (cb_object) : NULL;
 
        /* Hook the two together */
        call->args = args;
@@ -475,30 +273,32 @@ _gck_call_async_ready (gpointer data, GCancellable *cancellable,
                         GAsyncReadyCallback callback, gpointer user_data)
 {
        GckArguments *args = (GckArguments*)data;
+       GckCall* call;
+       GTask* task;
+
        g_assert (GCK_IS_CALL (args->call));
+       g_assert (G_IS_TASK (args->call->task));
 
-       args->call->cancellable = cancellable;
-       if (cancellable) {
-               g_assert (G_IS_CANCELLABLE (cancellable));
-               g_object_ref (cancellable);
-       }
+       /* XXX: Maybe move the callback object parameter to this function */
+       call = g_steal_pointer (&args->call);
+       task = g_task_new (g_task_get_source_object (call->task),
+                          cancellable, callback, user_data);
+       g_task_set_task_data (task, call, g_object_unref);
+       g_set_object (&call->task, task);
 
-       args->call->callback = callback;
-       args->call->user_data = user_data;
+       g_object_unref (task);
 
-       return args->call;
+       return call;
 }
 
 void
 _gck_call_async_go (GckCall *call)
 {
        g_assert (GCK_IS_CALL (call));
+       g_assert (G_IS_TASK (call->task));
 
-       /* To keep things balanced, process at one completed event */
-       process_completed(GCK_CALL_GET_CLASS (call));
-
-       g_assert (GCK_CALL_GET_CLASS (call)->thread_pool);
-       g_thread_pool_push (GCK_CALL_GET_CLASS (call)->thread_pool, call, NULL);
+       g_task_run_in_thread (call->task, _gck_call_thread_func);
+       g_clear_object (&call->task);
 }
 
 void
@@ -512,16 +312,9 @@ _gck_call_async_ready_go (gpointer data, GCancellable *cancellable,
 gboolean
 _gck_call_basic_finish (GAsyncResult *result, GError **err)
 {
-       CK_RV rv;
-
-       g_return_val_if_fail (GCK_IS_CALL (result), FALSE);
+       g_return_val_if_fail (G_IS_TASK (result), FALSE);
 
-       rv = GCK_CALL (result)->rv;
-       if (rv == CKR_OK)
-               return TRUE;
-
-       g_set_error (err, GCK_ERROR, rv, "%s", gck_message_from_rv (rv));
-       return FALSE;
+       return g_task_propagate_boolean (G_TASK (result), err);
 }
 
 void
@@ -529,11 +322,10 @@ _gck_call_async_short (GckCall *call, CK_RV rv)
 {
        g_assert (GCK_IS_CALL (call));
 
-       call->rv = rv;
-
        /* Already complete, so just push it for processing in main loop */
-       g_assert (GCK_CALL_GET_CLASS (call)->completed_queue);
-       g_async_queue_push (GCK_CALL_GET_CLASS (call)->completed_queue, call);
+       _gck_task_return (call->task, rv);
+       g_clear_object (&call->task);
+
        g_main_context_wakeup (NULL);
 }
 
diff --git a/gck/gck-enumerator.c b/gck/gck-enumerator.c
index 20ef4d9..87a8176 100644
--- a/gck/gck-enumerator.c
+++ b/gck/gck-enumerator.c
@@ -1339,7 +1339,7 @@ gck_enumerator_next_finish (GckEnumerator *self, GAsyncResult *result, GError **
 
        g_object_ref (self);
 
-       args = _gck_call_arguments (result, EnumerateNext);
+       args = _gck_call_async_result_arguments (result, EnumerateNext);
        state = args->state;
        args->state = NULL;
        want_objects = args->want_objects;
diff --git a/gck/gck-module.c b/gck/gck-module.c
index 5dc4ef9..509c4c2 100644
--- a/gck/gck-module.c
+++ b/gck/gck-module.c
@@ -443,7 +443,7 @@ gck_module_initialize_finish (GAsyncResult *result,
        GckModule *module = NULL;
        Initialize *args;
 
-       args = _gck_call_arguments (result, Initialize);
+       args = _gck_call_async_result_arguments (result, Initialize);
        if (_gck_call_basic_finish (result, error)) {
                module = args->result;
                args->result = NULL;
diff --git a/gck/gck-modules.c b/gck/gck-modules.c
index 766da57..2331423 100644
--- a/gck/gck-modules.c
+++ b/gck/gck-modules.c
@@ -147,7 +147,7 @@ gck_modules_initialize_registered_finish (GAsyncResult *result,
        GList *modules = NULL;
        InitializeRegistered *args;
 
-       args = _gck_call_arguments (result, InitializeRegistered);
+       args = _gck_call_async_result_arguments (result, InitializeRegistered);
        if (_gck_call_basic_finish (result, error)) {
                modules = args->results;
                args->results = NULL;
diff --git a/gck/gck-object.c b/gck/gck-object.c
index 2ce73d4..084a74f 100644
--- a/gck/gck-object.c
+++ b/gck/gck-object.c
@@ -464,7 +464,7 @@ gboolean
 gck_object_destroy_finish (GckObject *self, GAsyncResult *result, GError **error)
 {
        g_return_val_if_fail (GCK_IS_OBJECT (self), FALSE);
-       g_return_val_if_fail (GCK_IS_CALL (result), FALSE);
+       g_return_val_if_fail (G_IS_TASK (result), FALSE);
        return _gck_call_basic_finish (result, error);
 }
 
@@ -584,11 +584,11 @@ gck_object_set_finish (GckObject *self, GAsyncResult *result, GError **error)
        SetAttributes *args;
 
        g_return_val_if_fail (GCK_IS_OBJECT (self), FALSE);
-       g_return_val_if_fail (GCK_IS_CALL (result), FALSE);
+       g_return_val_if_fail (G_IS_TASK (result), FALSE);
        g_return_val_if_fail (!error || !*error, FALSE);
 
        /* Unlock the attributes we were using */
-       args = _gck_call_arguments (result, SetAttributes);
+       args = _gck_call_async_result_arguments (result, SetAttributes);
        g_assert (args->attrs);
 
        return _gck_call_basic_finish (result, error);
@@ -795,10 +795,10 @@ gck_object_get_finish (GckObject *self, GAsyncResult *result, GError **error)
        GetAttributes *args;
 
        g_return_val_if_fail (GCK_IS_OBJECT (self), NULL);
-       g_return_val_if_fail (GCK_IS_CALL (result), NULL);
+       g_return_val_if_fail (G_IS_TASK (result), NULL);
        g_return_val_if_fail (!error || !*error, NULL);
 
-       args = _gck_call_arguments (result, GetAttributes);
+       args = _gck_call_async_result_arguments (result, GetAttributes);
 
        if (!_gck_call_basic_finish (result, error))
                return NULL;
@@ -1001,14 +1001,14 @@ gck_object_get_data_finish (GckObject *self,
        guchar *data;
 
        g_return_val_if_fail (GCK_IS_OBJECT (self), NULL);
-       g_return_val_if_fail (GCK_IS_CALL (result), NULL);
+       g_return_val_if_fail (G_IS_TASK (result), NULL);
        g_return_val_if_fail (n_data, NULL);
        g_return_val_if_fail (!error || !*error, NULL);
 
        if (!_gck_call_basic_finish (result, error))
                return NULL;
 
-       args = _gck_call_arguments (result, GetAttributeData);
+       args = _gck_call_async_result_arguments (result, GetAttributeData);
 
        *n_data = args->n_result;
        data = args->result;
@@ -1146,11 +1146,11 @@ gck_object_set_template_finish (GckObject *self, GAsyncResult *result, GError **
        set_template_args *args;
 
        g_return_val_if_fail (GCK_IS_OBJECT (self), FALSE);
-       g_return_val_if_fail (GCK_IS_CALL (result), FALSE);
+       g_return_val_if_fail (G_IS_TASK (result), FALSE);
        g_return_val_if_fail (!error || !*error, FALSE);
 
        /* Unlock the attributes we were using */
-       args = _gck_call_arguments (result, set_template_args);
+       args = _gck_call_async_result_arguments (result, set_template_args);
        g_assert (args->attrs);
 
        return _gck_call_basic_finish (result, error);
@@ -1304,12 +1304,12 @@ gck_object_get_template_finish (GckObject *self, GAsyncResult *result,
        get_template_args *args;
 
        g_return_val_if_fail (GCK_IS_OBJECT (self), NULL);
-       g_return_val_if_fail (GCK_IS_CALL (result), NULL);
+       g_return_val_if_fail (G_IS_TASK (result), NULL);
        g_return_val_if_fail (!error || !*error, NULL);
 
        if (!_gck_call_basic_finish (result, error))
                return NULL;
 
-       args = _gck_call_arguments (result, get_template_args);
+       args = _gck_call_async_result_arguments (result, get_template_args);
        return gck_attributes_ref_sink (gck_builder_end (&args->builder));
 }
diff --git a/gck/gck-private.h b/gck/gck-private.h
index dc4c44b..46a9d11 100644
--- a/gck/gck-private.h
+++ b/gck/gck-private.h
@@ -157,18 +157,15 @@ typedef struct _GckArguments {
 
 #define GCK_ARGUMENTS_INIT        { NULL, NULL, 0 }
 
-#define GCK_TYPE_CALL             (_gck_call_get_type())
-#define GCK_CALL(obj)             (G_TYPE_CHECK_INSTANCE_CAST((obj), GCK_TYPE_CALL, GckCall))
-#define GCK_CALL_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST((klass), GCK_TYPE_CALL, GckCall))
-#define GCK_IS_CALL(obj)          (G_TYPE_CHECK_INSTANCE_TYPE((obj), GCK_TYPE_CALL))
-#define GCK_IS_CALL_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE((klass), GCK_TYPE_CALL))
-#define GCK_CALL_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS((obj), GCK_TYPE_CALL, GckCallClass))
+G_DECLARE_FINAL_TYPE (GckCall, _gck_call, GCK, CALL, GObject)
 
-typedef struct _GckCallClass GckCallClass;
+#define GCK_TYPE_CALL             (_gck_call_get_type())
 
-GType              _gck_call_get_type                    (void) G_GNUC_CONST;
+#define            _gck_call_arguments(call, type) (type*) \
+   (_gck_call_get_arguments (GCK_CALL (call)))
 
-#define            _gck_call_arguments(call, type)       (type*)(_gck_call_get_arguments (GCK_CALL (call)))
+#define            _gck_call_async_result_arguments(task, type) \
+   (type*)(_gck_call_get_arguments (g_task_get_task_data (G_TASK (task))))
 
 gpointer           _gck_call_get_arguments               (GckCall *call);
 
diff --git a/gck/gck-session.c b/gck/gck-session.c
index c776005..c9aecdf 100644
--- a/gck/gck-session.c
+++ b/gck/gck-session.c
@@ -518,7 +518,7 @@ gck_session_initable_init_finish (GAsyncInitable *initable,
                OpenSession *args;
 
                if (_gck_call_basic_finish (result, error)) {
-                       args = _gck_call_arguments (result, OpenSession);
+                       args = _gck_call_async_result_arguments (result, OpenSession);
                        self->pv->handle = args->session;
                        ret = TRUE;
                }
@@ -1467,7 +1467,7 @@ gck_session_create_object_finish (GckSession *self, GAsyncResult *result, GError
 {
        CreateObject *args;
 
-       args = _gck_call_arguments (result, CreateObject);
+       args = _gck_call_async_result_arguments (result, CreateObject);
 
        if (!_gck_call_basic_finish (result, error))
                return NULL;
@@ -1655,7 +1655,7 @@ gck_session_find_handles_finish (GckSession *self,
        g_return_val_if_fail (n_handles != NULL, NULL);
        g_return_val_if_fail (error == NULL || *error == NULL, NULL);
 
-       args = _gck_call_arguments (result, FindObjects);
+       args = _gck_call_async_result_arguments (result, FindObjects);
 
        if (!_gck_call_basic_finish (result, error))
                return NULL;
@@ -1982,7 +1982,7 @@ gck_session_generate_key_pair_finish (GckSession *self,
        g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
        g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
 
-       args = _gck_call_arguments (result, GenerateKeyPair);
+       args = _gck_call_async_result_arguments (result, GenerateKeyPair);
 
        if (!_gck_call_basic_finish (result, error))
                return FALSE;
@@ -2167,7 +2167,7 @@ gck_session_wrap_key_finish (GckSession *self, GAsyncResult *result,
        g_return_val_if_fail (GCK_IS_SESSION (self), NULL);
        g_return_val_if_fail (n_result, NULL);
 
-       args = _gck_call_arguments (result, WrapKey);
+       args = _gck_call_async_result_arguments (result, WrapKey);
 
        if (!_gck_call_basic_finish (result, error))
                return NULL;
@@ -2372,7 +2372,7 @@ gck_session_unwrap_key_finish (GckSession *self, GAsyncResult *result, GError **
 
        g_return_val_if_fail (GCK_IS_SESSION (self), NULL);
 
-       args = _gck_call_arguments (result, UnwrapKey);
+       args = _gck_call_async_result_arguments (result, UnwrapKey);
 
        if (!_gck_call_basic_finish (result, error))
                return NULL;
@@ -2542,7 +2542,7 @@ gck_session_derive_key_finish (GckSession *self, GAsyncResult *result, GError **
 
        g_return_val_if_fail (GCK_IS_SESSION (self), NULL);
 
-       args = _gck_call_arguments (result, DeriveKey);
+       args = _gck_call_async_result_arguments (result, DeriveKey);
 
        if (!_gck_call_basic_finish (result, error))
                return NULL;
@@ -2707,7 +2707,7 @@ crypt_finish (GckSession *self, GAsyncResult *result, gsize *n_result, GError **
 
        if (!_gck_call_basic_finish (result, error))
                return NULL;
-       args = _gck_call_arguments (result, Crypt);
+       args = _gck_call_async_result_arguments (result, Crypt);
 
        /* Steal the values from the results */
        res = args->result;
diff --git a/gck/test-gck-crypto.c b/gck/test-gck-crypto.c
index 00a6ad3..b7e2118 100644
--- a/gck/test-gck-crypto.c
+++ b/gck/test-gck-crypto.c
@@ -88,6 +88,8 @@ teardown (Test *test, gconstpointer unused)
        g_object_unref (test->module);
        g_object_unref (test->session_with_auth);
 
+       egg_test_wait_for_gtask_thread (test->session || test->session_with_auth || test->module);
+
        g_assert_null (test->session);
        g_assert_null (test->session_with_auth);
        g_assert_null (test->module);
@@ -290,6 +292,7 @@ test_login_context_specific (Test *test, gconstpointer unused)
        g_error_free (error);
 
        g_object_unref (key);
+       egg_test_wait_for_gtask_thread (key);
        g_assert_null (key);
 }
 
@@ -389,6 +392,7 @@ test_verify (Test *test, gconstpointer unused)
        g_object_unref (result);
 
        g_object_unref (key);
+       egg_test_wait_for_gtask_thread (key);
        g_assert_null (key);
 }
 
diff --git a/gck/test-gck-enumerator.c b/gck/test-gck-enumerator.c
index afb7e90..e7ad139 100644
--- a/gck/test-gck-enumerator.c
+++ b/gck/test-gck-enumerator.c
@@ -62,9 +62,8 @@ teardown (Test *test, gconstpointer unused)
        gck_list_unref_free (test->modules);
 
        g_object_unref (test->module);
+       egg_test_wait_for_gtask_thread (test->module);
        g_assert_null (test->module);
-
-       g_thread_pool_stop_unused_threads ();
 }
 
 static void
diff --git a/gck/test-gck-module.c b/gck/test-gck-module.c
index 1e9d658..91e7e4d 100644
--- a/gck/test-gck-module.c
+++ b/gck/test-gck-module.c
@@ -51,6 +51,7 @@ static void
 teardown (Test *test, gconstpointer unused)
 {
        g_object_unref (test->module);
+       egg_test_wait_for_gtask_thread (test->module);
        g_assert_null (test->module);
 }
 
diff --git a/gck/test-gck-session.c b/gck/test-gck-session.c
index cb7898f..0a296df 100644
--- a/gck/test-gck-session.c
+++ b/gck/test-gck-session.c
@@ -74,6 +74,8 @@ teardown (Test *test, gconstpointer unused)
        g_object_unref (test->slot);
        g_object_unref (test->module);
 
+       egg_test_wait_for_gtask_thread (test->session || test->slot || test->module);
+
        g_assert_null (test->session);
        g_assert_null (test->slot);
        g_assert_null (test->module);
@@ -148,6 +150,7 @@ test_open_close_session (Test *test, gconstpointer unused)
        g_assert_null (result);
 
        g_object_unref (sess);
+       egg_test_wait_for_gtask_thread (sess);
        g_assert_null (sess);
 }
 
diff --git a/gcr/test-gnupg-key.c b/gcr/test-gnupg-key.c
index 4590311..e73f934 100644
--- a/gcr/test-gnupg-key.c
+++ b/gcr/test-gnupg-key.c
@@ -78,6 +78,7 @@ static void
 teardown (Test *test, gconstpointer unused)
 {
        g_object_unref (test->key);
+       egg_test_wait_for_gtask_thread (test->key);
        g_assert (test->key == NULL);
 
        g_ptr_array_unref (test->records);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]