[gimp/gimp-2-10] app: add gimp_async_remove_callback()
- From: Ell <ell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/gimp-2-10] app: add gimp_async_remove_callback()
- Date: Sat, 26 May 2018 18:23:13 +0000 (UTC)
commit c96c6802e81a4f4536a43ea7ec1328931a1cbaa5
Author: Ell <ell_se yahoo com>
Date: Sat May 26 12:06:38 2018 -0400
app: add gimp_async_remove_callback()
... which removes a callback previously added through
gimp_async_add_callback().
(cherry picked from commit 85f67e196ca060c08052bf7585356fa39e633e25)
app/core/gimpasync.c | 39 +++++++++++++++++++++++++++++++++++++++
app/core/gimpasync.h | 42 +++++++++++++++++++++++-------------------
2 files changed, 62 insertions(+), 19 deletions(-)
---
diff --git a/app/core/gimpasync.c b/app/core/gimpasync.c
index b86dfb61bb..7a70380fdf 100644
--- a/app/core/gimpasync.c
+++ b/app/core/gimpasync.c
@@ -328,6 +328,45 @@ gimp_async_add_callback (GimpAsync *async,
g_mutex_unlock (&async->priv->mutex);
}
+/* removes all callbacks previously registered through
+ * 'gimp_async_add_callback()', matching 'callback' and 'data', which hasn't
+ * been called yet.
+ *
+ * may only be called on the main thread.
+ */
+void
+gimp_async_remove_callback (GimpAsync *async,
+ GimpAsyncCallback callback,
+ gpointer data)
+{
+ GList *iter;
+
+ g_return_if_fail (GIMP_IS_ASYNC (async));
+ g_return_if_fail (callback != NULL);
+
+ g_mutex_lock (&async->priv->mutex);
+
+ iter = g_queue_peek_head_link (&async->priv->callbacks);
+
+ while (iter)
+ {
+ GimpAsyncCallbackInfo *callback_info = iter->data;
+ GList *next = g_list_next (iter);
+
+ if (callback_info->callback == callback &&
+ callback_info->data == data)
+ {
+ g_queue_delete_link (&async->priv->callbacks, iter);
+
+ g_slice_free (GimpAsyncCallbackInfo, callback_info);
+ }
+
+ iter = next;
+ }
+
+ g_mutex_unlock (&async->priv->mutex);
+}
+
/* transitions 'async' to the "stopped" state, indicating that the task
* completed normally, possibly providing a result.
*
diff --git a/app/core/gimpasync.h b/app/core/gimpasync.h
index 1cd7cb23c0..b3d84dea9c 100644
--- a/app/core/gimpasync.h
+++ b/app/core/gimpasync.h
@@ -50,31 +50,35 @@ struct _GimpAsyncClass
};
-GType gimp_async_get_type (void) G_GNUC_CONST;
+GType gimp_async_get_type (void) G_GNUC_CONST;
-GimpAsync * gimp_async_new (void);
+GimpAsync * gimp_async_new (void);
-gboolean gimp_async_is_stopped (GimpAsync *async);
+gboolean gimp_async_is_stopped (GimpAsync *async);
-void gimp_async_wait (GimpAsync *async);
-gboolean gimp_async_wait_until (GimpAsync *async,
- gint64 end_time);
-void gimp_async_add_callback (GimpAsync *async,
- GimpAsyncCallback callback,
- gpointer data);
+void gimp_async_wait (GimpAsync *async);
+gboolean gimp_async_wait_until (GimpAsync *async,
+ gint64 end_time);
-void gimp_async_finish (GimpAsync *async,
- gpointer result);
-void gimp_async_finish_full (GimpAsync *async,
- gpointer result,
- GDestroyNotify result_destroy_func);
-gboolean gimp_async_is_finished (GimpAsync *async);
-gpointer gimp_async_get_result (GimpAsync *async);
+void gimp_async_add_callback (GimpAsync *async,
+ GimpAsyncCallback callback,
+ gpointer data);
+void gimp_async_remove_callback (GimpAsync *async,
+ GimpAsyncCallback callback,
+ gpointer data);
-void gimp_async_abort (GimpAsync *async);
+void gimp_async_finish (GimpAsync *async,
+ gpointer result);
+void gimp_async_finish_full (GimpAsync *async,
+ gpointer result,
+ GDestroyNotify result_destroy_func);
+gboolean gimp_async_is_finished (GimpAsync *async);
+gpointer gimp_async_get_result (GimpAsync *async);
-void gimp_async_cancel (GimpAsync *async);
-gboolean gimp_async_is_canceled (GimpAsync *async);
+void gimp_async_abort (GimpAsync *async);
+
+void gimp_async_cancel (GimpAsync *async);
+gboolean gimp_async_is_canceled (GimpAsync *async);
#endif /* __GIMP_ASYNC_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]