llvmpipe: Avoid deadlock when unloading opengl32.dll
authorJosé Fonseca <jfonseca@vmware.com>
Fri, 7 Nov 2014 16:15:43 +0000 (16:15 +0000)
committerJosé Fonseca <jfonseca@vmware.com>
Fri, 7 Nov 2014 21:00:06 +0000 (21:00 +0000)
On Windows, DllMain calls and thread creation/destruction are
serialized, so when llvmpipe is destroyed from DllMain waiting for the
rasterizer threads to finish will deadlock.

So, instead of waiting for rasterizer threads to have finished, simply wait for the
rasterizer threads to notify they are just about to finish.

Verified with this very simple program:

   #include <windows.h>
   int main() {
      HMODULE hModule = LoadLibraryA("opengl32.dll");
      FreeLibrary(hModule);
   }

Fixes https://bugs.freedesktop.org/show_bug.cgi?id=76252

Reviewed-by: Roland Scheidegger <sroland@vmware.com>
Cc: 10.2 10.3 <mesa-stable@lists.freedesktop.org>
src/gallium/drivers/llvmpipe/lp_rast.c

index a3420a21fbf373876bc432a413d64293aecf789c..6b54d4374f75b711f9a93b40533654a9a9532e32 100644 (file)
@@ -800,6 +800,8 @@ static PIPE_THREAD_ROUTINE( thread_function, init_data )
       pipe_semaphore_signal(&task->work_done);
    }
 
+   pipe_semaphore_signal(&task->work_done);
+
    return 0;
 }
 
@@ -885,9 +887,11 @@ void lp_rast_destroy( struct lp_rasterizer *rast )
       pipe_semaphore_signal(&rast->tasks[i].work_ready);
    }
 
-   /* Wait for threads to terminate before cleaning up per-thread data */
+   /* Wait for threads to terminate before cleaning up per-thread data.
+    * We don't actually call pipe_thread_wait to avoid dead lock on Windows
+    * per https://bugs.freedesktop.org/show_bug.cgi?id=76252 */
    for (i = 0; i < rast->num_threads; i++) {
-      pipe_thread_wait(rast->threads[i]);
+      pipe_semaphore_wait(&rast->tasks[i].work_done);
    }
 
    /* Clean up per-thread data */