You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

163 satır
3.6KB

  1. // -*- C++ -*-
  2. //===-- execution_defs.h --------------------------------------------------===//
  3. //
  4. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  5. // See https://llvm.org/LICENSE.txt for license information.
  6. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  7. //
  8. //===----------------------------------------------------------------------===//
  9. #ifndef _PSTL_EXECUTION_POLICY_DEFS_H
  10. #define _PSTL_EXECUTION_POLICY_DEFS_H
  11. #include <type_traits>
  12. namespace __pstl
  13. {
  14. namespace execution
  15. {
  16. inline namespace v1
  17. {
  18. // 2.4, Sequential execution policy
  19. class sequenced_policy
  20. {
  21. public:
  22. // For internal use only
  23. static constexpr std::false_type
  24. __allow_unsequenced()
  25. {
  26. return std::false_type{};
  27. }
  28. static constexpr std::false_type
  29. __allow_vector()
  30. {
  31. return std::false_type{};
  32. }
  33. static constexpr std::false_type
  34. __allow_parallel()
  35. {
  36. return std::false_type{};
  37. }
  38. };
  39. // 2.5, Parallel execution policy
  40. class parallel_policy
  41. {
  42. public:
  43. // For internal use only
  44. static constexpr std::false_type
  45. __allow_unsequenced()
  46. {
  47. return std::false_type{};
  48. }
  49. static constexpr std::false_type
  50. __allow_vector()
  51. {
  52. return std::false_type{};
  53. }
  54. static constexpr std::true_type
  55. __allow_parallel()
  56. {
  57. return std::true_type{};
  58. }
  59. };
  60. // 2.6, Parallel+Vector execution policy
  61. class parallel_unsequenced_policy
  62. {
  63. public:
  64. // For internal use only
  65. static constexpr std::true_type
  66. __allow_unsequenced()
  67. {
  68. return std::true_type{};
  69. }
  70. static constexpr std::true_type
  71. __allow_vector()
  72. {
  73. return std::true_type{};
  74. }
  75. static constexpr std::true_type
  76. __allow_parallel()
  77. {
  78. return std::true_type{};
  79. }
  80. };
  81. class unsequenced_policy
  82. {
  83. public:
  84. // For internal use only
  85. static constexpr std::true_type
  86. __allow_unsequenced()
  87. {
  88. return std::true_type{};
  89. }
  90. static constexpr std::true_type
  91. __allow_vector()
  92. {
  93. return std::true_type{};
  94. }
  95. static constexpr std::false_type
  96. __allow_parallel()
  97. {
  98. return std::false_type{};
  99. }
  100. };
  101. // 2.8, Execution policy objects
  102. constexpr sequenced_policy seq{};
  103. constexpr parallel_policy par{};
  104. constexpr parallel_unsequenced_policy par_unseq{};
  105. constexpr unsequenced_policy unseq{};
  106. // 2.3, Execution policy type trait
  107. template <class _Tp>
  108. struct is_execution_policy : std::false_type
  109. {
  110. };
  111. template <>
  112. struct is_execution_policy<__pstl::execution::sequenced_policy> : std::true_type
  113. {
  114. };
  115. template <>
  116. struct is_execution_policy<__pstl::execution::parallel_policy> : std::true_type
  117. {
  118. };
  119. template <>
  120. struct is_execution_policy<__pstl::execution::parallel_unsequenced_policy> : std::true_type
  121. {
  122. };
  123. template <>
  124. struct is_execution_policy<__pstl::execution::unsequenced_policy> : std::true_type
  125. {
  126. };
  127. #if _PSTL_CPP14_VARIABLE_TEMPLATES_PRESENT
  128. template <class _Tp>
  129. constexpr bool is_execution_policy_v = __pstl::execution::is_execution_policy<_Tp>::value;
  130. #endif
  131. } // namespace v1
  132. } // namespace execution
  133. namespace __internal
  134. {
  135. template <class _ExecPolicy, class _Tp>
  136. #if _GLIBCXX_RELEASE >= 9
  137. using __enable_if_execution_policy =
  138. typename std::enable_if<__pstl::execution::is_execution_policy<std::__remove_cvref_t<_ExecPolicy>>::value,
  139. _Tp>::type;
  140. #else
  141. using __enable_if_execution_policy =
  142. typename std::enable_if<__pstl::execution::is_execution_policy<typename std::decay<_ExecPolicy>::type>::value,
  143. _Tp>::type;
  144. #endif
  145. } // namespace __internal
  146. } // namespace __pstl
  147. #endif /* _PSTL_EXECUTION_POLICY_DEFS_H */