Path: blob/main/contrib/llvm-project/libcxx/include/__pstl/backends/std_thread.h
35266 views
//===----------------------------------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef _LIBCPP___PSTL_BACKENDS_STD_THREAD_H9#define _LIBCPP___PSTL_BACKENDS_STD_THREAD_H1011#include <__config>12#include <__pstl/backend_fwd.h>13#include <__pstl/cpu_algos/any_of.h>14#include <__pstl/cpu_algos/cpu_traits.h>15#include <__pstl/cpu_algos/fill.h>16#include <__pstl/cpu_algos/find_if.h>17#include <__pstl/cpu_algos/for_each.h>18#include <__pstl/cpu_algos/merge.h>19#include <__pstl/cpu_algos/stable_sort.h>20#include <__pstl/cpu_algos/transform.h>21#include <__pstl/cpu_algos/transform_reduce.h>22#include <__utility/empty.h>23#include <__utility/move.h>24#include <cstddef>25#include <optional>2627#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)28# pragma GCC system_header29#endif3031_LIBCPP_PUSH_MACROS32#include <__undef_macros>3334_LIBCPP_BEGIN_NAMESPACE_STD35namespace __pstl {3637//38// This partial backend implementation is for testing purposes only and not meant for production use. This will be39// replaced by a proper implementation once the PSTL implementation is somewhat stable.40//41// This is intended to be used on top of the "default backend".42//4344template <>45struct __cpu_traits<__std_thread_backend_tag> {46template <class _RandomAccessIterator, class _Fp>47_LIBCPP_HIDE_FROM_ABI static optional<__empty>48__for_each(_RandomAccessIterator __first, _RandomAccessIterator __last, _Fp __f) {49__f(__first, __last);50return __empty{};51}5253template <class _Index, class _UnaryOp, class _Tp, class _BinaryOp, class _Reduce>54_LIBCPP_HIDE_FROM_ABI static optional<_Tp>55__transform_reduce(_Index __first, _Index __last, _UnaryOp, _Tp __init, _BinaryOp, _Reduce __reduce) {56return __reduce(std::move(__first), std::move(__last), std::move(__init));57}5859template <class _RandomAccessIterator, class _Compare, class _LeafSort>60_LIBCPP_HIDE_FROM_ABI static optional<__empty>61__stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp, _LeafSort __leaf_sort) {62__leaf_sort(__first, __last, __comp);63return __empty{};64}6566_LIBCPP_HIDE_FROM_ABI static void __cancel_execution() {}6768template <class _RandomAccessIterator1,69class _RandomAccessIterator2,70class _RandomAccessIterator3,71class _Compare,72class _LeafMerge>73_LIBCPP_HIDE_FROM_ABI static optional<__empty>74__merge(_RandomAccessIterator1 __first1,75_RandomAccessIterator1 __last1,76_RandomAccessIterator2 __first2,77_RandomAccessIterator2 __last2,78_RandomAccessIterator3 __outit,79_Compare __comp,80_LeafMerge __leaf_merge) {81__leaf_merge(__first1, __last1, __first2, __last2, __outit, __comp);82return __empty{};83}8485static constexpr size_t __lane_size = 64;86};8788// Mandatory implementations of the computational basis89template <class _ExecutionPolicy>90struct __find_if<__std_thread_backend_tag, _ExecutionPolicy>91: __cpu_parallel_find_if<__std_thread_backend_tag, _ExecutionPolicy> {};9293template <class _ExecutionPolicy>94struct __for_each<__std_thread_backend_tag, _ExecutionPolicy>95: __cpu_parallel_for_each<__std_thread_backend_tag, _ExecutionPolicy> {};9697template <class _ExecutionPolicy>98struct __merge<__std_thread_backend_tag, _ExecutionPolicy>99: __cpu_parallel_merge<__std_thread_backend_tag, _ExecutionPolicy> {};100101template <class _ExecutionPolicy>102struct __stable_sort<__std_thread_backend_tag, _ExecutionPolicy>103: __cpu_parallel_stable_sort<__std_thread_backend_tag, _ExecutionPolicy> {};104105template <class _ExecutionPolicy>106struct __transform<__std_thread_backend_tag, _ExecutionPolicy>107: __cpu_parallel_transform<__std_thread_backend_tag, _ExecutionPolicy> {};108109template <class _ExecutionPolicy>110struct __transform_binary<__std_thread_backend_tag, _ExecutionPolicy>111: __cpu_parallel_transform_binary<__std_thread_backend_tag, _ExecutionPolicy> {};112113template <class _ExecutionPolicy>114struct __transform_reduce<__std_thread_backend_tag, _ExecutionPolicy>115: __cpu_parallel_transform_reduce<__std_thread_backend_tag, _ExecutionPolicy> {};116117template <class _ExecutionPolicy>118struct __transform_reduce_binary<__std_thread_backend_tag, _ExecutionPolicy>119: __cpu_parallel_transform_reduce_binary<__std_thread_backend_tag, _ExecutionPolicy> {};120121// Not mandatory, but better optimized122template <class _ExecutionPolicy>123struct __any_of<__std_thread_backend_tag, _ExecutionPolicy>124: __cpu_parallel_any_of<__std_thread_backend_tag, _ExecutionPolicy> {};125126template <class _ExecutionPolicy>127struct __fill<__std_thread_backend_tag, _ExecutionPolicy>128: __cpu_parallel_fill<__std_thread_backend_tag, _ExecutionPolicy> {};129130} // namespace __pstl131_LIBCPP_END_NAMESPACE_STD132133_LIBCPP_POP_MACROS134135#endif // _LIBCPP___PSTL_BACKENDS_STD_THREAD_H136137138