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