#ifndef BOOST_COMPUTE_UTILITY_WAIT_LIST_HPP
#define BOOST_COMPUTE_UTILITY_WAIT_LIST_HPP
#include <vector>
#include <boost/compute/config.hpp>
#ifndef BOOST_COMPUTE_NO_HDR_INITIALIZER_LIST
#include <initializer_list>
#endif
#include <boost/compute/event.hpp>
namespace boost {
namespace compute {
template<class T> class future;
class wait_list
{
public:
typedef std::vector<event>::iterator iterator;
typedef std::vector<event>::const_iterator const_iterator;
wait_list()
{
}
wait_list(const event &event)
{
insert(event);
}
wait_list(const wait_list &other)
: m_events(other.m_events)
{
}
#ifndef BOOST_COMPUTE_NO_HDR_INITIALIZER_LIST
wait_list(std::initializer_list<event> events)
: m_events(events)
{
}
#endif
wait_list& operator=(const wait_list &other)
{
if(this != &other){
m_events = other.m_events;
}
return *this;
}
#ifndef BOOST_COMPUTE_NO_RVALUE_REFERENCES
wait_list(wait_list&& other)
: m_events(std::move(other.m_events))
{
}
wait_list& operator=(wait_list&& other)
{
m_events = std::move(other.m_events);
return *this;
}
#endif
~wait_list()
{
}
bool empty() const
{
return m_events.empty();
}
uint_ size() const
{
return static_cast<uint_>(m_events.size());
}
void clear()
{
m_events.clear();
}
const cl_event* get_event_ptr() const
{
if(empty()){
return 0;
}
return reinterpret_cast<const cl_event *>(&m_events[0]);
}
void reserve(size_t new_capacity) {
m_events.reserve(new_capacity);
}
void insert(const event &event)
{
m_events.push_back(event);
}
template<class T>
void insert(const future<T> &future)
{
insert(future.get_event());
}
void wait() const
{
if(!empty()){
BOOST_COMPUTE_ASSERT_CL_SUCCESS(
clWaitForEvents(size(), get_event_ptr())
);
}
}
const event& operator[](size_t pos) const {
return m_events[pos];
}
event& operator[](size_t pos) {
return m_events[pos];
}
iterator begin() {
return m_events.begin();
}
const_iterator begin() const {
return m_events.begin();
}
const_iterator cbegin() const {
return m_events.begin();
}
iterator end() {
return m_events.end();
}
const_iterator end() const {
return m_events.end();
}
const_iterator cend() const {
return m_events.end();
}
private:
std::vector<event> m_events;
};
} }
#endif