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/move.h>
15 #include <cstddef>
16 
17 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18 #  pragma GCC system_header
19 #endif
20 
21 _LIBCPP_PUSH_MACROS
22 #include <__undef_macros>
23 
24 #if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
25 
26 // This backend implementation is for testing purposes only and not meant for production use. This will be replaced
27 // by a proper implementation once the PSTL implementation is somewhat stable.
28 
29 _LIBCPP_BEGIN_NAMESPACE_STD
30 
31 namespace __par_backend {
32 inline namespace __thread_cpu_backend {
33 
34 template <class _RandomAccessIterator, class _Fp>
35 _LIBCPP_HIDE_FROM_ABI void __parallel_for(_RandomAccessIterator __first, _RandomAccessIterator __last, _Fp __f) {
36   __f(__first, __last);
37 }
38 
39 template <class _Index, class _UnaryOp, class _Tp, class _BinaryOp, class _Reduce>
40 _LIBCPP_HIDE_FROM_ABI _Tp
41 __parallel_transform_reduce(_Index __first, _Index __last, _UnaryOp, _Tp __init, _BinaryOp, _Reduce __reduce) {
42   return __reduce(std::move(__first), std::move(__last), std::move(__init));
43 }
44 
45 template <class _RandomAccessIterator, class _Compare, class _LeafSort>
46 _LIBCPP_HIDE_FROM_ABI void __parallel_stable_sort(
47     _RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp, _LeafSort __leaf_sort) {
48   __leaf_sort(__first, __last, __comp);
49 }
50 
51 _LIBCPP_HIDE_FROM_ABI inline void __cancel_execution() {}
52 
53 template <class _RandomAccessIterator1,
54           class _RandomAccessIterator2,
55           class _RandomAccessIterator3,
56           class _Compare,
57           class _LeafMerge>
58 _LIBCPP_HIDE_FROM_ABI void __parallel_merge(
59     _RandomAccessIterator1 __first1,
60     _RandomAccessIterator1 __last1,
61     _RandomAccessIterator2 __first2,
62     _RandomAccessIterator2 __last2,
63     _RandomAccessIterator3 __outit,
64     _Compare __comp,
65     _LeafMerge __leaf_merge) {
66   __leaf_merge(__first1, __last1, __first2, __last2, __outit, __comp);
67 }
68 
69 } // namespace __thread_cpu_backend
70 } // namespace __par_backend
71 
72 _LIBCPP_END_NAMESPACE_STD
73 
74 #endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && && _LIBCPP_STD_VER >= 17
75 
76 _LIBCPP_POP_MACROS
77 
78 #endif // _LIBCPP___ALGORITHM_PSTL_BACKENDS_CPU_BACKENDS_THREAD_H
79