{
gpointer ret;
g_return_val_if_fail (array != NULL, NULL);
+
/* empty array */
if (G_UNLIKELY (array->length == 0))
return NULL;
gst_queue_array_push_tail (GstQueueArray * array, gpointer data)
{
g_return_if_fail (array != NULL);
+
/* Check if we need to make room */
if (G_UNLIKELY (array->length == array->size))
gst_queue_array_do_expand (array);
}
/**
+ * gst_queue_array_peek_tail: (skip)
+ * @array: a #GstQueueArray object
+ *
+ * Returns the tail of the queue @array, but does not remove it from the queue.
+ *
+ * Returns: The tail of the queue
+ *
+ * Since: 1.14
+ */
+gpointer
+gst_queue_array_peek_tail (GstQueueArray * array)
+{
+ guint len, idx;
+
+ g_return_val_if_fail (array != NULL, NULL);
+
+ len = array->length;
+
+ /* empty array */
+ if (len == 0)
+ return NULL;
+
+ idx = (array->head + (len - 1)) % array->size;
+
+ return *(gpointer *) (array->array + (sizeof (gpointer) * idx));
+}
+
+/**
+ * gst_queue_array_pop_tail: (skip)
+ * @array: a #GstQueueArray object
+ *
+ * Returns the tail of the queue @array and removes
+ * it from the queue.
+ *
+ * Returns: The tail of the queue
+ *
+ * Since: 1.14
+ */
+gpointer
+gst_queue_array_pop_tail (GstQueueArray * array)
+{
+ gpointer ret;
+ guint len, idx;
+
+ g_return_val_if_fail (array != NULL, NULL);
+
+ len = array->length;
+
+ /* empty array */
+ if (len == 0)
+ return NULL;
+
+ idx = (array->head + (len - 1)) % array->size;
+
+ ret = *(gpointer *) (array->array + (sizeof (gpointer) * idx));
+
+ array->tail = idx;
+ array->length--;
+
+ return ret;
+}
+
+/**
* gst_queue_array_is_empty: (skip)
* @array: a #GstQueueArray object
*
GST_END_TEST;
+GST_START_TEST (test_array_peek_pop_tail)
+{
+ const guint array_sizes[] = { 0, 1, 2, 5 };
+ guint s;
+
+ for (s = 0; s < G_N_ELEMENTS (array_sizes); ++s) {
+ GstQueueArray *array;
+
+ GST_INFO ("Testing with initial size %u", array_sizes[s]);
+
+ array = gst_queue_array_new (array_sizes[s]);
+ fail_unless_equals_int (gst_queue_array_get_length (array), 0);
+
+ fail_unless (gst_queue_array_peek_tail (array) == NULL);
+ fail_unless (gst_queue_array_pop_tail (array) == NULL);
+
+ gst_queue_array_push_tail (array, GINT_TO_POINTER (42));
+ fail_unless_equals_int (gst_queue_array_get_length (array), 1);
+ fail_unless (gst_queue_array_peek_tail (array) == GINT_TO_POINTER (42));
+ fail_unless (gst_queue_array_peek_head (array) == GINT_TO_POINTER (42));
+ fail_unless_equals_int (gst_queue_array_get_length (array), 1);
+ fail_unless (gst_queue_array_pop_tail (array) == GINT_TO_POINTER (42));
+ fail_unless_equals_int (gst_queue_array_get_length (array), 0);
+
+ gst_queue_array_push_tail (array, GINT_TO_POINTER (42));
+ fail_unless_equals_int (gst_queue_array_get_length (array), 1);
+ fail_unless (gst_queue_array_pop_head (array) == GINT_TO_POINTER (42));
+ fail_unless_equals_int (gst_queue_array_get_length (array), 0);
+ fail_unless (gst_queue_array_peek_tail (array) == NULL);
+ fail_unless (gst_queue_array_pop_tail (array) == NULL);
+
+ gst_queue_array_push_tail (array, GINT_TO_POINTER (43));
+ gst_queue_array_push_tail (array, GINT_TO_POINTER (44));
+
+ fail_unless_equals_int (gst_queue_array_get_length (array), 2);
+ fail_unless_equals_int (GPOINTER_TO_INT (gst_queue_array_peek_head (array)),
+ 43);
+ fail_unless_equals_int (GPOINTER_TO_INT (gst_queue_array_peek_tail (array)),
+ 44);
+ fail_unless_equals_int (gst_queue_array_get_length (array), 2);
+ fail_unless (gst_queue_array_pop_tail (array) == GINT_TO_POINTER (44));
+ fail_unless_equals_int (gst_queue_array_get_length (array), 1);
+ fail_unless (gst_queue_array_peek_head (array) == GINT_TO_POINTER (43));
+ fail_unless (gst_queue_array_peek_tail (array) == GINT_TO_POINTER (43));
+ fail_unless_equals_int (gst_queue_array_get_length (array), 1);
+
+ gst_queue_array_free (array);
+ }
+}
+
+GST_END_TEST;
+
static Suite *
gst_queue_array_suite (void)
{
tcase_add_test (tc_chain, test_array_grow_end);
tcase_add_test (tc_chain, test_array_drop2);
tcase_add_test (tc_chain, test_array_grow_from_prealloc1);
+ tcase_add_test (tc_chain, test_array_peek_pop_tail);
return s;
}