radeon/winsys: fix handling in radeon_drm_cs_flush v2
authorChristian König <christian.koenig@amd.com>
Mon, 7 Oct 2013 10:08:29 +0000 (12:08 +0200)
committerChristian König <christian.koenig@amd.com>
Thu, 10 Oct 2013 09:50:38 +0000 (11:50 +0200)
Calling radeon_drm_cs_flush from multiple threads might cause deadlocks,
fix this by immediately signaling the semaphore after waiting for it.

This is a candidate for the stable branch(es).

Partially fixes: https://bugs.freedesktop.org/show_bug.cgi?id=70123

v2: some fixes on commit message

Signed-off-by: Christian König <christian.koenig@amd.com>
src/gallium/winsys/radeon/drm/radeon_drm_cs.c
src/gallium/winsys/radeon/drm/radeon_drm_cs.h

index 62f77044b3a378cf878deee87f82144bae65a0ae..0782e10c800f321e2742aa45e87ba058bc68239d 100644 (file)
@@ -178,7 +178,7 @@ static struct radeon_winsys_cs *radeon_drm_cs_create(struct radeon_winsys *rws,
     if (!cs) {
         return NULL;
     }
-    pipe_semaphore_init(&cs->flush_completed, 0);
+    pipe_semaphore_init(&cs->flush_completed, 1);
 
     cs->ws = ws;
     cs->trace_buf = (struct radeon_bo*)trace_buf;
@@ -453,9 +453,9 @@ void radeon_drm_cs_sync_flush(struct radeon_winsys_cs *rcs)
     struct radeon_drm_cs *cs = radeon_drm_cs(rcs);
 
     /* Wait for any pending ioctl to complete. */
-    if (cs->ws->thread && cs->flush_started) {
+    if (cs->ws->thread) {
         pipe_semaphore_wait(&cs->flush_completed);
-        cs->flush_started = 0;
+        pipe_semaphore_signal(&cs->flush_completed);
     }
 }
 
@@ -567,7 +567,7 @@ static void radeon_drm_cs_flush(struct radeon_winsys_cs *rcs, unsigned flags, ui
         }
 
         if (cs->ws->thread) {
-            cs->flush_started = 1;
+            pipe_semaphore_wait(&cs->flush_completed);
             radeon_drm_ws_queue_cs(cs->ws, cs);
             if (!(flags & RADEON_FLUSH_ASYNC))
                 radeon_drm_cs_sync_flush(rcs);
index 7683e96f525df5a1d2dcbc6037d621924f1be939..ebec161c540b08cef5785e7f09e2e7f2c6f24771 100644 (file)
@@ -76,7 +76,6 @@ struct radeon_drm_cs {
     void (*flush_cs)(void *ctx, unsigned flags);
     void *flush_data;
 
-    int flush_started;
     pipe_semaphore flush_completed;
     struct radeon_bo                    *trace_buf;
 };