Commit d3d977cb authored by Julian Bouzas's avatar Julian Bouzas
Browse files

config-policy: add timeout when waiting on conditional variables

parent c56209fa
......@@ -71,6 +71,8 @@ loop_thread_start (void *d)
static void
config_policy_setup (TestConfigPolicyFixture *self, gconstpointer user_data)
{
gint64 end_time;
/* Data */
g_mutex_init (&self->mutex);
g_cond_init (&self->cond);
......@@ -81,8 +83,13 @@ config_policy_setup (TestConfigPolicyFixture *self, gconstpointer user_data)
/* Wait for everything to be created */
g_mutex_lock (&self->mutex);
end_time = g_get_monotonic_time () + 3 * G_TIME_SPAN_SECOND;
while (!self->created)
g_cond_wait (&self->cond, &self->mutex);
if (!g_cond_wait_until (&self->cond, &self->mutex, end_time)) {
/* Abort when timeout has passed */
g_warning ("Aborting due to timeout when waiting for connection");
abort();
}
g_mutex_unlock (&self->mutex);
}
......
......@@ -39,11 +39,17 @@ G_DEFINE_TYPE (WpConfigPolicyContext, wp_config_policy_context, G_TYPE_OBJECT);
static WpBaseEndpoint *
wait_for_endpoint (WpConfigPolicyContext *self, WpBaseEndpointLink **link)
{
gint64 end_time;
g_mutex_lock (&self->mutex);
/* Wait for endpoint to be set */
end_time = g_get_monotonic_time () + 3 * G_TIME_SPAN_SECOND;
while (!self->endpoint)
g_cond_wait (&self->cond, &self->mutex);
if (!g_cond_wait_until (&self->cond, &self->mutex, end_time)) {
/* Abort when timeout has passed */
g_warning ("Aborting due to timeout when waiting for endpoint");
abort();
}
/* Set endpoint to a local value and clear global value */
WpBaseEndpoint *endpoint = g_object_ref (self->endpoint);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment