1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef _LIBCPP___ALGORITHM_PSTL_BACKENDS_CPU_BACKENDS_THREAD_H
10 #define _LIBCPP___ALGORITHM_PSTL_BACKENDS_CPU_BACKENDS_THREAD_H
11 
12 #include <__assert>
13 #include <__config>
14 #include <__utility/empty.h>
15 #include <__utility/move.h>
16 #include <cstddef>
17 #include <optional>
18 
19 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20 #  pragma GCC system_header
21 #endif
22 
23 _LIBCPP_PUSH_MACROS
24 #include <__undef_macros>
25 
26 #if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
27 
28 // This backend implementation is for testing purposes only and not meant for production use. This will be replaced
29 // by a proper implementation once the PSTL implementation is somewhat stable.
30 
31 _LIBCPP_BEGIN_NAMESPACE_STD
32 
33 namespace __par_backend {
34 inline namespace __thread_cpu_backend {
35 
36 template <class _RandomAccessIterator, class _Fp>
37 _LIBCPP_HIDE_FROM_ABI optional<__empty>
__parallel_for(_RandomAccessIterator __first,_RandomAccessIterator __last,_Fp __f)38 __parallel_for(_RandomAccessIterator __first, _RandomAccessIterator __last, _Fp __f) {
39   __f(__first, __last);
40   return __empty{};
41 }
42 
43 template <class _Index, class _UnaryOp, class _Tp, class _BinaryOp, class _Reduce>
44 _LIBCPP_HIDE_FROM_ABI optional<_Tp>
__parallel_transform_reduce(_Index __first,_Index __last,_UnaryOp,_Tp __init,_BinaryOp,_Reduce __reduce)45 __parallel_transform_reduce(_Index __first, _Index __last, _UnaryOp, _Tp __init, _BinaryOp, _Reduce __reduce) {
46   return __reduce(std::move(__first), std::move(__last), std::move(__init));
47 }
48 
49 template <class _RandomAccessIterator, class _Compare, class _LeafSort>
__parallel_stable_sort(_RandomAccessIterator __first,_RandomAccessIterator __last,_Compare __comp,_LeafSort __leaf_sort)50 _LIBCPP_HIDE_FROM_ABI optional<__empty> __parallel_stable_sort(
51     _RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp, _LeafSort __leaf_sort) {
52   __leaf_sort(__first, __last, __comp);
53   return __empty{};
54 }
55 
__cancel_execution()56 _LIBCPP_HIDE_FROM_ABI inline void __cancel_execution() {}
57 
58 template <class _RandomAccessIterator1,
59           class _RandomAccessIterator2,
60           class _RandomAccessIterator3,
61           class _Compare,
62           class _LeafMerge>
__parallel_merge(_RandomAccessIterator1 __first1,_RandomAccessIterator1 __last1,_RandomAccessIterator2 __first2,_RandomAccessIterator2 __last2,_RandomAccessIterator3 __outit,_Compare __comp,_LeafMerge __leaf_merge)63 _LIBCPP_HIDE_FROM_ABI optional<__empty> __parallel_merge(
64     _RandomAccessIterator1 __first1,
65     _RandomAccessIterator1 __last1,
66     _RandomAccessIterator2 __first2,
67     _RandomAccessIterator2 __last2,
68     _RandomAccessIterator3 __outit,
69     _Compare __comp,
70     _LeafMerge __leaf_merge) {
71   __leaf_merge(__first1, __last1, __first2, __last2, __outit, __comp);
72   return __empty{};
73 }
74 
75 } // namespace __thread_cpu_backend
76 } // namespace __par_backend
77 
78 _LIBCPP_END_NAMESPACE_STD
79 
80 #endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && && _LIBCPP_STD_VER >= 17
81 
82 _LIBCPP_POP_MACROS
83 
84 #endif // _LIBCPP___ALGORITHM_PSTL_BACKENDS_CPU_BACKENDS_THREAD_H
85