[glib] GAsyncQueue: Add some useful api
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] GAsyncQueue: Add some useful api
- Date: Mon, 29 Jun 2015 15:21:15 +0000 (UTC)
commit b662c6f09fe1a01bb1345f6cd7ab5a702eec5ee3
Author: Matthias Clasen <mclasen redhat com>
Date: Thu Jun 18 10:26:14 2015 -0400
GAsyncQueue: Add some useful api
The underlying queue supports removing and pushing items to
the front, and these operations can sometimes be useful.
https://bugzilla.gnome.org/show_bug.cgi?id=751160
docs/reference/glib/glib-sections.txt | 4 +
glib/gasyncqueue.c | 100 +++++++++++++++++++++++++++++++++
glib/gasyncqueue.h | 13 ++++
3 files changed, 117 insertions(+), 0 deletions(-)
---
diff --git a/docs/reference/glib/glib-sections.txt b/docs/reference/glib/glib-sections.txt
index 4346ac2..5e783e8 100644
--- a/docs/reference/glib/glib-sections.txt
+++ b/docs/reference/glib/glib-sections.txt
@@ -839,6 +839,8 @@ g_async_queue_ref
g_async_queue_unref
g_async_queue_push
g_async_queue_push_sorted
+g_async_queue_push_front
+g_async_queue_remove
g_async_queue_pop
g_async_queue_try_pop
g_async_queue_timeout_pop
@@ -852,6 +854,8 @@ g_async_queue_ref_unlocked
g_async_queue_unref_and_unlock
g_async_queue_push_unlocked
g_async_queue_push_sorted_unlocked
+g_async_queue_push_front_unlocked
+g_async_queue_remove_unlocked
g_async_queue_pop_unlocked
g_async_queue_try_pop_unlocked
g_async_queue_timeout_pop_unlocked
diff --git a/glib/gasyncqueue.c b/glib/gasyncqueue.c
index 8ed66ab..5fc7300 100644
--- a/glib/gasyncqueue.c
+++ b/glib/gasyncqueue.c
@@ -785,6 +785,106 @@ g_async_queue_sort_unlocked (GAsyncQueue *queue,
&sd);
}
+/**
+ * g_async_queue_remove:
+ * @queue: a #GAsyncQueue
+ * @data: the @data to remove from the @queue
+ *
+ * Remove an item from the queue. This function does not block.
+ *
+ * Returns: %TRUE if the item was removed
+ *
+ * Since: 2.46
+ */
+gboolean
+g_async_queue_remove (GAsyncQueue *queue,
+ gpointer data)
+{
+ gboolean ret;
+
+ g_return_val_if_fail (queue != NULL, FALSE);
+ g_return_val_if_fail (data != NULL, FALSE);
+
+ g_mutex_lock (&queue->mutex);
+ ret = g_async_queue_remove_unlocked (queue, data);
+ g_mutex_unlock (&queue->mutex);
+
+ return ret;
+}
+
+/**
+ * g_async_queue_remove_unlocked:
+ * @queue: a #GAsyncQueue
+ * @data: the @data to remove from the @queue
+ *
+ * Remove an item from the queue. This function does not block.
+ *
+ * This function must be called while holding the @queue's lock.
+ *
+ * Returns: %TRUE if the item was removed
+ *
+ * Since: 2.46
+ */
+gboolean
+g_async_queue_remove_unlocked (GAsyncQueue *queue,
+ gpointer data)
+{
+ g_return_val_if_fail (queue != NULL, FALSE);
+ g_return_val_if_fail (data != NULL, FALSE);
+
+ return g_queue_remove (&queue->queue, data);
+}
+
+/**
+ * g_async_queue_push_front:
+ * @queue: a #GAsyncQueue
+ * @data: @data to push into the @queue
+ *
+ * Pushes the @data into the @queue. @data must not be %NULL.
+ * In contrast to g_async_queue_push(), this function
+ * pushes the new item ahead of the items already in the queue,
+ * so that it will be the next one to be popped off the queue.
+ *
+ * Since: 2.46
+ */
+void
+g_async_queue_push_front (GAsyncQueue *queue,
+ gpointer data)
+{
+ g_return_if_fail (queue != NULL);
+ g_return_if_fail (data != NULL);
+
+ g_mutex_lock (&queue->mutex);
+ g_async_queue_push_front_unlocked (queue, data);
+ g_mutex_unlock (&queue->mutex);
+}
+
+/**
+ * g_async_queue_push_front_unlocked:
+ * @queue: a #GAsyncQueue
+ * @data: @data to push into the @queue
+ *
+ * Pushes the @data into the @queue. @data must not be %NULL.
+ * In contrast to g_async_queue_push_unlocked(), this function
+ * pushes the new item ahead of the items already in the queue,
+ * so that it will be the next one to be popped off the queue.
+ *
+ * This function must be called while holding the @queue's lock.
+ *
+ * Since: 2.46
+ */
+void
+g_async_queue_push_front_unlocked (GAsyncQueue *queue,
+ gpointer data)
+{
+ g_return_if_fail (queue != NULL);
+ g_return_if_fail (data != NULL);
+
+ g_queue_push_tail (&queue->queue, data);
+ if (queue->waiting_threads > 0)
+ g_cond_signal (&queue->cond);
+}
+
/*
* Private API
*/
diff --git a/glib/gasyncqueue.h b/glib/gasyncqueue.h
index fa9565f..0c71e14 100644
--- a/glib/gasyncqueue.h
+++ b/glib/gasyncqueue.h
@@ -97,6 +97,19 @@ void g_async_queue_sort_unlocked (GAsyncQueue *queue,
GCompareDataFunc func,
gpointer user_data);
+GLIB_AVAILABLE_IN_2_46
+gboolean g_async_queue_remove (GAsyncQueue *queue,
+ gpointer item);
+GLIB_AVAILABLE_IN_2_46
+gboolean g_async_queue_remove_unlocked (GAsyncQueue *queue,
+ gpointer item);
+GLIB_AVAILABLE_IN_2_46
+void g_async_queue_push_front (GAsyncQueue *queue,
+ gpointer item);
+GLIB_AVAILABLE_IN_2_46
+void g_async_queue_push_front_unlocked (GAsyncQueue *queue,
+ gpointer item);
+
GLIB_DEPRECATED_FOR(g_async_queue_timeout_pop)
gpointer g_async_queue_timed_pop (GAsyncQueue *queue,
GTimeVal *end_time);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]