[libcxx-commits] [PATCH] D151717: [libc++][PSTL] Add a GCD backend

Louis Dionne via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Jun 27 08:32:47 PDT 2023


ldionne added inline comments.


================
Comment at: libcxx/include/__algorithm/pstl_backends/cpu_backends/libdispatch.h:37
+[[_Clang::__callback__(__func, __context, __)]] _LIBCPP_EXPORTED_FROM_ABI void
+__dispatch_apply(size_t __chunk_count, void* __context, void (*__func)(void* __context, size_t __chunk)) noexcept;
+
----------------
Otherwise this is a bit confusing.


================
Comment at: libcxx/include/__algorithm/pstl_backends/cpu_backends/libdispatch.h:101-102
+    pmr::vector<__merge_range<_RandomAccessIterator1, _RandomAccessIterator2, _RandomAccessIteratorOut>>& __ranges) {
+  std::size_t __size_x = __last1 - __first1;
+  std::size_t __size_y = __last2 - __first2;
+
----------------
Seems more fitting given the names of the iterators?


================
Comment at: libcxx/include/__algorithm/pstl_backends/cpu_backends/libdispatch.h:158-172
+#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
+  try {
+#endif
+    auto __ranges = __libdispatch::__calculate_merge_ranges(__first1, __last1, __first2, __last2, __result, __comp);
+
+    // __dispatch_apply is noexcept, so we don't convert any user exceptions
+    __libdispatch::__dispatch_apply(__ranges.size(), [&](size_t __index) {
----------------
IMO this captures better the fact that we are only catching exceptions in `__libdispatch::__calculate_merge_ranges`:

```
pmr::vector<...> __ranges;
try {
  __ranges = __calculate(...);
} catch ( ) {
  throw __pstl_bad_alloc();
}

__libdispatch::__dispatch_apply(...);
```

This makes it more obvious that we let `__dispatch_apply` terminate if an exception is thrown.

Edit: This might not work if the allocator doesn't propagate.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151717/new/

https://reviews.llvm.org/D151717



More information about the libcxx-commits mailing list