[Spice-devel] [PATCH v2 01/13] channel-base: Use GTask instead of GSimpleAsyncResult

Jonathon Jongsma jjongsma at redhat.com
Tue Feb 16 19:45:50 UTC 2016


Acked-by: Jonathon Jongsma <jjongsma at redhat.com>


On Fri, 2016-02-12 at 10:46 +0100, Fabiano FidĂȘncio wrote:
> Instead of using GSimpleAsyncResult, use the new GTask API, which is
> much more straightforward.
> For using the new GTask API, let's bump GIO (part of GLib) dependency
> version to 2.36, which is safe based on major distro support:
> - Debian Jessie: glib-2.42
> - RHEL-7.1: glib-2.40
> - SLES12: glib-2.38
> - Ubuntu LTS 14.04: glib-2.40
> ---
>  configure.ac       |  6 +++---
>  src/channel-base.c | 29 +++++++++++++----------------
>  2 files changed, 16 insertions(+), 19 deletions(-)
> 
> diff --git a/configure.ac b/configure.ac
> index 38db8b5..e113487 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -201,7 +201,7 @@ fi
>  
>  AC_CHECK_FUNCS(clearenv strtok_r)
>  
> -PKG_CHECK_MODULES(GLIB2, glib-2.0 >= 2.28)
> +PKG_CHECK_MODULES(GLIB2, glib-2.0)
>  AC_SUBST(GLIB2_CFLAGS)
>  AC_SUBST(GLIB2_LIBS)
>  
> @@ -209,7 +209,7 @@ PKG_CHECK_MODULES(GOBJECT2, gobject-2.0)
>  AC_SUBST(GOBJECT2_CFLAGS)
>  AC_SUBST(GOBJECT2_LIBS)
>  
> -PKG_CHECK_MODULES(GIO, gio-2.0 >= 2.10.0 $gio_os)
> +PKG_CHECK_MODULES(GIO, gio-2.0 >= 2.36 $gio_os)
>  AC_SUBST(GIO_CFLAGS)
>  AC_SUBST(GIO_LIBS)
>  
> @@ -217,7 +217,7 @@ PKG_CHECK_MODULES(CAIRO, cairo >= 1.2.0)
>  AC_SUBST(CAIRO_CFLAGS)
>  AC_SUBST(CAIRO_LIBS)
>  
> -PKG_CHECK_MODULES(GTHREAD, gthread-2.0 > 2.0.0)
> +PKG_CHECK_MODULES(GTHREAD, gthread-2.0)
>  AC_SUBST(GTHREAD_CFLAGS)
>  AC_SUBST(GTHREAD_LIBS)
>  
> diff --git a/src/channel-base.c b/src/channel-base.c
> index 13e4ced..de04b89 100644
> --- a/src/channel-base.c
> +++ b/src/channel-base.c
> @@ -240,10 +240,12 @@ void spice_channel_set_handlers(SpiceChannelClass
> *klass,
>  static void
>  vmc_write_free_cb(uint8_t *data, void *user_data)
>  {
> -    GSimpleAsyncResult *result = user_data;
> +    GTask *task = user_data;
> +    gsize count = GPOINTER_TO_SIZE(g_task_get_task_data(task));
>  
> -    g_simple_async_result_complete_in_idle(result);
> -    g_object_unref(result);
> +    g_task_return_int(task, count);
> +
> +    g_object_unref(task);
>  }
>  
>  G_GNUC_INTERNAL
> @@ -254,15 +256,14 @@ void spice_vmc_write_async(SpiceChannel *self,
>                             gpointer user_data)
>  {
>      SpiceMsgOut *msg;
> -    GSimpleAsyncResult *simple;
> +    GTask *task;
>  
> -    simple = g_simple_async_result_new(G_OBJECT(self), callback, user_data,
> -                                       spice_port_write_async);
> -    g_simple_async_result_set_op_res_gssize(simple, count);
> +    task = g_task_new(self, cancellable, callback, user_data);
> +    g_task_set_task_data(task, GSIZE_TO_POINTER(count), NULL);
>  
>      msg = spice_msg_out_new(SPICE_CHANNEL(self), SPICE_MSGC_SPICEVMC_DATA);
>      spice_marshaller_add_ref_full(msg->marshaller, (uint8_t*)buffer, count,
> -                                  vmc_write_free_cb, simple);
> +                                  vmc_write_free_cb, task);
>      spice_msg_out_send(msg);
>  }
>  
> @@ -270,17 +271,13 @@ G_GNUC_INTERNAL
>  gssize spice_vmc_write_finish(SpiceChannel *self,
>                                GAsyncResult *result, GError **error)
>  {
> -    GSimpleAsyncResult *simple;
> +    GTask *task;
>  
>      g_return_val_if_fail(result != NULL, -1);
>  
> -    simple = (GSimpleAsyncResult *)result;
> -
> -    if (g_simple_async_result_propagate_error(simple, error))
> -        return -1;
> +    task = G_TASK(result);
>  
> -    g_return_val_if_fail(g_simple_async_result_is_valid(result,
> G_OBJECT(self),
> -                                                       
>  spice_port_write_async), -1);
> +    g_return_val_if_fail(g_task_is_valid(task, self), -1);
>  
> -    return g_simple_async_result_get_op_res_gssize(simple);
> +    return g_task_propagate_int(task, error);
>  }




More information about the Spice-devel mailing list