]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/compute/include/boost/compute/async/wait_guard.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / compute / include / boost / compute / async / wait_guard.hpp
CommitLineData
7c673cae
FG
1//---------------------------------------------------------------------------//
2// Copyright (c) 2013-2015 Kyle Lutz <kyle.r.lutz@gmail.com>
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
11#ifndef BOOST_COMPUTE_ASYNC_WAIT_GUARD_HPP
12#define BOOST_COMPUTE_ASYNC_WAIT_GUARD_HPP
13
14#include <boost/noncopyable.hpp>
15
16namespace boost {
17namespace compute {
18
19/// \class wait_guard
20/// \brief A guard object for synchronizing an operation on the device
21///
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.
25///
26/// This is useful for ensuring that an OpenCL operation completes before
27/// leaving the current scope and cleaning up any resources.
28///
29/// For example:
30/// \code
31/// // enqueue a compute kernel for execution
32/// event e = queue.enqueue_nd_range_kernel(...);
33///
34/// // call e.wait() upon exiting the current scope
35/// wait_guard<event> guard(e);
36/// \endcode
37///
38/// \ref wait_list, wait_for_all()
39template<class Waitable>
40class wait_guard : boost::noncopyable
41{
42public:
43 /// Creates a new wait_guard object for \p waitable.
44 wait_guard(const Waitable &waitable)
45 : m_waitable(waitable)
46 {
47 }
48
49 /// Destroys the wait_guard object. The default implementation will call
50 /// \c wait() on the stored waitable object.
51 ~wait_guard()
52 {
53 m_waitable.wait();
54 }
55
56private:
57 Waitable m_waitable;
58};
59
60} // end compute namespace
61} // end boost namespace
62
63#endif // BOOST_COMPUTE_ASYNC_WAIT_GUARD_HPP