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