user_event.hpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. //---------------------------------------------------------------------------//
  2. // Copyright (c) 2013-2014 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. #ifndef BOOST_COMPUTE_USER_EVENT_HPP
  11. #define BOOST_COMPUTE_USER_EVENT_HPP
  12. #include <boost/compute/event.hpp>
  13. #include <boost/compute/context.hpp>
  14. namespace boost {
  15. namespace compute {
  16. #if defined(BOOST_COMPUTE_CL_VERSION_1_1) || defined(BOOST_COMPUTE_DOXYGEN_INVOKED)
  17. /// \class user_event
  18. /// \brief An user-created event.
  19. ///
  20. /// \opencl_version_warning{1,1}
  21. ///
  22. /// \see event
  23. class user_event : public event
  24. {
  25. public:
  26. /// Creates a new user-event object.
  27. ///
  28. /// \see_opencl_ref{clCreateUserEvent}
  29. explicit user_event(const context &context)
  30. {
  31. cl_int error;
  32. m_event = clCreateUserEvent(context.get(), &error);
  33. if(!m_event){
  34. BOOST_THROW_EXCEPTION(opencl_error(error));
  35. }
  36. }
  37. /// Creates a new user-event from \p other.
  38. user_event(const user_event &other)
  39. : event(other)
  40. {
  41. }
  42. /// Copies the user-event from \p other to \c *this.
  43. user_event& operator=(const user_event &other)
  44. {
  45. event::operator=(other);
  46. return *this;
  47. }
  48. #ifndef BOOST_COMPUTE_NO_RVALUE_REFERENCES
  49. /// Move-constructs a new user event object from \p other.
  50. user_event(user_event&& other) BOOST_NOEXCEPT
  51. : event(std::move(other))
  52. {
  53. }
  54. /// Move-assigns the user event from \p other to \c *this.
  55. user_event& operator=(user_event&& other) BOOST_NOEXCEPT
  56. {
  57. event::operator=(std::move(other));
  58. return *this;
  59. }
  60. #endif // BOOST_COMPUTE_NO_RVALUE_REFERENCES
  61. /// Sets the execution status for the user-event.
  62. ///
  63. /// \see_opencl_ref{clSetUserEventStatus}
  64. void set_status(cl_int execution_status)
  65. {
  66. cl_int ret = clSetUserEventStatus(m_event, execution_status);
  67. if(ret != CL_SUCCESS){
  68. BOOST_THROW_EXCEPTION(opencl_error(ret));
  69. }
  70. }
  71. };
  72. #endif // BOOST_COMPUTE_CL_VERSION_1_1
  73. } // end compute namespace
  74. } // end boost namespace
  75. #endif // BOOST_COMPUTE_EVENT_HPP