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 10 #ifndef _PSTL_EXECUTION_POLICY_DEFS_H 11 #define _PSTL_EXECUTION_POLICY_DEFS_H 12 13 #include <type_traits> 14 15 #include "pstl_config.h" 16 17 _PSTL_HIDE_FROM_ABI_PUSH 18 19 namespace __pstl 20 { 21 namespace execution 22 { 23 inline namespace v1 24 { 25 26 // 2.4, Sequential execution policy 27 class sequenced_policy 28 { 29 public: 30 // For internal use only 31 static constexpr std::false_type __allow_unsequenced()32 __allow_unsequenced() 33 { 34 return std::false_type{}; 35 } 36 static constexpr std::false_type __allow_vector()37 __allow_vector() 38 { 39 return std::false_type{}; 40 } 41 static constexpr std::false_type __allow_parallel()42 __allow_parallel() 43 { 44 return std::false_type{}; 45 } 46 }; 47 48 // 2.5, Parallel execution policy 49 class parallel_policy 50 { 51 public: 52 // For internal use only 53 static constexpr std::false_type __allow_unsequenced()54 __allow_unsequenced() 55 { 56 return std::false_type{}; 57 } 58 static constexpr std::false_type __allow_vector()59 __allow_vector() 60 { 61 return std::false_type{}; 62 } 63 static constexpr std::true_type __allow_parallel()64 __allow_parallel() 65 { 66 return std::true_type{}; 67 } 68 }; 69 70 // 2.6, Parallel+Vector execution policy 71 class parallel_unsequenced_policy 72 { 73 public: 74 // For internal use only 75 static constexpr std::true_type __allow_unsequenced()76 __allow_unsequenced() 77 { 78 return std::true_type{}; 79 } 80 static constexpr std::true_type __allow_vector()81 __allow_vector() 82 { 83 return std::true_type{}; 84 } 85 static constexpr std::true_type __allow_parallel()86 __allow_parallel() 87 { 88 return std::true_type{}; 89 } 90 }; 91 92 class unsequenced_policy 93 { 94 public: 95 // For internal use only 96 static constexpr std::true_type __allow_unsequenced()97 __allow_unsequenced() 98 { 99 return std::true_type{}; 100 } 101 static constexpr std::true_type __allow_vector()102 __allow_vector() 103 { 104 return std::true_type{}; 105 } 106 static constexpr std::false_type __allow_parallel()107 __allow_parallel() 108 { 109 return std::false_type{}; 110 } 111 }; 112 113 // 2.8, Execution policy objects 114 constexpr sequenced_policy seq{}; 115 constexpr parallel_policy par{}; 116 constexpr parallel_unsequenced_policy par_unseq{}; 117 constexpr unsequenced_policy unseq{}; 118 119 // 2.3, Execution policy type trait 120 template <class T> 121 struct is_execution_policy : std::false_type 122 { 123 }; 124 125 template <> 126 struct is_execution_policy<__pstl::execution::sequenced_policy> : std::true_type 127 { 128 }; 129 template <> 130 struct is_execution_policy<__pstl::execution::parallel_policy> : std::true_type 131 { 132 }; 133 template <> 134 struct is_execution_policy<__pstl::execution::parallel_unsequenced_policy> : std::true_type 135 { 136 }; 137 template <> 138 struct is_execution_policy<__pstl::execution::unsequenced_policy> : std::true_type 139 { 140 }; 141 142 #if defined(_PSTL_CPP14_VARIABLE_TEMPLATES_PRESENT) 143 template <class T> 144 constexpr bool is_execution_policy_v = __pstl::execution::is_execution_policy<T>::value; 145 #endif 146 147 } // namespace v1 148 } // namespace execution 149 150 namespace __internal 151 { 152 template <class ExecPolicy, class T> 153 using __enable_if_execution_policy = 154 typename std::enable_if<__pstl::execution::is_execution_policy<typename std::decay<ExecPolicy>::type>::value, 155 T>::type; 156 } // namespace __internal 157 158 } // namespace __pstl 159 160 _PSTL_HIDE_FROM_ABI_POP 161 162 #endif /* _PSTL_EXECUTION_POLICY_DEFS_H */ 163