mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-19 15:18:55 +02:00
GAsyncQueue: embed the GCond
Use g_cond_init/clear, now that we have them.
This commit is contained in:
@@ -94,7 +94,7 @@
|
|||||||
struct _GAsyncQueue
|
struct _GAsyncQueue
|
||||||
{
|
{
|
||||||
GMutex mutex;
|
GMutex mutex;
|
||||||
GCond *cond;
|
GCond cond;
|
||||||
GQueue queue;
|
GQueue queue;
|
||||||
GDestroyNotify item_free_func;
|
GDestroyNotify item_free_func;
|
||||||
guint waiting_threads;
|
guint waiting_threads;
|
||||||
@@ -139,7 +139,7 @@ g_async_queue_new_full (GDestroyNotify item_free_func)
|
|||||||
|
|
||||||
queue = g_new (GAsyncQueue, 1);
|
queue = g_new (GAsyncQueue, 1);
|
||||||
g_mutex_init (&queue->mutex);
|
g_mutex_init (&queue->mutex);
|
||||||
queue->cond = NULL;
|
g_cond_init (&queue->cond);
|
||||||
g_queue_init (&queue->queue);
|
g_queue_init (&queue->queue);
|
||||||
queue->waiting_threads = 0;
|
queue->waiting_threads = 0;
|
||||||
queue->ref_count = 1;
|
queue->ref_count = 1;
|
||||||
@@ -227,8 +227,7 @@ g_async_queue_unref (GAsyncQueue *queue)
|
|||||||
{
|
{
|
||||||
g_return_if_fail (queue->waiting_threads == 0);
|
g_return_if_fail (queue->waiting_threads == 0);
|
||||||
g_mutex_clear (&queue->mutex);
|
g_mutex_clear (&queue->mutex);
|
||||||
if (queue->cond)
|
g_cond_clear (&queue->cond);
|
||||||
g_cond_free (queue->cond);
|
|
||||||
if (queue->item_free_func)
|
if (queue->item_free_func)
|
||||||
g_queue_foreach (&queue->queue, (GFunc) queue->item_free_func, NULL);
|
g_queue_foreach (&queue->queue, (GFunc) queue->item_free_func, NULL);
|
||||||
g_queue_clear (&queue->queue);
|
g_queue_clear (&queue->queue);
|
||||||
@@ -313,7 +312,7 @@ g_async_queue_push_unlocked (GAsyncQueue *queue,
|
|||||||
|
|
||||||
g_queue_push_head (&queue->queue, data);
|
g_queue_push_head (&queue->queue, data);
|
||||||
if (queue->waiting_threads > 0)
|
if (queue->waiting_threads > 0)
|
||||||
g_cond_signal (queue->cond);
|
g_cond_signal (&queue->cond);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -400,7 +399,7 @@ g_async_queue_push_sorted_unlocked (GAsyncQueue *queue,
|
|||||||
(GCompareDataFunc)g_async_queue_invert_compare,
|
(GCompareDataFunc)g_async_queue_invert_compare,
|
||||||
&sd);
|
&sd);
|
||||||
if (queue->waiting_threads > 0)
|
if (queue->waiting_threads > 0)
|
||||||
g_cond_signal (queue->cond);
|
g_cond_signal (&queue->cond);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gpointer
|
static gpointer
|
||||||
@@ -415,21 +414,18 @@ g_async_queue_pop_intern_unlocked (GAsyncQueue *queue,
|
|||||||
if (try)
|
if (try)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (!queue->cond)
|
|
||||||
queue->cond = g_cond_new ();
|
|
||||||
|
|
||||||
if (!end_time)
|
if (!end_time)
|
||||||
{
|
{
|
||||||
queue->waiting_threads++;
|
queue->waiting_threads++;
|
||||||
while (!g_queue_peek_tail_link (&queue->queue))
|
while (!g_queue_peek_tail_link (&queue->queue))
|
||||||
g_cond_wait (queue->cond, &queue->mutex);
|
g_cond_wait (&queue->cond, &queue->mutex);
|
||||||
queue->waiting_threads--;
|
queue->waiting_threads--;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
queue->waiting_threads++;
|
queue->waiting_threads++;
|
||||||
while (!g_queue_peek_tail_link (&queue->queue))
|
while (!g_queue_peek_tail_link (&queue->queue))
|
||||||
if (!g_cond_timed_wait (queue->cond, &queue->mutex, end_time))
|
if (!g_cond_timed_wait (&queue->cond, &queue->mutex, end_time))
|
||||||
break;
|
break;
|
||||||
queue->waiting_threads--;
|
queue->waiting_threads--;
|
||||||
if (!g_queue_peek_tail_link (&queue->queue))
|
if (!g_queue_peek_tail_link (&queue->queue))
|
||||||
|
Reference in New Issue
Block a user