Skip to content

Commit d174c7e

Browse files
committed
Use libdispatch backend if available.
1 parent 7ef6c8d commit d174c7e

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ include(CheckIncludeFileCXX)
424424
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
425425
CHECK_INCLUDE_FILE_CXX("dispatch/dispatch.h" STDEXEC_FOUND_LIBDISPATCH)
426426
option(STDEXEC_ENABLE_LIBDISPATCH "Enable the tests for the Grand Central Dispatch scheduler" ${STDEXEC_FOUND_LIBDISPATCH})
427+
target_compile_definitions(stdexec INTERFACE STDEXEC_ENABLE_LIBDISPATCH)
427428
endif()
428429

429430
option (STDEXEC_ENABLE_NUMA "Enable NUMA affinity for static_thread_pool" OFF)

include/exec/__detail/__system_context_default_impl.hpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
#include "__system_context_replaceability_api.hpp"
1919
#include "stdexec/execution.hpp"
2020
#include "exec/static_thread_pool.hpp"
21+
#if STDEXEC_ENABLE_LIBDISPATCH
22+
# include "exec/libdispatch_queue.hpp"
23+
#endif
2124

2225
#include <thread>
2326
#include <atomic>
@@ -31,8 +34,6 @@ namespace exec::__system_context_default_impl {
3134
using system_context_replaceability::system_scheduler;
3235
using system_context_replaceability::__system_context_backend_factory;
3336

34-
using __pool_scheduler_t = decltype(std::declval<exec::static_thread_pool>().get_scheduler());
35-
3637
/// Receiver that calls the callback when the operation completes.
3738
template <class _Sender>
3839
struct __operation;
@@ -59,6 +60,8 @@ namespace exec::__system_context_default_impl {
5960
---------------------
6061
Total: 160; extra 32 bytes compared to internal operation state.
6162
63+
Using libdispatch backend, the operation sizes are 48 (down from 80) and 128 (down from 160).
64+
6265
[*] sizes taken on an Apple M2 Pro arm64 arch. They may differ on other architectures, or with different implementations.
6366
*/
6467

@@ -169,13 +172,16 @@ namespace exec::__system_context_default_impl {
169172
}
170173
};
171174

172-
struct __system_scheduler_impl : system_scheduler {
173-
__system_scheduler_impl()
175+
template <typename _BaseSchedulerContext>
176+
struct __system_scheduler_generic_impl : system_scheduler {
177+
__system_scheduler_generic_impl()
174178
: __pool_scheduler_(__pool_.get_scheduler()) {
175179
}
176180
private:
181+
using __pool_scheduler_t = decltype(std::declval<_BaseSchedulerContext>().get_scheduler());
182+
177183
/// The underlying thread pool.
178-
exec::static_thread_pool __pool_;
184+
_BaseSchedulerContext __pool_;
179185
__pool_scheduler_t __pool_scheduler_;
180186

181187
//! Functor called by the `bulk` operation; sends a `start` signal to the frontend.
@@ -277,6 +283,12 @@ namespace exec::__system_context_default_impl {
277283
}
278284
};
279285

286+
#if STDEXEC_ENABLE_LIBDISPATCH
287+
using __system_scheduler_impl = __system_scheduler_generic_impl<exec::libdispatch_queue>;
288+
#else
289+
using __system_scheduler_impl = __system_scheduler_generic_impl<exec::static_thread_pool>;
290+
#endif
291+
280292
/// The singleton to hold the `system_scheduler` instance.
281293
inline constinit __instance_data<system_scheduler, __system_scheduler_impl>
282294
__system_scheduler_singleton{};

0 commit comments

Comments
 (0)