+2007-12-18 Tim-Philipp Müller <tim at centricular dot net>
+
+ * 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).
+
2007-12-18 13:45:23 Tim Janik <timj@imendio.com>
* glib/gtestutils.[hc]: added g_test_trap_assert_stdout_unmatched() and
GMutex *mutex;
GCond *cond;
GQueue *queue;
+ GDestroyNotify item_free_func;
guint waiting_threads;
gint32 ref_count;
};
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.
*
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);
}
/* Get a new GAsyncQueue with the ref_count 1 */
GAsyncQueue* g_async_queue_new (void);
+GAsyncQueue* g_async_queue_new_full (GDestroyNotify item_free_func);
+
/* Lock and unlock a GAsyncQueue. All functions lock the queue for
* themselves, but in certain cirumstances you want to hold the lock longer,
* thus you lock the queue, call the *_unlocked functions and unlock it again.