Skip to content
Snippets Groups Projects
Commit 2355b71e authored by Guillaume Roguez's avatar Guillaume Roguez Committed by Tristan Matthews
Browse files

gnome: remove semaphore timed operation in video renderer.

The sem_timedwait() is replaced by a sem_trywait().
This patch seems also to resolve other --timeout-- bugs seen in the daemon.

This code is run by the main GUI event loop,
so never do locking stuff into it.

Change-Id: I4b68e6ec4527f67728a509701f5076c81dc35148
parent 10ef6c38
No related branches found
No related tags found
No related merge requests found
......@@ -226,30 +226,13 @@ video_renderer_start_shm(VideoRenderer *self)
return TRUE;
}
static const gint TIMEOUT_SEC = 1; // 1 second
static struct timespec
create_timeout()
{
struct timespec timeout = {0, 0};
if (clock_gettime(CLOCK_REALTIME, &timeout) == -1)
perror("clock_gettime");
timeout.tv_sec += TIMEOUT_SEC;
return timeout;
}
static gboolean
shm_lock(SHMHeader *shm_area)
{
const struct timespec timeout = create_timeout();
/* We need an upper limit on how long we'll wait to avoid locking the whole GUI */
if (sem_timedwait(&shm_area->mutex, &timeout) < 0) {
g_warning("%s", g_strerror(errno));
if (errno == ETIMEDOUT)
return FALSE;
}
return TRUE;
int err = sem_trywait(&shm_area->mutex);
if (err < 0 && errno != EAGAIN)
g_warning("Renderer: sem_trywait() failed, %s", strerror(errno));
return !err;
}
static void
......@@ -295,11 +278,12 @@ video_renderer_render_to_texture(VideoRendererPrivate *priv)
// wait for a new buffer
while (priv->buffer_gen == priv->shm_area->buffer_gen) {
shm_unlock(priv->shm_area);
const struct timespec timeout = create_timeout();
// Could not decrement semaphore in time, returning
if (sem_timedwait(&priv->shm_area->notification, &timeout) < 0) {
if (errno == ETIMEDOUT)
g_warning("Renderer %s timed out waiting for notification", priv->shm_path);
// Could not decrement semaphore, returning
int err = sem_trywait(&priv->shm_area->notification);
if (err < 0) {
if (errno != EAGAIN)
g_warning("Renderer %s: sem_trywait() failed, %s", priv->shm_path,
strerror(errno));
return;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment