wait.hpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. //---------------------------------------------------------------------------//
  2. // Copyright (c) 2013-2014 Kyle Lutz <[email protected]>
  3. //
  4. // Distributed under the Boost Software License, Version 1.0
  5. // See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt
  7. //
  8. // See http://boostorg.github.com/compute for more information.
  9. //---------------------------------------------------------------------------//
  10. #ifndef BOOST_COMPUTE_ASYNC_WAIT_HPP
  11. #define BOOST_COMPUTE_ASYNC_WAIT_HPP
  12. #include <boost/compute/config.hpp>
  13. #include <boost/compute/utility/wait_list.hpp>
  14. namespace boost {
  15. namespace compute {
  16. namespace detail {
  17. #ifndef BOOST_COMPUTE_NO_VARIADIC_TEMPLATES
  18. template<class Event>
  19. inline void insert_events_variadic(wait_list &l, Event&& event)
  20. {
  21. l.insert(std::forward<Event>(event));
  22. }
  23. template<class Event, class... Rest>
  24. inline void insert_events_variadic(wait_list &l, Event&& event, Rest&&... rest)
  25. {
  26. l.insert(std::forward<Event>(event));
  27. insert_events_variadic(l, std::forward<Rest>(rest)...);
  28. }
  29. #endif // BOOST_COMPUTE_NO_VARIADIC_TEMPLATES
  30. } // end detail namespace
  31. #ifndef BOOST_COMPUTE_NO_VARIADIC_TEMPLATES
  32. /// Blocks until all events have completed. Events can either be \ref event
  33. /// objects or \ref future "future<T>" objects.
  34. ///
  35. /// \see event, wait_list
  36. template<class... Events>
  37. inline void wait_for_all(Events&&... events)
  38. {
  39. wait_list l;
  40. detail::insert_events_variadic(l, std::forward<Events>(events)...);
  41. l.wait();
  42. }
  43. #endif // BOOST_COMPUTE_NO_VARIADIC_TEMPLATES
  44. } // end compute namespace
  45. } // end boost namespace
  46. #endif // BOOST_COMPUTE_ASYNC_WAIT_HPP