From c7fcdf5346c62ea82aba490d6569596e6f5f19f9 Mon Sep 17 00:00:00 2001 From: Mikael Simberg Date: Tue, 11 Jul 2023 11:04:15 +0200 Subject: [PATCH] Add pika::wait as a public wrapper function for thread_manager::wait --- .../include/pika/init_runtime/init_runtime.hpp | 1 + libs/pika/init_runtime/src/init_runtime.cpp | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/libs/pika/init_runtime/include/pika/init_runtime/init_runtime.hpp b/libs/pika/init_runtime/include/pika/init_runtime/init_runtime.hpp index 78971d76a..b2d36f63d 100644 --- a/libs/pika/init_runtime/include/pika/init_runtime/init_runtime.hpp +++ b/libs/pika/init_runtime/include/pika/init_runtime/init_runtime.hpp @@ -143,6 +143,7 @@ namespace pika { init_params const& params = init_params()); PIKA_EXPORT int finalize(error_code& ec = throws); PIKA_EXPORT int stop(error_code& ec = throws); + PIKA_EXPORT int wait(error_code& ec = throws); PIKA_EXPORT int suspend(error_code& ec = throws); PIKA_EXPORT int resume(error_code& ec = throws); } // namespace pika diff --git a/libs/pika/init_runtime/src/init_runtime.cpp b/libs/pika/init_runtime/src/init_runtime.cpp index a1d573536..c6e9c9077 100644 --- a/libs/pika/init_runtime/src/init_runtime.cpp +++ b/libs/pika/init_runtime/src/init_runtime.cpp @@ -217,6 +217,21 @@ namespace pika { return result; } + int wait(error_code& ec) + { + runtime* rt = get_runtime_ptr(); + if (nullptr == rt) + { + PIKA_THROWS_IF(ec, pika::error::invalid_status, "pika::wait", + "the runtime system is not active (did you already call pika::stop?)"); + return -1; + } + + rt->get_thread_manager().wait(); + + return 0; + } + int suspend(error_code& ec) { if (threads::detail::get_self_ptr())