From 97ec2b5c6a003355ed53cbd3d2f16243e1be8d74 Mon Sep 17 00:00:00 2001 From: Mathis Logemann <13556116+mathisloge@users.noreply.github.com> Date: Mon, 19 May 2025 22:18:27 +0200 Subject: [PATCH 1/2] [execpools,asio] add executor getter to be able to schedule asio functions --- include/execpools/asio/asio_thread_pool.hpp | 6 ++++++ test/execpools/test_asio_thread_pool.cpp | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/include/execpools/asio/asio_thread_pool.hpp b/include/execpools/asio/asio_thread_pool.hpp index 5c4085e5b..dc1153854 100644 --- a/include/execpools/asio/asio_thread_pool.hpp +++ b/include/execpools/asio/asio_thread_pool.hpp @@ -30,6 +30,12 @@ namespace execpools { return static_cast( asio_impl::query(executor_, asio_impl::execution::occupancy)); } + + [[nodiscard]] + auto executor() const { + return executor_; + } + private: [[nodiscard]] static constexpr auto forward_progress_guarantee() -> stdexec::forward_progress_guarantee { diff --git a/test/execpools/test_asio_thread_pool.cpp b/test/execpools/test_asio_thread_pool.cpp index 9b54586e6..5df38701d 100644 --- a/test/execpools/test_asio_thread_pool.cpp +++ b/test/execpools/test_asio_thread_pool.cpp @@ -29,6 +29,8 @@ #include +#include + namespace ex = stdexec; namespace { @@ -168,4 +170,20 @@ namespace { REQUIRE(value.data() == output.data()); CHECK(output == std::array{1.0, 3.0, 2.0, 0.0}); } + + TEST_CASE("asiothreadpool with asioexec interoperability") { + const auto current_thread_id = std::this_thread::get_id(); + + execpools::asio_thread_pool pool{1ul}; + asioexec::asio_impl::system_timer timer{pool.executor()}; + const auto [other_thread_id] = + stdexec::sync_wait(timer.async_wait(asioexec::use_sender) | stdexec::then([](auto&&...) { + return std::this_thread::get_id(); + })) + .value(); + REQUIRE(current_thread_id != other_thread_id); + + // demo to access underlying execution context + asioexec::asio_impl::query(pool.executor(), asioexec::asio_impl::execution::context_t{}).stop(); + } } // namespace From fa52e97ec9f320a85ad5a86f9a377eff016f8ab6 Mon Sep 17 00:00:00 2001 From: Mathis Logemann <13556116+mathisloge@users.noreply.github.com> Date: Sat, 24 May 2025 09:58:07 +0200 Subject: [PATCH 2/2] [asio_thread_pool] Change executor to get_executor --- include/execpools/asio/asio_thread_pool.hpp | 2 +- test/execpools/test_asio_thread_pool.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/execpools/asio/asio_thread_pool.hpp b/include/execpools/asio/asio_thread_pool.hpp index dc1153854..2bf42ce92 100644 --- a/include/execpools/asio/asio_thread_pool.hpp +++ b/include/execpools/asio/asio_thread_pool.hpp @@ -32,7 +32,7 @@ namespace execpools { } [[nodiscard]] - auto executor() const { + auto get_executor() const { return executor_; } diff --git a/test/execpools/test_asio_thread_pool.cpp b/test/execpools/test_asio_thread_pool.cpp index 5df38701d..253421b80 100644 --- a/test/execpools/test_asio_thread_pool.cpp +++ b/test/execpools/test_asio_thread_pool.cpp @@ -175,7 +175,7 @@ namespace { const auto current_thread_id = std::this_thread::get_id(); execpools::asio_thread_pool pool{1ul}; - asioexec::asio_impl::system_timer timer{pool.executor()}; + asioexec::asio_impl::system_timer timer{pool.get_executor()}; const auto [other_thread_id] = stdexec::sync_wait(timer.async_wait(asioexec::use_sender) | stdexec::then([](auto&&...) { return std::this_thread::get_id(); @@ -184,6 +184,6 @@ namespace { REQUIRE(current_thread_id != other_thread_id); // demo to access underlying execution context - asioexec::asio_impl::query(pool.executor(), asioexec::asio_impl::execution::context_t{}).stop(); + asioexec::asio_impl::query(pool.get_executor(), asioexec::asio_impl::execution::context_t{}).stop(); } } // namespace