mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-06-23 04:34:51 +02:00
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
This commit is contained in:
parent
5574315b52
commit
b662c6f09f
@ -839,6 +839,8 @@ g_async_queue_ref
|
|||||||
g_async_queue_unref
|
g_async_queue_unref
|
||||||
g_async_queue_push
|
g_async_queue_push
|
||||||
g_async_queue_push_sorted
|
g_async_queue_push_sorted
|
||||||
|
g_async_queue_push_front
|
||||||
|
g_async_queue_remove
|
||||||
g_async_queue_pop
|
g_async_queue_pop
|
||||||
g_async_queue_try_pop
|
g_async_queue_try_pop
|
||||||
g_async_queue_timeout_pop
|
g_async_queue_timeout_pop
|
||||||
@ -852,6 +854,8 @@ g_async_queue_ref_unlocked
|
|||||||
g_async_queue_unref_and_unlock
|
g_async_queue_unref_and_unlock
|
||||||
g_async_queue_push_unlocked
|
g_async_queue_push_unlocked
|
||||||
g_async_queue_push_sorted_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_pop_unlocked
|
||||||
g_async_queue_try_pop_unlocked
|
g_async_queue_try_pop_unlocked
|
||||||
g_async_queue_timeout_pop_unlocked
|
g_async_queue_timeout_pop_unlocked
|
||||||
|
@ -785,6 +785,106 @@ g_async_queue_sort_unlocked (GAsyncQueue *queue,
|
|||||||
&sd);
|
&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
|
* Private API
|
||||||
*/
|
*/
|
||||||
|
@ -97,6 +97,19 @@ void g_async_queue_sort_unlocked (GAsyncQueue *queue,
|
|||||||
GCompareDataFunc func,
|
GCompareDataFunc func,
|
||||||
gpointer user_data);
|
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)
|
GLIB_DEPRECATED_FOR(g_async_queue_timeout_pop)
|
||||||
gpointer g_async_queue_timed_pop (GAsyncQueue *queue,
|
gpointer g_async_queue_timed_pop (GAsyncQueue *queue,
|
||||||
GTimeVal *end_time);
|
GTimeVal *end_time);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user