Events can be added to an OpenCL command queue concurrently from multiple
threads, but pipe_context bjects are not threadsafe.  The threadsafe
wrappers protect all pipe_context function calls with a mutex, so we
can safely use them with multiple threads.

v2:
  - Don't use wrapper for pipe_screen.

CC: 10.6 <mesa-sta...@lists.freedesktop.org>
---
 src/gallium/state_trackers/clover/core/queue.cpp | 2 ++
 src/gallium/targets/opencl/Makefile.am           | 4 +++-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/gallium/state_trackers/clover/core/queue.cpp 
b/src/gallium/state_trackers/clover/core/queue.cpp
index 87f9dcc..16b089c 100644
--- a/src/gallium/state_trackers/clover/core/queue.cpp
+++ b/src/gallium/state_trackers/clover/core/queue.cpp
@@ -24,6 +24,7 @@
 #include "core/event.hpp"
 #include "pipe/p_screen.h"
 #include "pipe/p_context.h"
+#include "threadsafe/threadsafe.h"
 
 using namespace clover;
 
@@ -33,6 +34,7 @@ command_queue::command_queue(clover::context &ctx, 
clover::device &dev,
    pipe = dev.pipe->context_create(dev.pipe, NULL);
    if (!pipe)
       throw error(CL_INVALID_DEVICE);
+   pipe = pipe_threadsafe_context(pipe);
 }
 
 command_queue::~command_queue() {
diff --git a/src/gallium/targets/opencl/Makefile.am 
b/src/gallium/targets/opencl/Makefile.am
index 70e60e2..be5a59d 100644
--- a/src/gallium/targets/opencl/Makefile.am
+++ b/src/gallium/targets/opencl/Makefile.am
@@ -16,6 +16,7 @@ endif
 
 lib@OPENCL_LIBNAME@_la_LIBADD = \
        
$(top_builddir)/src/gallium/auxiliary/pipe-loader/libpipe_loader_client.la \
+       $(top_builddir)/src/gallium/drivers/threadsafe/libthreadsafe.la \
        $(top_builddir)/src/gallium/state_trackers/clover/libclover.la \
        $(top_builddir)/src/gallium/auxiliary/libgallium.la \
        $(top_builddir)/src/util/libmesautil.la \
@@ -36,7 +37,8 @@ lib@OPENCL_LIBNAME@_la_LIBADD = \
        -lclangEdit \
        -lclangLex \
        -lclangBasic \
-       $(LLVM_LIBS)
+       $(LLVM_LIBS) \
+       $(PTHREAD_LIBS)
 
 nodist_EXTRA_lib@OPENCL_LIBNAME@_la_SOURCES = dummy.cpp
 lib@OPENCL_LIBNAME@_la_SOURCES =
-- 
2.0.4

_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to