1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2013-2015 Kyle Lutz <kyle.r.lutz@gmail.com>
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
8 // See http://boostorg.github.com/compute for more information.
9 //---------------------------------------------------------------------------//
11 #ifndef BOOST_COMPUTE_ASYNC_WAIT_GUARD_HPP
12 #define BOOST_COMPUTE_ASYNC_WAIT_GUARD_HPP
14 #include <boost/noncopyable.hpp>
20 /// \brief A guard object for synchronizing an operation on the device
22 /// The wait_guard class stores a waitable object representing an operation
23 /// on a compute device (e.g. \ref event, \ref future "future<T>") and calls
24 /// its \c wait() method when the guard object goes out of scope.
26 /// This is useful for ensuring that an OpenCL operation completes before
27 /// leaving the current scope and cleaning up any resources.
31 /// // enqueue a compute kernel for execution
32 /// event e = queue.enqueue_nd_range_kernel(...);
34 /// // call e.wait() upon exiting the current scope
35 /// wait_guard<event> guard(e);
38 /// \ref wait_list, wait_for_all()
39 template<class Waitable>
40 class wait_guard : boost::noncopyable
43 /// Creates a new wait_guard object for \p waitable.
44 wait_guard(const Waitable &waitable)
45 : m_waitable(waitable)
49 /// Destroys the wait_guard object. The default implementation will call
50 /// \c wait() on the stored waitable object.
60 } // end compute namespace
61 } // end boost namespace
63 #endif // BOOST_COMPUTE_ASYNC_WAIT_GUARD_HPP