[Mesa-dev] [PATCH 4/5] clover: Add a mutex to guard queue::queued_events

Francisco Jerez currojerez at riseup.net
Fri May 8 15:06:47 PDT 2015


Tom Stellard <thomas.stellard at amd.com> writes:

> 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.
> ---
>  src/gallium/state_trackers/clover/core/queue.cpp | 2 ++
>  src/gallium/state_trackers/clover/core/queue.hpp | 2 ++
>  2 files changed, 4 insertions(+)
>
> diff --git a/src/gallium/state_trackers/clover/core/queue.cpp b/src/gallium/state_trackers/clover/core/queue.cpp
> index 24f9326..87f9dcc 100644
> --- a/src/gallium/state_trackers/clover/core/queue.cpp
> +++ b/src/gallium/state_trackers/clover/core/queue.cpp
> @@ -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);
>  
> diff --git a/src/gallium/state_trackers/clover/core/queue.hpp b/src/gallium/state_trackers/clover/core/queue.hpp
> index b7166e6..bddb86c 100644
> --- a/src/gallium/state_trackers/clover/core/queue.hpp
> +++ b/src/gallium/state_trackers/clover/core/queue.hpp
> @@ -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;
>     };
>  }
> -- 
> 2.0.4

Thanks, this patch is:
Reviewed-by: Francisco Jerez <currojerez at riseup.net>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 212 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20150509/8fe481af/attachment.sig>


More information about the mesa-dev mailing list