void
event::trigger() {
if (!--wait_count) {
+ cv.notify_all();
action_ok(*this);
while (!_chain.empty()) {
ev.deps.push_back(*this);
}
+void
+event::wait() const {
+ for (event &ev : deps)
+ ev.wait();
+
+ std::unique_lock<std::mutex> lock(mutex);
+ cv.wait(lock, [=]{ return !wait_count; });
+}
+
hard_event::hard_event(command_queue &q, cl_command_type command,
const ref_vector<event> &deps, action action) :
event(q.context(), deps, profile(q, action), [](event &ev){}),
hard_event::wait() const {
pipe_screen *screen = queue()->device().pipe;
+ event::wait();
+
if (status() == CL_QUEUED)
queue()->flush();
void
soft_event::wait() const {
- for (event &ev : deps)
- ev.wait();
+ event::wait();
if (status() != CL_COMPLETE)
throw error(CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST);
#ifndef CLOVER_CORE_EVENT_HPP
#define CLOVER_CORE_EVENT_HPP
+#include <condition_variable>
#include <functional>
#include "core/object.hpp"
virtual cl_int status() const = 0;
virtual command_queue *queue() const = 0;
virtual cl_command_type command() const = 0;
- virtual void wait() const = 0;
+ virtual void wait() const;
virtual struct pipe_fence_handle *fence() const {
return NULL;
action action_ok;
action action_fail;
std::vector<intrusive_ref<event>> _chain;
+ mutable std::condition_variable cv;
+ mutable std::mutex mutex;
};
///