Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:29:58

0001 //---------------------------------------------------------------------------//
0002 // Copyright (c) 2013-2015 Kyle Lutz <kyle.r.lutz@gmail.com>
0003 //
0004 // Distributed under the Boost Software License, Version 1.0
0005 // See accompanying file LICENSE_1_0.txt or copy at
0006 // http://www.boost.org/LICENSE_1_0.txt
0007 //
0008 // See http://boostorg.github.com/compute for more information.
0009 //---------------------------------------------------------------------------//
0010 
0011 #ifndef BOOST_COMPUTE_ASYNC_WAIT_GUARD_HPP
0012 #define BOOST_COMPUTE_ASYNC_WAIT_GUARD_HPP
0013 
0014 #include <boost/noncopyable.hpp>
0015 
0016 namespace boost {
0017 namespace compute {
0018 
0019 /// \class wait_guard
0020 /// \brief A guard object for synchronizing an operation on the device
0021 ///
0022 /// The wait_guard class stores a waitable object representing an operation
0023 /// on a compute device (e.g. \ref event, \ref future "future<T>") and calls
0024 /// its \c wait() method when the guard object goes out of scope.
0025 ///
0026 /// This is useful for ensuring that an OpenCL operation completes before
0027 /// leaving the current scope and cleaning up any resources.
0028 ///
0029 /// For example:
0030 /// \code
0031 /// // enqueue a compute kernel for execution
0032 /// event e = queue.enqueue_nd_range_kernel(...);
0033 ///
0034 /// // call e.wait() upon exiting the current scope
0035 /// wait_guard<event> guard(e);
0036 /// \endcode
0037 ///
0038 /// \ref wait_list, wait_for_all()
0039 template<class Waitable>
0040 class wait_guard : boost::noncopyable
0041 {
0042 public:
0043     /// Creates a new wait_guard object for \p waitable.
0044     wait_guard(const Waitable &waitable)
0045         : m_waitable(waitable)
0046     {
0047     }
0048 
0049     /// Destroys the wait_guard object. The default implementation will call
0050     /// \c wait() on the stored waitable object.
0051     ~wait_guard()
0052     {
0053         m_waitable.wait();
0054     }
0055 
0056 private:
0057     Waitable m_waitable;
0058 };
0059 
0060 } // end compute namespace
0061 } // end boost namespace
0062 
0063 #endif // BOOST_COMPUTE_ASYNC_WAIT_GUARD_HPP