atomic.hpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. //---------------------------------------------------------------------------//
  2. // Copyright (c) 2013 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_FUNCTIONAL_ATOMIC_HPP
  11. #define BOOST_COMPUTE_FUNCTIONAL_ATOMIC_HPP
  12. #include <boost/compute/cl.hpp>
  13. #include <boost/compute/function.hpp>
  14. #ifndef BOOST_COMPUTE_DOXYGEN_INVOKED
  15. #ifdef BOOST_COMPUTE_CL_VERSION_1_1
  16. #define BOOST_COMPUTE_DETAIL_ATOMIC_PREFIX "atomic_"
  17. #else
  18. #define BOOST_COMPUTE_DETAIL_ATOMIC_PREFIX "atom_"
  19. #endif
  20. #endif // BOOST_COMPUTE_DOXYGEN_INVOKED
  21. namespace boost {
  22. namespace compute {
  23. template<class T>
  24. class atomic_add : public function<T (T*, T)>
  25. {
  26. public:
  27. atomic_add()
  28. : function<T (T*, T)>(BOOST_COMPUTE_DETAIL_ATOMIC_PREFIX "add")
  29. {
  30. }
  31. };
  32. template<class T>
  33. class atomic_sub : public function<T (T*, T)>
  34. {
  35. public:
  36. atomic_sub()
  37. : function<T (T*, T)>(BOOST_COMPUTE_DETAIL_ATOMIC_PREFIX "sub")
  38. {
  39. }
  40. };
  41. template<class T>
  42. class atomic_xchg : public function<T (T*, T)>
  43. {
  44. public:
  45. atomic_xchg()
  46. : function<T (T*, T)>(BOOST_COMPUTE_DETAIL_ATOMIC_PREFIX "xchg")
  47. {
  48. }
  49. };
  50. template<class T>
  51. class atomic_inc : public function<T (T*)>
  52. {
  53. public:
  54. atomic_inc()
  55. : function<T (T*)>(BOOST_COMPUTE_DETAIL_ATOMIC_PREFIX "inc")
  56. {
  57. }
  58. };
  59. template<class T>
  60. class atomic_dec : public function<T (T*)>
  61. {
  62. public:
  63. atomic_dec()
  64. : function<T (T*)>(BOOST_COMPUTE_DETAIL_ATOMIC_PREFIX "dec")
  65. {
  66. }
  67. };
  68. template<class T>
  69. class atomic_cmpxchg : public function<T (T*, T, T)>
  70. {
  71. public:
  72. atomic_cmpxchg()
  73. : function<T (T*, T, T)>(BOOST_COMPUTE_DETAIL_ATOMIC_PREFIX "cmpxchg")
  74. {
  75. }
  76. };
  77. template<class T>
  78. class atomic_max : public function<T (T*, T)>
  79. {
  80. public:
  81. atomic_max()
  82. : function<T (T*, T)>(BOOST_COMPUTE_DETAIL_ATOMIC_PREFIX "max")
  83. {
  84. }
  85. };
  86. template<class T>
  87. class atomic_min : public function<T (T*, T)>
  88. {
  89. public:
  90. atomic_min()
  91. : function<T (T*, T)>(BOOST_COMPUTE_DETAIL_ATOMIC_PREFIX "min")
  92. {
  93. }
  94. };
  95. template<class T>
  96. class atomic_and : public function<T (T*, T)>
  97. {
  98. public:
  99. atomic_and()
  100. : function<T (T*, T)>(BOOST_COMPUTE_DETAIL_ATOMIC_PREFIX "and")
  101. {
  102. }
  103. };
  104. template<class T>
  105. class atomic_or : public function<T (T*, T)>
  106. {
  107. public:
  108. atomic_or()
  109. : function<T (T*, T)>(BOOST_COMPUTE_DETAIL_ATOMIC_PREFIX "or")
  110. {
  111. }
  112. };
  113. template<class T>
  114. class atomic_xor : public function<T (T*, T)>
  115. {
  116. public:
  117. atomic_xor()
  118. : function<T (T*, T)>(BOOST_COMPUTE_DETAIL_ATOMIC_PREFIX "xor")
  119. {
  120. }
  121. };
  122. } // end compute namespace
  123. } // end boost namespace
  124. #endif // BOOST_COMPUTE_FUNCTIONAL_ATOMIC_HPP