mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-07-25 03:17:52 +02:00
add g_async_queue_new_full() which takes a GDestroyNotify function to free
* docs/reference/glib/glib-sections.txt: * glib/gasyncqueue.c: (g_async_queue_new), (g_async_queue_new_full), (g_async_queue_unref): * glib/gasyncqueue.h: add g_async_queue_new_full() which takes a GDestroyNotify function to free any remaining queue items when the queue is destroyed after the final atomic unref (#367550). svn path=/trunk/; revision=6152
This commit is contained in:
@@ -35,6 +35,7 @@ struct _GAsyncQueue
|
||||
GMutex *mutex;
|
||||
GCond *cond;
|
||||
GQueue *queue;
|
||||
GDestroyNotify item_free_func;
|
||||
guint waiting_threads;
|
||||
gint32 ref_count;
|
||||
};
|
||||
@@ -60,9 +61,29 @@ g_async_queue_new (void)
|
||||
retval->queue = g_queue_new ();
|
||||
retval->waiting_threads = 0;
|
||||
retval->ref_count = 1;
|
||||
retval->item_free_func = NULL;
|
||||
return retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_async_queue_new_full:
|
||||
*
|
||||
* Creates a new asynchronous queue with an initial reference count of 1 and
|
||||
* sets up a destroy notify function that is used to free any remaining
|
||||
* queue items when the queue is destroyed after the final unref.
|
||||
*
|
||||
* Return value: the new #GAsyncQueue.
|
||||
*
|
||||
* Since: 2.16
|
||||
**/
|
||||
GAsyncQueue*
|
||||
g_async_queue_new_full (GDestroyNotify item_free_func)
|
||||
{
|
||||
GAsyncQueue *async_queue = g_async_queue_new ();
|
||||
async_queue->item_free_func = item_free_func;
|
||||
return async_queue;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_async_queue_ref:
|
||||
* @queue: a #GAsyncQueue.
|
||||
@@ -147,6 +168,8 @@ g_async_queue_unref (GAsyncQueue *queue)
|
||||
g_mutex_free (queue->mutex);
|
||||
if (queue->cond)
|
||||
g_cond_free (queue->cond);
|
||||
if (queue->item_free_func)
|
||||
g_queue_foreach (queue->queue, (GFunc) queue->item_free_func, NULL);
|
||||
g_queue_free (queue->queue);
|
||||
g_free (queue);
|
||||
}
|
||||
|
Reference in New Issue
Block a user