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#include <__algorithm/min.h>
10#include <__config>
11#include <__pstl/backends/libdispatch.h>
12#include <dispatch/dispatch.h>
13
14_LIBCPP_BEGIN_NAMESPACE_STD
15namespace __pstl::__libdispatch {
16
17void __dispatch_apply(size_t chunk_count, void* context, void (*func)(void* context, size_t chunk)) noexcept {
18 ::dispatch_apply_f(chunk_count, DISPATCH_APPLY_AUTO, context, func);
19}
20
21__chunk_partitions __partition_chunks(ptrdiff_t element_count) noexcept {
22 __chunk_partitions partitions;
23 partitions.__chunk_count_ = std::max<ptrdiff_t>(1, element_count / 256);
24 partitions.__chunk_size_ = element_count / partitions.__chunk_count_;
25 partitions.__first_chunk_size_ = element_count - (partitions.__chunk_count_ - 1) * partitions.__chunk_size_;
26 if (partitions.__chunk_count_ == 0 && element_count > 0)
27 partitions.__chunk_count_ = 1;
28 return partitions;
29}
30
31} // namespace __pstl::__libdispatch
32_LIBCPP_END_NAMESPACE_STD
33

source code of libcxx/src/pstl/libdispatch.cpp