| 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 <__config> |
| 10 | #include <__pstl/backends/statpart.h> |
| 11 | |
| 12 | #if defined(__APPLE__) |
| 13 | # include <dispatch/dispatch.h> |
| 14 | #endif |
| 15 | |
| 16 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 17 | _LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS |
| 18 | namespace __pstl::__statpart { |
| 19 | |
| 20 | void __apply(size_t chunk_count, void* context, void (*func)(void* context, size_t chunk)) noexcept { |
| 21 | #if defined(__APPLE__) |
| 22 | ::dispatch_apply_f(chunk_count, DISPATCH_APPLY_AUTO, context, func); |
| 23 | #else |
| 24 | // Currently there's no parallelism provider on non-Apple platforms. |
| 25 | // A basic task scheduler based on a thread pool will be added later to perform the application in parallel. |
| 26 | for (size_t i = 0; i < chunk_count; ++i) |
| 27 | func(context, i); |
| 28 | #endif |
| 29 | } |
| 30 | |
| 31 | } // namespace __pstl::__statpart |
| 32 | _LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS |
| 33 | _LIBCPP_END_NAMESPACE_STD |
| 34 | |