clover: Add a mutex to guard queue::queued_events
authorTom Stellard <thomas.stellard@amd.com>
Thu, 7 May 2015 13:57:14 +0000 (13:57 +0000)
committerTom Stellard <thomas.stellard@amd.com>
Mon, 11 May 2015 18:52:18 +0000 (18:52 +0000)
This fixes a potential crash where on a sequence like this:

Thread 0: Check if queue is not empty.
Thread 1: Remove item from queue, making it empty.
Thread 0: Do something assuming queue is not empty.

CC: 10.5 <mesa-stable@lists.freedesktop.org>
Reviewed-by: Francisco Jerez <currojerez@riseup.net>
src/gallium/state_trackers/clover/core/queue.cpp
src/gallium/state_trackers/clover/core/queue.hpp

index 24f9326662da17d390fe5cf28185b16d5ce3e01c..87f9dcc647624e26d29b7eb025f7f28a5a8094a3 100644 (file)
@@ -44,6 +44,7 @@ command_queue::flush() {
    pipe_screen *screen = device().pipe;
    pipe_fence_handle *fence = NULL;
 
+   std::lock_guard<std::mutex> lock(queued_events_mutex);
    if (!queued_events.empty()) {
       pipe->flush(pipe, &fence, 0);
 
@@ -69,6 +70,7 @@ command_queue::profiling_enabled() const {
 
 void
 command_queue::sequence(hard_event &ev) {
+   std::lock_guard<std::mutex> lock(queued_events_mutex);
    if (!queued_events.empty())
       queued_events.back()().chain(ev);
 
index b7166e685b75e50987546bfa868a9680f55616a4..bddb86c0e4c9c3acab1e2de94b3a5ccd5fbb89c0 100644 (file)
@@ -24,6 +24,7 @@
 #define CLOVER_CORE_QUEUE_HPP
 
 #include <deque>
+#include <mutex>
 
 #include "core/object.hpp"
 #include "core/context.hpp"
@@ -69,6 +70,7 @@ namespace clover {
 
       cl_command_queue_properties props;
       pipe_context *pipe;
+      std::mutex queued_events_mutex;
       std::deque<intrusive_ref<hard_event>> queued_events;
    };
 }