mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-27 06:26:15 +01:00
Lazy creation of GCond. Only signal GCond, if threads are waiting.
2004-02-18 Sebastian Wilhelmi <seppi@seppi.de> * glib/gasyncqueue.c: Lazy creation of GCond. Only signal GCond, if threads are waiting.
This commit is contained in:
parent
1a2b93f361
commit
265c78b9df
@ -50,7 +50,7 @@ g_async_queue_new ()
|
|||||||
{
|
{
|
||||||
GAsyncQueue* retval = g_new (GAsyncQueue, 1);
|
GAsyncQueue* retval = g_new (GAsyncQueue, 1);
|
||||||
retval->mutex = g_mutex_new ();
|
retval->mutex = g_mutex_new ();
|
||||||
retval->cond = g_cond_new ();
|
retval->cond = NULL;
|
||||||
retval->queue = g_queue_new ();
|
retval->queue = g_queue_new ();
|
||||||
retval->waiting_threads = 0;
|
retval->waiting_threads = 0;
|
||||||
retval->ref_count = 1;
|
retval->ref_count = 1;
|
||||||
@ -119,7 +119,8 @@ g_async_queue_unref_and_unlock (GAsyncQueue *queue)
|
|||||||
{
|
{
|
||||||
g_return_if_fail (queue->waiting_threads == 0);
|
g_return_if_fail (queue->waiting_threads == 0);
|
||||||
g_mutex_free (queue->mutex);
|
g_mutex_free (queue->mutex);
|
||||||
g_cond_free (queue->cond);
|
if (queue->cond)
|
||||||
|
g_cond_free (queue->cond);
|
||||||
g_queue_free (queue->queue);
|
g_queue_free (queue->queue);
|
||||||
g_free (queue);
|
g_free (queue);
|
||||||
}
|
}
|
||||||
@ -211,7 +212,8 @@ g_async_queue_push_unlocked (GAsyncQueue* queue, gpointer data)
|
|||||||
g_return_if_fail (data);
|
g_return_if_fail (data);
|
||||||
|
|
||||||
g_queue_push_head (queue->queue, data);
|
g_queue_push_head (queue->queue, data);
|
||||||
g_cond_signal (queue->cond);
|
if (queue->waiting_threads > 0)
|
||||||
|
g_cond_signal (queue->cond);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gpointer
|
static gpointer
|
||||||
@ -224,6 +226,10 @@ g_async_queue_pop_intern_unlocked (GAsyncQueue* queue, gboolean try,
|
|||||||
{
|
{
|
||||||
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++;
|
||||||
|
Loading…
Reference in New Issue
Block a user