execution 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. // -*- C++ -*-
  2. //===----------------------------------------------------------------------===//
  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 _LIBCPP_EXECUTION
  10. #define _LIBCPP_EXECUTION
  11. /*
  12. namespace std::execution {
  13. struct sequenced_policy;
  14. struct parallel_policy;
  15. struct parallel_unsequenced_policy;
  16. struct unsequenced_policy; // since C++20
  17. inline constexpr sequenced_policy seq = implementation-defined;
  18. inline constexpr parallel_policy par = implementation-defined;
  19. inline constexpr parallel_unsequenced_policy par_unseq = implementation-defined;
  20. inline constexpr unsequenced_policy unseq = implementation-defined; // since C++20
  21. }
  22. namespace std {
  23. template <class T>
  24. struct is_execution_policy;
  25. template <class T>
  26. inline constexpr bool is_execution_policy_v;
  27. }
  28. */
  29. #include <__assert> // all public C++ headers provide the assertion handler
  30. #include <__config>
  31. #include <__type_traits/is_execution_policy.h>
  32. #include <__type_traits/is_same.h>
  33. #include <__type_traits/remove_cvref.h>
  34. #include <version>
  35. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  36. # pragma GCC system_header
  37. #endif
  38. #if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
  39. _LIBCPP_BEGIN_NAMESPACE_STD
  40. namespace execution {
  41. struct sequenced_policy {
  42. _LIBCPP_HIDE_FROM_ABI constexpr explicit sequenced_policy(__disable_user_instantiations_tag) {}
  43. sequenced_policy(const sequenced_policy&) = delete;
  44. sequenced_policy& operator=(const sequenced_policy&) = delete;
  45. };
  46. inline constexpr sequenced_policy seq{__disable_user_instantiations_tag{}};
  47. struct parallel_policy {
  48. _LIBCPP_HIDE_FROM_ABI constexpr explicit parallel_policy(__disable_user_instantiations_tag) {}
  49. parallel_policy(const parallel_policy&) = delete;
  50. parallel_policy& operator=(const parallel_policy&) = delete;
  51. };
  52. inline constexpr parallel_policy par{__disable_user_instantiations_tag{}};
  53. struct parallel_unsequenced_policy {
  54. _LIBCPP_HIDE_FROM_ABI constexpr explicit parallel_unsequenced_policy(__disable_user_instantiations_tag) {}
  55. parallel_unsequenced_policy(const parallel_unsequenced_policy&) = delete;
  56. parallel_unsequenced_policy& operator=(const parallel_unsequenced_policy&) = delete;
  57. };
  58. inline constexpr parallel_unsequenced_policy par_unseq{__disable_user_instantiations_tag{}};
  59. struct __unsequenced_policy {
  60. _LIBCPP_HIDE_FROM_ABI constexpr explicit __unsequenced_policy(__disable_user_instantiations_tag) {}
  61. __unsequenced_policy(const __unsequenced_policy&) = delete;
  62. __unsequenced_policy& operator=(const __unsequenced_policy&) = delete;
  63. };
  64. constexpr __unsequenced_policy __unseq{__disable_user_instantiations_tag{}};
  65. # if _LIBCPP_STD_VER >= 20
  66. struct unsequenced_policy {
  67. _LIBCPP_HIDE_FROM_ABI constexpr explicit unsequenced_policy(__disable_user_instantiations_tag) {}
  68. unsequenced_policy(const unsequenced_policy&) = delete;
  69. unsequenced_policy& operator=(const unsequenced_policy&) = delete;
  70. };
  71. inline constexpr unsequenced_policy unseq{__disable_user_instantiations_tag{}};
  72. # endif // _LIBCPP_STD_VER >= 20
  73. } // namespace execution
  74. template <>
  75. inline constexpr bool is_execution_policy_v<execution::sequenced_policy> = true;
  76. template <>
  77. inline constexpr bool is_execution_policy_v<execution::parallel_policy> = true;
  78. template <>
  79. inline constexpr bool is_execution_policy_v<execution::parallel_unsequenced_policy> = true;
  80. template <>
  81. inline constexpr bool is_execution_policy_v<execution::__unsequenced_policy> = true;
  82. template <>
  83. inline constexpr bool __is_parallel_execution_policy_impl<execution::parallel_policy> = true;
  84. template <>
  85. inline constexpr bool __is_parallel_execution_policy_impl<execution::parallel_unsequenced_policy> = true;
  86. template <>
  87. inline constexpr bool __is_unsequenced_execution_policy_impl<execution::__unsequenced_policy> = true;
  88. template <>
  89. inline constexpr bool __is_unsequenced_execution_policy_impl<execution::parallel_unsequenced_policy> = true;
  90. # if _LIBCPP_STD_VER >= 20
  91. template <>
  92. inline constexpr bool is_execution_policy_v<execution::unsequenced_policy> = true;
  93. template <>
  94. inline constexpr bool __is_unsequenced_execution_policy_impl<execution::unsequenced_policy> = true;
  95. # endif
  96. template <class _Tp>
  97. struct is_execution_policy : bool_constant<is_execution_policy_v<_Tp>> {};
  98. template <class _ExecutionPolicy>
  99. _LIBCPP_HIDE_FROM_ABI auto __remove_parallel_policy(const _ExecutionPolicy&) {
  100. if constexpr (is_same_v<_ExecutionPolicy, execution::parallel_policy>) {
  101. return execution::sequenced_policy(execution::__disable_user_instantiations_tag{});
  102. } else if constexpr (is_same_v<_ExecutionPolicy, execution::parallel_unsequenced_policy>) {
  103. return execution::__unsequenced_policy{execution::__disable_user_instantiations_tag{}};
  104. }
  105. }
  106. _LIBCPP_END_NAMESPACE_STD
  107. #endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
  108. #endif // _LIBCPP_EXECUTION