[Mesa-dev] [PATCH 5/5] clover: Add a mutex to guard event::chain and event::wait_count
Tom Stellard
thomas.stellard at amd.com
Thu May 7 16:36:58 PDT 2015
This mutex effectively prevents an event's chain or wait_count from
being updated while it is in the process of triggering. Otherwise it
may be possible to add to an event's chain after it has been triggered,
which causes the chained event to never be triggered.
---
src/gallium/state_trackers/clover/core/event.cpp | 3 +++
src/gallium/state_trackers/clover/core/event.hpp | 1 +
2 files changed, 4 insertions(+)
diff --git a/src/gallium/state_trackers/clover/core/event.cpp b/src/gallium/state_trackers/clover/core/event.cpp
index da227bb..646fd38 100644
--- a/src/gallium/state_trackers/clover/core/event.cpp
+++ b/src/gallium/state_trackers/clover/core/event.cpp
@@ -38,6 +38,7 @@ event::~event() {
void
event::trigger() {
+ std::lock_guard<std::mutex> lock(trigger_mutex);
if (!--wait_count) {
signalled_cv.notify_all();
action_ok(*this);
@@ -54,6 +55,7 @@ event::abort(cl_int status) {
_status = status;
action_fail(*this);
+ std::lock_guard<std::mutex> lock(trigger_mutex);
while (!_chain.empty()) {
_chain.back()().abort(status);
_chain.pop_back();
@@ -67,6 +69,7 @@ event::signalled() const {
void
event::chain(event &ev) {
+ std::lock_guard<std::mutex> lock(trigger_mutex);
if (!signalled()) {
ev.wait_count++;
_chain.push_back(ev);
diff --git a/src/gallium/state_trackers/clover/core/event.hpp b/src/gallium/state_trackers/clover/core/event.hpp
index dffafb9..a64fbba 100644
--- a/src/gallium/state_trackers/clover/core/event.hpp
+++ b/src/gallium/state_trackers/clover/core/event.hpp
@@ -90,6 +90,7 @@ namespace clover {
std::vector<intrusive_ref<event>> _chain;
std::condition_variable signalled_cv;
std::mutex signalled_mutex;
+ std::mutex trigger_mutex;
};
///
--
2.0.4
More information about the mesa-dev
mailing list