gallium/u_queue: guard fence->signalled checks with fence->mutex
authorNicolai Hähnle <nicolai.haehnle@amd.com>
Sat, 9 Jul 2016 17:40:51 +0000 (19:40 +0200)
committerNicolai Hähnle <nicolai.haehnle@amd.com>
Mon, 11 Jul 2016 09:03:59 +0000 (11:03 +0200)
I have seen a hang during application shutdown that could be explained by the
following race condition which this patch fixes:

1. Worker thread enters util_queue_fence_signal, sets fence->signalled = true.
2. Main thread calls util_queue_job_wait, which returns immediately.
3. Main thread deletes the job and fence structures, leaving garbage behind.
4. Worker thread calls pipe_condvar_broadcast, which gets stuck forever because
   it is accessing garbage.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Reviewed-by: Edward O'Callaghan <funfunctor@folklore1984.net>
src/gallium/auxiliary/util/u_queue.c

index 627c08a524ae09a60634ef8762cabcd0e407b7af..24293367ec8c87016c70b6ef696db033e3b70e03 100644 (file)
@@ -41,9 +41,6 @@ util_queue_fence_signal(struct util_queue_fence *fence)
 void
 util_queue_job_wait(struct util_queue_fence *fence)
 {
-   if (fence->signalled)
-      return;
-
    pipe_mutex_lock(fence->mutex);
    while (!fence->signalled)
       pipe_condvar_wait(fence->cond, fence->mutex);