On 07.07, Christophe Fergeau wrote:
> Hey,
> 
> On Mon, Jun 30, 2014 at 07:50:16PM +0200, Timm Bäder wrote:
> > ---
> >  libvirt-gobject/libvirt-gobject-domain.c | 60 
> > ++++++++++++++++++++++++++++++++
> >  libvirt-gobject/libvirt-gobject-domain.h | 10 ++++++
> >  libvirt-gobject/libvirt-gobject.sym      |  2 ++
> >  3 files changed, 72 insertions(+)
> > 
> > diff --git a/libvirt-gobject/libvirt-gobject-domain.c 
> > b/libvirt-gobject/libvirt-gobject-domain.c
> > index b12a4a0..6b53d25 100644
> > --- a/libvirt-gobject/libvirt-gobject-domain.c
> > +++ b/libvirt-gobject/libvirt-gobject-domain.c
> > @@ -1618,3 +1618,63 @@ GList *gvir_domain_get_snapshots(GVirDomain *dom)
> >  
> >      return snapshots;
> >  }
> > +
> > +
> > +
> > +static void _fetch_snapshots_async_thread(GTask *task,
> > +                                          gpointer source_object,
> > +                                          gpointer task_data,
> > +                                          GCancellable *cancellable) {
> > +    GError *error = NULL;
> > +    gboolean status;
> > +
> > +    status = gvir_domain_fetch_snapshots(source_object,
> > +                                         GPOINTER_TO_UINT(task_data),
> > +                                         cancellable,
> > +                                         &error);
> > +    if (status)
> > +        g_task_return_boolean(task, TRUE);
> > +    else
> > +        g_task_return_error(task, error);
> > +}
> > +
> > +
> > +/**
> > + *
> > + * @dom: The domain
> > + * @list_flags: bitwise-OR of #GVirDomainSnapshotListFlags
> > + * @cancellable: (allow-none)(transfer-none): cancellation object
> > + * @callback: (scope async): completion callback
> > + * @user_data: (closure): opaque data for callback
> > + */
> > +void gvir_domain_fetch_snapshots_async(GVirDomain *dom,
> > +                                       guint list_flags,
> > +                                       GCancellable *cancellable,
> > +                                       GAsyncReadyCallback callback,
> > +                                       gpointer user_data) {
> > +    GTask *task;
> > +
> > +    g_return_if_fail(GVIR_IS_DOMAIN(dom));
> > +    g_return_if_fail((cancellable == NULL) || 
> > G_IS_CANCELLABLE(cancellable));
> > +
> > +    task = g_task_new(dom, cancellable, callback, user_data);
> 
> GTask was introduced in glib 2.36, so configure.ac needs to be updated
> to reflect that. glib 2.36 was released in March 2013, and is available
> in RHEL7, so using this would be fine with me. Others may want to
> disagree though :)
> 
> > +    g_task_set_task_data(task, GUINT_TO_POINTER(list_flags), NULL);
> > +    g_task_run_in_thread(task, _fetch_snapshots_async_thread);
> 
> I'm a bit unclear as how the initial ref obtained through g_task_new()
> is handled. Have you checked it's correctly freed after _finish() has
> been called and that it's not leaked?

Ouch, I've been fooled by the example in the GTask documentation (which
was wrong), it does ineed have to be unreffed in the function that calls
g_task_run_in_thread (which will itself take its own ref).


> 
> Looks good otherwise.
> 
> Christophe



> --
> libvir-list mailing list
> libvir-list@redhat.com
> https://www.redhat.com/mailman/listinfo/libvir-list

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Reply via email to