#ifndef BOOST_COMPUTE_ASYNC_FUTURE_HPP
#define BOOST_COMPUTE_ASYNC_FUTURE_HPP
#include <boost/compute/event.hpp>
namespace boost {
namespace compute {
template<class T>
class future
{
public:
future()
: m_event(0)
{
}
future(const T &result, const event &event)
: m_result(result),
m_event(event)
{
}
future(const future<T> &other)
: m_result(other.m_result),
m_event(other.m_event)
{
}
future& operator=(const future<T> &other)
{
if(this != &other){
m_result = other.m_result;
m_event = other.m_event;
}
return *this;
}
~future()
{
}
T get()
{
wait();
return m_result;
}
bool valid() const
{
return m_event != 0;
}
void wait() const
{
m_event.wait();
}
event get_event() const
{
return m_event;
}
#if defined(BOOST_COMPUTE_CL_VERSION_1_1) || defined(BOOST_COMPUTE_DOXYGEN_INVOKED)
template<class Function>
future& then(Function callback)
{
m_event.set_callback(callback);
return *this;
}
#endif
private:
T m_result;
event m_event;
};
template<>
class future<void>
{
public:
future()
: m_event(0)
{
}
template<class T>
future(const future<T> &other)
: m_event(other.get_event())
{
}
explicit future(const event &event)
: m_event(event)
{
}
template<class T>
future<void> &operator=(const future<T> &other)
{
m_event = other.get_event();
return *this;
}
future<void> &operator=(const future<void> &other)
{
if(this != &other){
m_event = other.m_event;
}
return *this;
}
~future()
{
}
void get()
{
wait();
}
bool valid() const
{
return m_event != 0;
}
void wait() const
{
m_event.wait();
}
event get_event() const
{
return m_event;
}
#if defined(BOOST_COMPUTE_CL_VERSION_1_1) || defined(BOOST_COMPUTE_DOXYGEN_INVOKED)
template<class Function>
future<void> &then(Function callback)
{
m_event.set_callback(callback);
return *this;
}
#endif
private:
event m_event;
};
template<class Result>
inline future<Result> make_future(const Result &result, const event &event)
{
return future<Result>(result, event);
}
} }
#endif