123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 |
- #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
|