mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-02-20 13:06:23 +00:00
harness: improve _wait_for_clock_id_waits performance
By moving the functionality down to the testclock, the implementation no longer needs to poll the waits, but rather wait properly for them to be added. The performance-hit here would be that by polling the test-clock regularly, you would create contention on the testclock-lock, making code using the testclock (gst_clock_id_wait) fighting for the lock.
This commit is contained in:
parent
c6e5f59b2c
commit
fa34768729
3 changed files with 58 additions and 18 deletions
|
@ -1364,30 +1364,15 @@ gst_harness_set_time (GstHarness * h, GstClockTime time)
|
|||
* MT safe.
|
||||
*
|
||||
* Returns: a @gboolean %TRUE if the waits have been registered, %FALSE if not.
|
||||
* (Could be that it timed out waiting or that more waits then waits was found)
|
||||
* (Could be that it timed out waiting or that more waits than waits was found)
|
||||
*
|
||||
* Since: 1.6
|
||||
*/
|
||||
gboolean
|
||||
gst_harness_wait_for_clock_id_waits (GstHarness * h, guint waits, guint timeout)
|
||||
{
|
||||
GstTestClock *testclock = h->priv->testclock;
|
||||
gint64 start_time;
|
||||
gboolean ret;
|
||||
|
||||
start_time = g_get_monotonic_time ();
|
||||
while (gst_test_clock_peek_id_count (testclock) < waits) {
|
||||
gint64 time_spent;
|
||||
|
||||
g_usleep (G_USEC_PER_SEC / 1000);
|
||||
time_spent = g_get_monotonic_time () - start_time;
|
||||
if ((time_spent / G_USEC_PER_SEC) > timeout)
|
||||
break;
|
||||
}
|
||||
|
||||
ret = (waits == gst_test_clock_peek_id_count (testclock));
|
||||
|
||||
return ret;
|
||||
return gst_test_clock_timed_wait_for_multiple_pending_ids (h->priv->testclock,
|
||||
waits, timeout * 1000, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1034,6 +1034,55 @@ gst_test_clock_wait_for_multiple_pending_ids (GstTestClock * test_clock,
|
|||
GST_OBJECT_UNLOCK (test_clock);
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_test_clock_timed_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
|
||||
* @timeout_ms: the timeout in milliseconds
|
||||
* @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, or the timeout expires.
|
||||
*
|
||||
* MT safe.
|
||||
*
|
||||
* Returns: a @gboolean %TRUE if the waits have been registered, %FALSE if not.
|
||||
* (Could be that it timed out waiting or that more waits than waits was found)
|
||||
*
|
||||
* Since: 1.16
|
||||
*/
|
||||
gboolean
|
||||
gst_test_clock_timed_wait_for_multiple_pending_ids (GstTestClock * test_clock,
|
||||
guint count, guint timeout_ms, GList ** pending_list)
|
||||
{
|
||||
GstTestClockPrivate *priv;
|
||||
gint64 timeout = g_get_monotonic_time () +
|
||||
timeout_ms * (G_USEC_PER_SEC / 1000);
|
||||
gboolean ret;
|
||||
|
||||
g_return_val_if_fail (GST_IS_TEST_CLOCK (test_clock), FALSE);
|
||||
priv = GST_TEST_CLOCK_GET_PRIVATE (test_clock);
|
||||
|
||||
GST_OBJECT_LOCK (test_clock);
|
||||
|
||||
while (g_list_length (priv->entry_contexts) < count &&
|
||||
g_get_monotonic_time () < timeout) {
|
||||
g_cond_wait_until (&priv->entry_added_cond,
|
||||
GST_OBJECT_GET_LOCK (test_clock), timeout);
|
||||
}
|
||||
|
||||
if (pending_list)
|
||||
*pending_list = gst_test_clock_get_pending_id_list_unlocked (test_clock);
|
||||
|
||||
ret = (g_list_length (priv->entry_contexts) == count);
|
||||
|
||||
GST_OBJECT_UNLOCK (test_clock);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_test_clock_process_id_list:
|
||||
* @test_clock: #GstTestClock for which to process the pending IDs
|
||||
|
|
|
@ -121,6 +121,12 @@ void gst_test_clock_wait_for_multiple_pending_ids (GstTestClock * test_
|
|||
guint count,
|
||||
GList ** pending_list);
|
||||
|
||||
GST_CHECK_API
|
||||
gboolean gst_test_clock_timed_wait_for_multiple_pending_ids (GstTestClock * test_clock,
|
||||
guint count,
|
||||
guint timeout_ms,
|
||||
GList ** pending_list);
|
||||
|
||||
GST_CHECK_API
|
||||
guint gst_test_clock_process_id_list (GstTestClock * test_clock,
|
||||
const GList * pending_list);
|
||||
|
|
Loading…
Reference in a new issue