Hey, On Tue, Nov 24, 2015 at 04:23:12PM +0000, Zeeshan Ali (Khattak) wrote: > Drop usage of deprecated GSimpleAsyncResult API. > --- > libvirt-gobject/libvirt-gobject-domain.c | 290 +++++++++--------------- > libvirt-gobject/libvirt-gobject-input-stream.c | 77 +++---- > libvirt-gobject/libvirt-gobject-output-stream.c | 75 +++--- > libvirt-gobject/libvirt-gobject-storage-pool.c | 281 ++++++++++------------- > libvirt-gobject/libvirt-gobject-stream.c | 53 +++-- > 5 files changed, 322 insertions(+), 454 deletions(-) > > diff --git a/libvirt-gobject/libvirt-gobject-domain.c b/libvirt-gobject/libvirt-gobject-domain.c > index 5509ce3..c768cd3 100644 > --- a/libvirt-gobject/libvirt-gobject-domain.c > +++ b/libvirt-gobject/libvirt-gobject-domain.c > diff --git a/libvirt-gobject/libvirt-gobject-input-stream.c b/libvirt-gobject/libvirt-gobject-input-stream.c > index ff1a70c..cd107e1 100644 > --- a/libvirt-gobject/libvirt-gobject-input-stream.c > +++ b/libvirt-gobject/libvirt-gobject-input-stream.c > @@ -45,8 +45,7 @@ struct _GVirInputStreamPrivate > GVirStream *stream; > > /* pending operation metadata */ > - GSimpleAsyncResult *result; > - GCancellable *cancellable; > + GTask *task; > gpointer buffer; > gsize count; > }; > @@ -103,48 +102,44 @@ gvir_input_stream_read_ready(GVirStream *stream, > { > GVirInputStream *input_stream = GVIR_INPUT_STREAM(opaque); > GVirInputStreamPrivate *priv = input_stream->priv; > - GSimpleAsyncResult *simple = priv->result; > + GTask *task = priv->task; > + GCancellable *cancellable = g_task_get_cancellable(task); > GError *error = NULL; > gssize result; > > + priv->task = NULL; > + > if (!(cond & GVIR_STREAM_IO_CONDITION_READABLE)) { > g_warn_if_reached(); > - g_simple_async_result_set_error(simple, > - G_IO_ERROR, > - G_IO_ERROR_INVALID_ARGUMENT, > - "%s", > - "Expected stream to be readable"); > + g_task_return_new_error(task, > + G_IO_ERROR, > + G_IO_ERROR_INVALID_ARGUMENT, > + "%s", > + "Expected stream to be readable"); > goto cleanup; > } > > - result = gvir_stream_receive(stream, priv->buffer, priv->count, > - priv->cancellable, &error); > + result = gvir_stream_receive(stream, priv->buffer, priv->count, > + cancellable, &error); > + if (error != NULL) { > + if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK)) { > + g_warn_if_reached(); > + g_task_return_new_error(task, > + G_IO_ERROR, > + G_IO_ERROR_INVALID_ARGUMENT, > + "%s", > + "Expected stream to be readable"); This is preexisting, but I believe 'error' is going to be leaked here. > + } else { > + g_task_return_error(task, error); > + } > > - if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK)) { > - g_warn_if_reached(); > - g_simple_async_result_set_error(simple, > - G_IO_ERROR, > - G_IO_ERROR_INVALID_ARGUMENT, > - "%s", > - "Expected stream to be readable"); > goto cleanup; > } > > - if (result >= 0) > - g_simple_async_result_set_op_res_gssize(simple, result); > - > - if (error) > - g_simple_async_result_take_error(simple, error); > - > - if (priv->cancellable) { > - g_object_unref(priv->cancellable); > - priv->cancellable = NULL; > - } > + g_task_return_int(task, result); > > cleanup: > - priv->result = NULL; > - g_simple_async_result_complete(simple); > - g_object_unref(simple); > + g_object_unref(task); > return FALSE; > } > > @@ -159,7 +154,7 @@ static void gvir_input_stream_read_async(GInputStream *stream, > GVirInputStream *input_stream = GVIR_INPUT_STREAM(stream); > > g_return_if_fail(GVIR_IS_INPUT_STREAM(stream)); > - g_return_if_fail(input_stream->priv->result == NULL); > + g_return_if_fail(input_stream->priv->task == NULL); > > gvir_stream_add_watch_full(input_stream->priv->stream, > G_PRIORITY_DEFAULT, > @@ -168,12 +163,8 @@ static void gvir_input_stream_read_async(GInputStream *stream, > g_object_ref(stream), > (GDestroyNotify)g_object_unref); > > - input_stream->priv->result = > - g_simple_async_result_new(G_OBJECT(stream), callback, user_data, > - gvir_input_stream_read_async); > - if (cancellable) > - g_object_ref(cancellable); > - input_stream->priv->cancellable = cancellable; > + input_stream->priv->task = > + g_task_new(stream, cancellable, callback, user_data); > input_stream->priv->buffer = buffer; > input_stream->priv->count = count; > } > @@ -181,22 +172,18 @@ static void gvir_input_stream_read_async(GInputStream *stream, > > static gssize gvir_input_stream_read_finish(GInputStream *stream, > GAsyncResult *result, > - GError **error G_GNUC_UNUSED) > + GError **error) > { > GVirInputStream *input_stream = GVIR_INPUT_STREAM(stream); > - GSimpleAsyncResult *simple; > virStreamPtr handle; > gssize count; > > g_return_val_if_fail(GVIR_IS_INPUT_STREAM(stream), -1); > - g_return_val_if_fail(g_simple_async_result_is_valid(result, G_OBJECT(stream), > - gvir_input_stream_read_async), > - -1); > + g_return_val_if_fail(g_task_is_valid(result, stream), -1); > + g_return_val_if_fail(error == NULL || *error == NULL, -1); > g_object_get(input_stream->priv->stream, "handle", &handle, NULL); > > - simple = G_SIMPLE_ASYNC_RESULT(result); > - > - count = g_simple_async_result_get_op_res_gssize(simple); > + count = g_task_propagate_int(G_TASK(result), error); > > virStreamFree(handle); > > diff --git a/libvirt-gobject/libvirt-gobject-output-stream.c b/libvirt-gobject/libvirt-gobject-output-stream.c > index f39328b..a9c1236 100644 > --- a/libvirt-gobject/libvirt-gobject-output-stream.c > +++ b/libvirt-gobject/libvirt-gobject-output-stream.c > @@ -45,8 +45,7 @@ struct _GVirOutputStreamPrivate > GVirStream *stream; > > /* pending operation metadata */ > - GSimpleAsyncResult *result; > - GCancellable *cancellable; > + GTask *task; > const void * buffer; > gsize count; > }; > @@ -103,48 +102,44 @@ gvir_output_stream_write_ready(GVirStream *stream, > { > GVirOutputStream *output_stream = GVIR_OUTPUT_STREAM(opaque); > GVirOutputStreamPrivate *priv = output_stream->priv; > - GSimpleAsyncResult *simple = priv->result; > + GTask *task = priv->task; > + GCancellable *cancellable = g_task_get_cancellable(task); > GError *error = NULL; > gssize result; > > if (!(cond & GVIR_STREAM_IO_CONDITION_WRITABLE)) { > g_warn_if_reached(); > - g_simple_async_result_set_error(simple, > - G_IO_ERROR, > - G_IO_ERROR_INVALID_ARGUMENT, > - "%s", > - "Expected stream to be writable"); > + g_task_return_new_error(task, > + G_IO_ERROR, > + G_IO_ERROR_INVALID_ARGUMENT, > + "%s", > + "Expected stream to be readable"); > goto cleanup; > } > > result = gvir_stream_send(stream, priv->buffer, priv->count, > - priv->cancellable, &error); > + cancellable, &error); > + > + if (error != NULL) { > + if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK)) { > + g_warn_if_reached(); > + g_task_return_new_error(task, > + G_IO_ERROR, > + G_IO_ERROR_INVALID_ARGUMENT, > + "%s", > + "Expected stream to be writable"); Same leak mentioned before (can be addressed in a separate patch though). > + } else { > + g_task_return_error(task, error); > + } > > - if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK)) { > - g_warn_if_reached(); > - g_simple_async_result_set_error(simple, > - G_IO_ERROR, > - G_IO_ERROR_INVALID_ARGUMENT, > - "%s", > - "Expected stream to be writable"); > goto cleanup; > } > > - if (result >= 0) > - g_simple_async_result_set_op_res_gssize(simple, result); > - > - if (error) > - g_simple_async_result_take_error(simple, error); > - > - if (priv->cancellable) { > - g_object_unref(priv->cancellable); > - priv->cancellable = NULL; > - } > + g_task_return_int(task, result); > > cleanup: > - priv->result = NULL; > - g_simple_async_result_complete(simple); > - g_object_unref(simple); > + priv->task = NULL; > + g_object_unref(task); > return FALSE; > } > > @@ -159,7 +154,7 @@ static void gvir_output_stream_write_async(GOutputStream *stream, > GVirOutputStream *output_stream = GVIR_OUTPUT_STREAM(stream); > > g_return_if_fail(GVIR_IS_OUTPUT_STREAM(stream)); > - g_return_if_fail(output_stream->priv->result == NULL); > + g_return_if_fail(output_stream->priv->task == NULL); > > gvir_stream_add_watch_full(output_stream->priv->stream, > G_PRIORITY_DEFAULT, > @@ -168,12 +163,8 @@ static void gvir_output_stream_write_async(GOutputStream *stream, > g_object_ref(stream), > (GDestroyNotify)g_object_unref); > > - output_stream->priv->result = > - g_simple_async_result_new(G_OBJECT(stream), callback, user_data, > - gvir_output_stream_write_async); > - if (cancellable) > - g_object_ref(cancellable); > - output_stream->priv->cancellable = cancellable; > + output_stream->priv->task = > + g_task_new(stream, cancellable, callback, user_data); > output_stream->priv->buffer = buffer; > output_stream->priv->count = count; > } > @@ -181,22 +172,18 @@ static void gvir_output_stream_write_async(GOutputStream *stream, > > static gssize gvir_output_stream_write_finish(GOutputStream *stream, > GAsyncResult *result, > - GError **error G_GNUC_UNUSED) > + GError **error) > { > GVirOutputStream *output_stream = GVIR_OUTPUT_STREAM(stream); > - GSimpleAsyncResult *simple; > virStreamPtr handle; > gssize count; > > g_return_val_if_fail(GVIR_IS_OUTPUT_STREAM(stream), -1); > - g_return_val_if_fail(g_simple_async_result_is_valid(result, G_OBJECT(stream), > - gvir_output_stream_write_async), > - -1); > + g_return_val_if_fail(g_task_is_valid(result, stream), -1); > + g_return_val_if_fail(error == NULL || *error == NULL, -1); > g_object_get(output_stream->priv->stream, "handle", &handle, NULL); > > - simple = G_SIMPLE_ASYNC_RESULT(result); > - > - count = g_simple_async_result_get_op_res_gssize(simple); > + count = g_task_propagate_int(G_TASK(result), error); > > virStreamFree(handle); > > diff --git a/libvirt-gobject/libvirt-gobject-storage-pool.c b/libvirt-gobject/libvirt-gobject-storage-pool.c > index a0dcebc..6290fcb 100644 > --- a/libvirt-gobject/libvirt-gobject-storage-pool.c > +++ b/libvirt-gobject/libvirt-gobject-storage-pool.c > @@ -439,17 +439,18 @@ cleanup: > } > > static void > -gvir_storage_pool_refresh_helper(GSimpleAsyncResult *res, > - GObject *object, > +gvir_storage_pool_refresh_helper(GTask *task, > + gpointer source_object, > + gpointer task_data G_GNUC_UNUSED, > GCancellable *cancellable) > { > - GVirStoragePool *pool = GVIR_STORAGE_POOL(object); > + GVirStoragePool *pool = GVIR_STORAGE_POOL(source_object); > GError *err = NULL; > > - if (!gvir_storage_pool_refresh(pool, cancellable, &err)) { > - g_simple_async_result_set_from_error(res, err); > - g_error_free(err); > - } > + if (!gvir_storage_pool_refresh(pool, cancellable, &err)) > + g_task_return_error(task, err); > + else > + g_task_return_boolean(task, TRUE); > } > > /** > @@ -464,20 +465,17 @@ void gvir_storage_pool_refresh_async(GVirStoragePool *pool, > GAsyncReadyCallback callback, > gpointer user_data) > { > - GSimpleAsyncResult *res; > + GTask *task; > > g_return_if_fail(GVIR_IS_STORAGE_POOL(pool)); > g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable)); > > - res = g_simple_async_result_new(G_OBJECT(pool), > - callback, > - user_data, > - gvir_storage_pool_refresh_async); > - g_simple_async_result_run_in_thread(res, > - gvir_storage_pool_refresh_helper, > - G_PRIORITY_DEFAULT, > - cancellable); > - g_object_unref(res); > + task = g_task_new(G_OBJECT(pool), > + cancellable, > + callback, > + user_data); > + g_task_run_in_thread(task, gvir_storage_pool_refresh_helper); > + g_object_unref(task); > } > > /** > @@ -490,15 +488,10 @@ gboolean gvir_storage_pool_refresh_finish(GVirStoragePool *pool, > GError **err) > { > g_return_val_if_fail(GVIR_IS_STORAGE_POOL(pool), FALSE); > - g_return_val_if_fail(g_simple_async_result_is_valid(result, G_OBJECT(pool), > - gvir_storage_pool_refresh_async), > - FALSE); > - > - if (g_simple_async_result_propagate_error(G_SIMPLE_ASYNC_RESULT(result), > - err)) > - return FALSE; > + g_return_val_if_fail(g_task_is_valid(result, pool), FALSE); > + g_return_val_if_fail(err == NULL || *err == NULL, FALSE); > > - return TRUE; > + return g_task_propagate_boolean(G_TASK(result), err); > } > > static void gvir_storage_vol_ref(gpointer obj, gpointer ignore G_GNUC_UNUSED) > @@ -658,24 +651,25 @@ typedef struct { > guint flags; > } StoragePoolBuildData; > For what it's worth, StoragePoolBuildData could also use GPOINTER_TO/FROM_UINT (but can be addressed later as this is preexisting). > +static void storage_pool_build_data_free(StoragePoolBuildData *data) > +{ > + g_slice_free(StoragePoolBuildData, data); > +} > + > static void > -gvir_storage_pool_build_helper(GSimpleAsyncResult *res, > - GObject *object, > +gvir_storage_pool_build_helper(GTask *task, > + gpointer source_object, > + gpointer task_data, > GCancellable *cancellable G_GNUC_UNUSED) > { > - GVirStoragePool *pool = GVIR_STORAGE_POOL(object); > - StoragePoolBuildData *data; > + GVirStoragePool *pool = GVIR_STORAGE_POOL(source_object); > + StoragePoolBuildData *data = (StoragePoolBuildData *) task_data; > GError *err = NULL; > > - data = (StoragePoolBuildData *) g_object_get_data(G_OBJECT(res), > - "StoragePoolBuildData"); > - > - if (!gvir_storage_pool_build(pool, data->flags, &err)) { > - g_simple_async_result_set_from_error(res, err); > - g_error_free(err); > - } > - > - g_slice_free (StoragePoolBuildData, data); > + if (!gvir_storage_pool_build(pool, data->flags, &err)) > + g_task_return_error(task, err); > + else > + g_task_return_boolean(task, TRUE); > } > > /** > @@ -692,7 +686,7 @@ void gvir_storage_pool_build_async (GVirStoragePool *pool, > GAsyncReadyCallback callback, > gpointer user_data) > { > - GSimpleAsyncResult *res; > + GTask *task; > StoragePoolBuildData *data; > > g_return_if_fail(GVIR_IS_STORAGE_POOL(pool)); > @@ -701,16 +695,13 @@ void gvir_storage_pool_build_async (GVirStoragePool *pool, > data = g_slice_new0(StoragePoolBuildData); > data->flags = flags; > > - res = g_simple_async_result_new(G_OBJECT(pool), > - callback, > - user_data, > - gvir_storage_pool_build_async); > - g_object_set_data(G_OBJECT(res), "StoragePoolBuildData", data); > - g_simple_async_result_run_in_thread(res, > - gvir_storage_pool_build_helper, > - G_PRIORITY_DEFAULT, > - cancellable); > - g_object_unref(res); > + task = g_task_new(G_OBJECT(pool), > + cancellable, > + callback, > + user_data); > + g_task_set_task_data(task, data, (GDestroyNotify)storage_pool_build_data_free); > + g_task_run_in_thread(task, gvir_storage_pool_build_helper); > + g_object_unref(task); > } > > /** > @@ -726,16 +717,10 @@ gboolean gvir_storage_pool_build_finish(GVirStoragePool *pool, > GError **err) > { > g_return_val_if_fail(GVIR_IS_STORAGE_POOL(pool), FALSE); > - g_return_val_if_fail(g_simple_async_result_is_valid(result, G_OBJECT(pool), > - gvir_storage_pool_build_async), > - FALSE); > + g_return_val_if_fail(g_task_is_valid(result, pool), FALSE); > g_return_val_if_fail(err == NULL || *err == NULL, FALSE); > > - if (g_simple_async_result_propagate_error(G_SIMPLE_ASYNC_RESULT(result), > - err)) > - return FALSE; > - > - return TRUE; > + return g_task_propagate_boolean(G_TASK(result), err); > } > > /** > @@ -762,17 +747,18 @@ gboolean gvir_storage_pool_undefine (GVirStoragePool *pool, > } > > static void > -gvir_storage_pool_undefine_helper(GSimpleAsyncResult *res, > - GObject *object, > +gvir_storage_pool_undefine_helper(GTask *task, > + gpointer source_object, > + gpointer task_data G_GNUC_UNUSED, > GCancellable *cancellable G_GNUC_UNUSED) > { > - GVirStoragePool *pool = GVIR_STORAGE_POOL(object); > + GVirStoragePool *pool = GVIR_STORAGE_POOL(source_object); > GError *err = NULL; > > - if (!gvir_storage_pool_undefine(pool, &err)) { > - g_simple_async_result_set_from_error(res, err); > - g_error_free(err); > - } > + if (!gvir_storage_pool_undefine(pool, &err)) > + g_task_return_error(task, err); > + else > + g_task_return_boolean(task, TRUE); > } > > /** > @@ -787,20 +773,17 @@ void gvir_storage_pool_undefine_async (GVirStoragePool *pool, > GAsyncReadyCallback callback, > gpointer user_data) > { > - GSimpleAsyncResult *res; > + GTask *task; > > g_return_if_fail(GVIR_IS_STORAGE_POOL(pool)); > g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable)); > > - res = g_simple_async_result_new(G_OBJECT(pool), > - callback, > - user_data, > - gvir_storage_pool_undefine_async); > - g_simple_async_result_run_in_thread(res, > - gvir_storage_pool_undefine_helper, > - G_PRIORITY_DEFAULT, > - cancellable); > - g_object_unref(res); > + task = g_task_new(G_OBJECT(pool), > + cancellable, > + callback, > + user_data); > + g_task_run_in_thread(task, gvir_storage_pool_undefine_helper); > + g_object_unref(task); > } > > /** > @@ -816,16 +799,10 @@ gboolean gvir_storage_pool_undefine_finish(GVirStoragePool *pool, > GError **err) > { > g_return_val_if_fail(GVIR_IS_STORAGE_POOL(pool), FALSE); > - g_return_val_if_fail(g_simple_async_result_is_valid(result, G_OBJECT(pool), > - gvir_storage_pool_undefine_async), > - FALSE); > + g_return_val_if_fail(g_task_is_valid(result, pool), FALSE); > g_return_val_if_fail(err == NULL || *err == NULL, FALSE); > > - if (g_simple_async_result_propagate_error(G_SIMPLE_ASYNC_RESULT(result), > - err)) > - return FALSE; > - > - return TRUE; > + return g_task_propagate_boolean(G_TASK(result), err); > } > > /** > @@ -854,23 +831,21 @@ gboolean gvir_storage_pool_start (GVirStoragePool *pool, > } > > static void > -gvir_storage_pool_start_helper(GSimpleAsyncResult *res, > - GObject *object, > +gvir_storage_pool_start_helper(GTask *task, > + gpointer source_object, > + gpointer task_data, > GCancellable *cancellable G_GNUC_UNUSED) > { > - GVirStoragePool *pool = GVIR_STORAGE_POOL(object); > + GVirStoragePool *pool = GVIR_STORAGE_POOL(source_object); > StoragePoolBuildData *data; > GError *err = NULL; > > - data = (StoragePoolBuildData *) g_object_get_data(G_OBJECT(res), > - "StoragePoolBuildData"); > + data = (StoragePoolBuildData *) task_data; > > - if (!gvir_storage_pool_start(pool, data->flags, &err)) { > - g_simple_async_result_set_from_error(res, err); > - g_error_free(err); > - } > - > - g_slice_free (StoragePoolBuildData, data); > + if (!gvir_storage_pool_start(pool, data->flags, &err)) > + g_task_return_error(task, err); > + else > + g_task_return_boolean(task, TRUE); > } > > /** > @@ -887,7 +862,7 @@ void gvir_storage_pool_start_async (GVirStoragePool *pool, > GAsyncReadyCallback callback, > gpointer user_data) > { > - GSimpleAsyncResult *res; > + GTask *task; > StoragePoolBuildData *data; > > g_return_if_fail(GVIR_IS_STORAGE_POOL(pool)); > @@ -896,16 +871,13 @@ void gvir_storage_pool_start_async (GVirStoragePool *pool, > data = g_slice_new0(StoragePoolBuildData); > data->flags = flags; > > - res = g_simple_async_result_new(G_OBJECT(pool), > - callback, > - user_data, > - gvir_storage_pool_start_async); > - g_object_set_data(G_OBJECT(res), "StoragePoolBuildData", data); > - g_simple_async_result_run_in_thread(res, > - gvir_storage_pool_start_helper, > - G_PRIORITY_DEFAULT, > - cancellable); > - g_object_unref(res); > + task = g_task_new(G_OBJECT(pool), > + cancellable, > + callback, > + user_data); > + g_task_set_task_data(task, data, (GDestroyNotify)storage_pool_build_data_free); > + g_task_run_in_thread(task, gvir_storage_pool_start_helper); > + g_object_unref(task); > } > > /** > @@ -921,16 +893,10 @@ gboolean gvir_storage_pool_start_finish(GVirStoragePool *pool, > GError **err) > { > g_return_val_if_fail(GVIR_IS_STORAGE_POOL(pool), FALSE); > - g_return_val_if_fail(g_simple_async_result_is_valid(result, G_OBJECT(pool), > - gvir_storage_pool_start_async), > - FALSE); > + g_return_val_if_fail(g_task_is_valid(result, pool), FALSE); > g_return_val_if_fail(err == NULL || *err == NULL, FALSE); > > - if (g_simple_async_result_propagate_error(G_SIMPLE_ASYNC_RESULT(result), > - err)) > - return FALSE; > - > - return TRUE; > + return g_task_propagate_boolean(G_TASK(result), err); > } > > /** > @@ -957,17 +923,18 @@ gboolean gvir_storage_pool_stop (GVirStoragePool *pool, > } > > static void > -gvir_storage_pool_stop_helper(GSimpleAsyncResult *res, > - GObject *object, > +gvir_storage_pool_stop_helper(GTask *task, > + gpointer source_object, > + gpointer task_data G_GNUC_UNUSED, > GCancellable *cancellable G_GNUC_UNUSED) > { > - GVirStoragePool *pool = GVIR_STORAGE_POOL(object); > + GVirStoragePool *pool = GVIR_STORAGE_POOL(source_object); > GError *err = NULL; > > - if (!gvir_storage_pool_stop(pool, &err)) { > - g_simple_async_result_set_from_error(res, err); > - g_error_free(err); > - } > + if (!gvir_storage_pool_stop(pool, &err)) > + g_task_return_error(task, err); > + else > + g_task_return_boolean(task, TRUE); > } > > /** > @@ -982,20 +949,17 @@ void gvir_storage_pool_stop_async (GVirStoragePool *pool, > GAsyncReadyCallback callback, > gpointer user_data) > { > - GSimpleAsyncResult *res; > + GTask *task; > > g_return_if_fail(GVIR_IS_STORAGE_POOL(pool)); > g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable)); > > - res = g_simple_async_result_new(G_OBJECT(pool), > - callback, > - user_data, > - gvir_storage_pool_stop_async); > - g_simple_async_result_run_in_thread(res, > - gvir_storage_pool_stop_helper, > - G_PRIORITY_DEFAULT, > - cancellable); > - g_object_unref(res); > + task = g_task_new(G_OBJECT(pool), > + cancellable, > + callback, > + user_data); > + g_task_run_in_thread(task, gvir_storage_pool_stop_helper); > + g_object_unref(task); > } > > /** > @@ -1011,16 +975,10 @@ gboolean gvir_storage_pool_stop_finish(GVirStoragePool *pool, > GError **err) > { > g_return_val_if_fail(GVIR_IS_STORAGE_POOL(pool), FALSE); > - g_return_val_if_fail(g_simple_async_result_is_valid(result, G_OBJECT(pool), > - gvir_storage_pool_stop_async), > - FALSE); > + g_return_val_if_fail(g_task_is_valid(result, pool), FALSE); > g_return_val_if_fail(err == NULL || *err == NULL, FALSE); > > - if (g_simple_async_result_propagate_error(G_SIMPLE_ASYNC_RESULT(result), > - err)) > - return FALSE; > - > - return TRUE; > + return g_task_propagate_boolean(G_TASK(result), err); > } > > /** > @@ -1100,23 +1058,21 @@ gboolean gvir_storage_pool_set_autostart(GVirStoragePool *pool, > } > > static void > -gvir_storage_pool_delete_helper(GSimpleAsyncResult *res, > - GObject *object, > +gvir_storage_pool_delete_helper(GTask *task, > + gpointer source_object, > + gpointer task_data, > GCancellable *cancellable G_GNUC_UNUSED) > { > - GVirStoragePool *pool = GVIR_STORAGE_POOL(object); > + GVirStoragePool *pool = GVIR_STORAGE_POOL(source_object); > StoragePoolBuildData *data; > GError *err = NULL; > > - data = (StoragePoolBuildData *) g_object_get_data(G_OBJECT(res), > - "StoragePoolBuildData"); > + data = (StoragePoolBuildData *) task_data; > > - if (!gvir_storage_pool_delete(pool, data->flags, &err)) { > - g_simple_async_result_set_from_error(res, err); > - g_error_free(err); > - } > - > - g_slice_free (StoragePoolBuildData, data); > + if (!gvir_storage_pool_delete(pool, data->flags, &err)) > + g_task_return_error(task, err); > + else > + g_task_return_boolean(task, TRUE); > } > > /** > @@ -1133,7 +1089,7 @@ void gvir_storage_pool_delete_async (GVirStoragePool *pool, > GAsyncReadyCallback callback, > gpointer user_data) > { > - GSimpleAsyncResult *res; > + GTask *task; > StoragePoolBuildData *data; > > g_return_if_fail(GVIR_IS_STORAGE_POOL(pool)); > @@ -1142,16 +1098,13 @@ void gvir_storage_pool_delete_async (GVirStoragePool *pool, > data = g_slice_new0(StoragePoolBuildData); > data->flags = flags; > > - res = g_simple_async_result_new(G_OBJECT(pool), > - callback, > - user_data, > - gvir_storage_pool_delete_async); > - g_object_set_data(G_OBJECT(res), "StoragePoolBuildData", data); > - g_simple_async_result_run_in_thread(res, > - gvir_storage_pool_delete_helper, > - G_PRIORITY_DEFAULT, > - cancellable); > - g_object_unref(res); > + task = g_task_new(G_OBJECT(pool), > + cancellable, > + callback, > + user_data); > + g_task_set_task_data(task, data, (GDestroyNotify)storage_pool_build_data_free); > + g_task_run_in_thread(task, gvir_storage_pool_delete_helper); > + g_object_unref(task); > } > > /** > @@ -1167,16 +1120,10 @@ gboolean gvir_storage_pool_delete_finish(GVirStoragePool *pool, > GError **err) > { > g_return_val_if_fail(GVIR_IS_STORAGE_POOL(pool), FALSE); > - g_return_val_if_fail(g_simple_async_result_is_valid(result, G_OBJECT(pool), > - gvir_storage_pool_delete_async), > - FALSE); > + g_return_val_if_fail(g_task_is_valid(result, pool), FALSE); > g_return_val_if_fail(err == NULL || *err == NULL, FALSE); > > - if (g_simple_async_result_propagate_error(G_SIMPLE_ASYNC_RESULT(result), > - err)) > - return FALSE; > - > - return TRUE; > + return g_task_propagate_boolean(G_TASK(result), err); > } > > G_GNUC_INTERNAL void gvir_storage_pool_delete_vol(GVirStoragePool *pool, > diff --git a/libvirt-gobject/libvirt-gobject-stream.c b/libvirt-gobject/libvirt-gobject-stream.c > index 46dbd9a..2a8fbd5 100644 > --- a/libvirt-gobject/libvirt-gobject-stream.c > +++ b/libvirt-gobject/libvirt-gobject-stream.c > @@ -129,14 +129,11 @@ static gboolean gvir_stream_close(GIOStream *io_stream, > return (i_ret && o_ret); > } > > - > -static void gvir_stream_close_async(GIOStream *stream, > - int io_priority G_GNUC_UNUSED, > - GCancellable *cancellable, > - GAsyncReadyCallback callback, > - gpointer user_data) > +static gboolean close_in_idle (gpointer data) > { > - GSimpleAsyncResult *res; > + GTask *task = G_TASK (data); > + GIOStream *stream = G_IO_STREAM(g_task_get_source_object (task)); > + GCancellable *cancellable = g_task_get_cancellable (task); > GIOStreamClass *class; > GError *error; > > @@ -146,27 +143,41 @@ static void gvir_stream_close_async(GIOStream *stream, > error = NULL; > if (class->close_fn && > !class->close_fn(stream, cancellable, &error)) { > - g_simple_async_report_take_gerror_in_idle(G_OBJECT (stream), > - callback, user_data, > - error); > - return; > + g_task_return_error(task, error); > + return FALSE; > } > > - res = g_simple_async_result_new(G_OBJECT (stream), > - callback, > - user_data, > - gvir_stream_close_async); > - g_simple_async_result_complete_in_idle(res); > - g_object_unref (res); > + g_task_return_boolean(task, TRUE); > + > + return FALSE; > } > > +static void gvir_stream_close_async(GIOStream *stream, > + int io_priority G_GNUC_UNUSED, > + GCancellable *cancellable, > + GAsyncReadyCallback callback, > + gpointer user_data) > +{ > + GTask *task; > + > + task = g_task_new(G_OBJECT(stream), > + cancellable, > + callback, > + user_data); > + g_idle_add(close_in_idle, task); > + g_object_unref(task); This g_object_unref needs to be in the idle otherwise the GTask will be destroyed before the idle runs. ACK. Christophe
Attachment:
signature.asc
Description: PGP signature
-- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list