testclock: replace newly-added GstTestClockIDList structure with a simple GList

Keep it simple. Likely also makes things easier for bindings,
and efficiency clearly has not been a consideration given how
the existing code handled these lists.
This commit is contained in:
Tim-Philipp Müller 2014-04-12 15:22:35 +01:00
parent 2e4900ba94
commit ed9d0381b2
4 changed files with 37 additions and 79 deletions

View file

@ -107,8 +107,7 @@ LIBGSTCHECK_EXPORTED_FUNCS = \
gst_test_clock_get_next_entry_time \
gst_test_clock_wait_for_multiple_pending_ids \
gst_test_clock_process_id_list \
gst_test_clock_id_list_get_latest_time \
gst_test_clock_id_list_free
gst_test_clock_id_list_get_latest_time
LIBGSTCHECK_EXPORTED_SYMBOLS = \

View file

@ -624,24 +624,20 @@ process_entry_context_unlocked (GstTestClock * test_clock,
}
}
static GstTestClockIDList *
static GList *
gst_test_clock_get_pending_id_list_unlocked (GstTestClock * test_clock)
{
GstTestClockPrivate *priv = GST_TEST_CLOCK_GET_PRIVATE (test_clock);
GstTestClockIDList *result = g_new0 (GstTestClockIDList, 1);
if (priv->entry_contexts != NULL) {
GQueue queue = G_QUEUE_INIT;
GList *cur;
for (cur = priv->entry_contexts; cur != NULL; cur = cur->next) {
GstClockEntryContext *ctx = cur->data;
result->cur =
g_list_append (result->cur, gst_clock_id_ref (ctx->clock_entry));
g_queue_push_tail (&queue, gst_clock_id_ref (ctx->clock_entry));
}
}
result->length = g_list_length (result->cur);
return result;
return queue.head;
}
/**
@ -987,7 +983,9 @@ gst_test_clock_get_next_entry_time (GstTestClock * test_clock)
* gst_test_clock_wait_for_multiple_pending_ids:
* @test_clock: #GstTestClock for which to await having enough pending clock
* @count: the number of pending clock notifications to wait for
* @pending_list: A #GstTestClockIDList with pending #GstClockIDs
* @pending_list: (out) (element-type Gst.ClockID) (transfer full) (allow-none): Address
* of a #GList pointer variable to store the list of pending #GstClockIDs
* that expired, or NULL
*
* Blocks until at least @count clock notifications have been requested from
* @test_clock. There is no timeout for this wait, see the main description of
@ -999,7 +997,7 @@ gst_test_clock_get_next_entry_time (GstTestClock * test_clock)
*/
void
gst_test_clock_wait_for_multiple_pending_ids (GstTestClock * test_clock,
guint count, GstTestClockIDList ** pending_list)
guint count, GList ** pending_list)
{
GstTestClockPrivate *priv;
@ -1020,9 +1018,10 @@ gst_test_clock_wait_for_multiple_pending_ids (GstTestClock * test_clock,
/**
* gst_test_clock_process_id_list:
* @test_clock: #GstTestClock for which to process the pending IDs
* @pending_list: A #GstTestClockIDList with pending #GstClockIDs
* @pending_list: (element-type Gst.ClockID) (transfer none) (allow-none): List
* of pending #GstClockIDs
*
* Processes and releases the pending IDs in #GstTestClockIDList
* Processes and releases the pending IDs in the list.
*
* MT safe.
*
@ -1030,16 +1029,16 @@ gst_test_clock_wait_for_multiple_pending_ids (GstTestClock * test_clock,
*/
guint
gst_test_clock_process_id_list (GstTestClock * test_clock,
GstTestClockIDList * pending_list)
const GList * pending_list)
{
GList *cur;
const GList *cur;
guint result = 0;
g_return_val_if_fail (GST_IS_TEST_CLOCK (test_clock), 0);
GST_OBJECT_LOCK (test_clock);
for (cur = pending_list->cur; cur != NULL; cur = cur->next) {
for (cur = pending_list; cur != NULL; cur = cur->next) {
GstClockID pending_id = cur->data;
GstClockEntryContext *ctx =
gst_test_clock_lookup_entry_context (test_clock, pending_id);
@ -1055,21 +1054,22 @@ gst_test_clock_process_id_list (GstTestClock * test_clock,
/**
* gst_test_clock_id_list_get_latest_time:
* @pending_list: A #GstTestClockIDList with pending #GstClockIDs
* @pending_list: (element-type Gst.ClockID) (transfer none) (allow-none): List
* of of pending #GstClockIDs
*
* Finds the latest time inside the #GstTestClockIDList
* Finds the latest time inside the list.
*
* MT safe.
*
* Since: 1.4
*/
GstClockTime
gst_test_clock_id_list_get_latest_time (GstTestClockIDList * pending_list)
gst_test_clock_id_list_get_latest_time (const GList * pending_list)
{
GList *cur;
const GList *cur;
GstClockTime result = 0;
for (cur = pending_list->cur; cur != NULL; cur = cur->next) {
for (cur = pending_list; cur != NULL; cur = cur->next) {
GstClockID *pending_id = cur->data;
GstClockTime time = gst_clock_id_get_time (pending_id);
if (time > result)
@ -1078,27 +1078,3 @@ gst_test_clock_id_list_get_latest_time (GstTestClockIDList * pending_list)
return result;
}
/**
* gst_test_clock_id_list_free:
* @pending_list: A #GstTestClockIDList with pending #GstClockIDs
*
* Free the supplied #GstTestClockIDList
*
* MT safe.
*
* Since: 1.4
*/
void
gst_test_clock_id_list_free (GstTestClockIDList * pending_list)
{
GList *cur;
for (cur = pending_list->cur; cur != NULL; cur = cur->next) {
GstClockID *pending_id = cur->data;
gst_clock_id_unref (pending_id);
}
g_list_free (pending_list->cur);
g_free (pending_list);
}

View file

@ -45,8 +45,6 @@ typedef struct _GstTestClock GstTestClock;
typedef struct _GstTestClockClass GstTestClockClass;
typedef struct _GstTestClockPrivate GstTestClockPrivate;
typedef struct _GstTestClockIDList GstTestClockIDList;
/**
* GstTestClock:
*
@ -76,21 +74,6 @@ struct _GstTestClockClass
GstClockClass parent_class;
};
/**
* GstTestClockIDList:
* @cur: A #GList with all pending #GstClockID
* @length: A #guint with the length of the list
*
* A #GstTestClockIDList structure, which is returned when waiting for multiple IDs
*
* Since: 1.4
*/
struct _GstTestClockIDList
{
GList * cur;
guint length;
};
GType gst_test_clock_get_type (void);
GstClock * gst_test_clock_new (void);
@ -124,14 +107,12 @@ GstClockTime gst_test_clock_get_next_entry_time (GstTestClock * test_clock);
void gst_test_clock_wait_for_multiple_pending_ids (GstTestClock * test_clock,
guint count,
GstTestClockIDList ** pending_list);
GList ** pending_list);
guint gst_test_clock_process_id_list (GstTestClock * test_clock,
GstTestClockIDList * pending_list);
const GList * pending_list);
GstClockTime gst_test_clock_id_list_get_latest_time (GstTestClockIDList * list);
void gst_test_clock_id_list_free (GstTestClockIDList * list);
GstClockTime gst_test_clock_id_list_get_latest_time (const GList * pending_list);
G_END_DECLS

View file

@ -690,6 +690,7 @@ GST_START_TEST (test_single_shot_sync_simultaneous_no_timeout)
gst_object_unref (clock);
}
GST_END_TEST;
GST_START_TEST (test_processing_multiple_ids)
@ -702,7 +703,7 @@ GST_START_TEST (test_processing_multiple_ids)
SyncClockWaitContext context_b;
GThread *worker_thread_a;
GThread *worker_thread_b;
GstTestClockIDList * pending_list;
GList *pending_list = NULL;
clock = gst_test_clock_new_with_start_time (GST_SECOND);
test_clock = GST_TEST_CLOCK (clock);
@ -727,10 +728,10 @@ GST_START_TEST (test_processing_multiple_ids)
gst_test_clock_wait_for_multiple_pending_ids (test_clock, 2, &pending_list);
/* assert they are correct */
assert_pending_id (pending_list->cur->data, clock_id_a, GST_CLOCK_ENTRY_SINGLE,
assert_pending_id (pending_list->data, clock_id_a, GST_CLOCK_ENTRY_SINGLE,
5 * GST_SECOND);
assert_pending_id (pending_list->cur->next->data, clock_id_b, GST_CLOCK_ENTRY_SINGLE,
6 * GST_SECOND);
assert_pending_id (pending_list->next->data, clock_id_b,
GST_CLOCK_ENTRY_SINGLE, 6 * GST_SECOND);
/* verify we are waiting for 6 seconds as the latest time */
fail_unless_equals_int64 (6 * GST_SECOND,
@ -738,7 +739,7 @@ GST_START_TEST (test_processing_multiple_ids)
/* process both ID's at the same time */
gst_test_clock_process_id_list (test_clock, pending_list);
gst_test_clock_id_list_free (pending_list);
g_list_free_full (pending_list, (GDestroyNotify) gst_clock_id_unref);
g_thread_join (worker_thread_a);
g_thread_join (worker_thread_b);
@ -754,6 +755,7 @@ GST_START_TEST (test_processing_multiple_ids)
gst_object_unref (clock);
}
GST_END_TEST;
GST_START_TEST (test_single_shot_async_past)