From 268b225a52930885ef801940ef16dc8ca610d81e Mon Sep 17 00:00:00 2001 From: Hartmut Kaiser Date: Fri, 18 Aug 2023 15:18:07 -0500 Subject: [PATCH] Fixing test failure - flyby: remove stubs from example --- .../cancelable_action/cancelable_action.cpp | 10 ++--- .../cancelable_action/cancelable_action.hpp | 22 +++++----- .../server/cancelable_action.hpp | 37 ++++++++++------ .../stubs/cancelable_action.hpp | 43 ------------------- .../cancelable_action_client.cpp | 5 ++- .../hpx/parcelports/init_all_parcelports.hpp | 6 +-- 6 files changed, 47 insertions(+), 76 deletions(-) delete mode 100644 examples/cancelable_action/cancelable_action/stubs/cancelable_action.hpp diff --git a/examples/cancelable_action/cancelable_action/cancelable_action.cpp b/examples/cancelable_action/cancelable_action/cancelable_action.cpp index 189b352e556c..8c176f414cc2 100644 --- a/examples/cancelable_action/cancelable_action/cancelable_action.cpp +++ b/examples/cancelable_action/cancelable_action/cancelable_action.cpp @@ -1,14 +1,14 @@ -// Copyright (c) 2007-2012 Hartmut Kaiser +// Copyright (c) 2007-2023 Hartmut Kaiser // // SPDX-License-Identifier: BSL-1.0 // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #include + #if !defined(HPX_COMPUTE_DEVICE_CODE) -#include #include -#include +#include #include "server/cancelable_action.hpp" @@ -17,8 +17,8 @@ HPX_REGISTER_COMPONENT_MODULE() /////////////////////////////////////////////////////////////////////////////// -typedef hpx::components::component - cancelable_action_component_type; +using cancelable_action_component_type = + hpx::components::component; HPX_REGISTER_COMPONENT(cancelable_action_component_type, cancelable_action) diff --git a/examples/cancelable_action/cancelable_action/cancelable_action.hpp b/examples/cancelable_action/cancelable_action/cancelable_action.hpp index cd660ff0e4ab..372ac05e1ebd 100644 --- a/examples/cancelable_action/cancelable_action/cancelable_action.hpp +++ b/examples/cancelable_action/cancelable_action/cancelable_action.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2007-2011 Hartmut Kaiser +// Copyright (c) 2007-2023 Hartmut Kaiser // // SPDX-License-Identifier: BSL-1.0 // Distributed under the Boost Software License, Version 1.0. (See accompanying @@ -11,21 +11,21 @@ #include #include -#include "stubs/cancelable_action.hpp" +#include "server/cancelable_action.hpp" #include namespace examples { + /////////////////////////////////////////////////////////////////////////// // Client side representation for for the \a server::cancelable_action // component. class cancelable_action : public hpx::components::client_base + server::cancelable_action> { - typedef hpx::components::client_base - base_type; + using base_type = hpx::components::client_base; public: // Default construct an empty client side representation (not @@ -45,16 +45,18 @@ namespace examples { } /////////////////////////////////////////////////////////////////////// - void do_it(hpx::error_code& ec = hpx::throws) + void do_it(hpx::error_code& ec = hpx::throws) const { + using action_type = server::cancelable_action::do_it_action; HPX_ASSERT(this->get_id()); - this->base_type::do_it(this->get_id(), ec); + hpx::async(this->get_id()).get(ec); } - void cancel_it() + void cancel_it() const { + using action_type = server::cancelable_action::cancel_it_action; HPX_ASSERT(this->get_id()); - this->base_type::cancel_it(this->get_id()); + hpx::post(this->get_id()); } }; } // namespace examples diff --git a/examples/cancelable_action/cancelable_action/server/cancelable_action.hpp b/examples/cancelable_action/cancelable_action/server/cancelable_action.hpp index b3b9de3e62f7..9c131d256650 100644 --- a/examples/cancelable_action/cancelable_action/server/cancelable_action.hpp +++ b/examples/cancelable_action/cancelable_action/server/cancelable_action.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2007-2022 Hartmut Kaiser +// Copyright (c) 2007-2023 Hartmut Kaiser // // SPDX-License-Identifier: BSL-1.0 // Distributed under the Boost Software License, Version 1.0. (See accompanying @@ -7,18 +7,22 @@ #pragma once #include + #if !defined(HPX_COMPUTE_DEVICE_CODE) -#include +#include + #include #include #include #include #include +#include #include /////////////////////////////////////////////////////////////////////////////// -namespace examples { namespace server { +namespace examples::server { + /////////////////////////////////////////////////////////////////////////// inline void delay(int c) { @@ -50,24 +54,29 @@ namespace examples { namespace server { explicit reset_id(cancelable_action& this_) : outer_(this_) { - std::lock_guard l(outer_.mtx_); - hpx::thread::id old_value = outer_.id_; + auto const mtx = outer_.mtx_; + std::lock_guard l(*mtx); + + [[maybe_unused]] hpx::thread::id const old_value = outer_.id_; outer_.id_ = hpx::this_thread::get_id(); HPX_ASSERT(old_value == hpx::thread::id()); - HPX_UNUSED(old_value); } ~reset_id() { - hpx::thread::id old_value = outer_.id_; + [[maybe_unused]] hpx::thread::id const old_value = outer_.id_; outer_.id_ = hpx::thread::id(); HPX_ASSERT(old_value != hpx::thread::id()); - HPX_UNUSED(old_value); } cancelable_action& outer_; }; public: + cancelable_action() + : mtx_(std::make_shared()) + { + } + // Do some lengthy work void do_it() { @@ -85,15 +94,17 @@ namespace examples { namespace server { } // Cancel the lengthy action above - void cancel_it() + void cancel_it() const { // Make sure id_ has been set hpx::util::yield_while([this]() { - std::lock_guard l(mtx_); + auto const mtx = mtx_; + std::lock_guard l(*mtx); return id_ == hpx::thread::id(); }); - std::lock_guard l(mtx_); + auto const mtx = mtx_; + std::lock_guard l(*mtx); HPX_ASSERT(id_ != hpx::thread::id()); hpx::thread::interrupt(id_); } @@ -103,10 +114,10 @@ namespace examples { namespace server { cancelable_action, cancel_it, cancel_it_action) private: - hpx::mutex mtx_; + std::shared_ptr mtx_; hpx::thread::id id_; }; -}} // namespace examples::server +} // namespace examples::server /////////////////////////////////////////////////////////////////////////////// HPX_REGISTER_ACTION_DECLARATION( diff --git a/examples/cancelable_action/cancelable_action/stubs/cancelable_action.hpp b/examples/cancelable_action/cancelable_action/stubs/cancelable_action.hpp deleted file mode 100644 index e7253a683c72..000000000000 --- a/examples/cancelable_action/cancelable_action/stubs/cancelable_action.hpp +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (c) 2007-2012 Hartmut Kaiser -// -// SPDX-License-Identifier: BSL-1.0 -// Distributed under the Boost Software License, Version 1.0. (See accompanying -// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - -#pragma once - -#include -#if !defined(HPX_COMPUTE_DEVICE_CODE) -#include - -#include "../server/cancelable_action.hpp" - -/////////////////////////////////////////////////////////////////////////////// -namespace examples { namespace stubs { - /////////////////////////////////////////////////////////////////////////// - struct cancelable_action - : hpx::components::stub_base - { - // Do some lengthy work - static hpx::future do_it_async(hpx::id_type const& gid) - { - typedef server::cancelable_action::do_it_action action_type; - return hpx::async(gid); - } - - static void do_it( - hpx::id_type const& gid, hpx::error_code& ec = hpx::throws) - { - do_it_async(gid).get(ec); - } - - // Cancel the lengthy action above - static void cancel_it(hpx::id_type const& gid) - { - typedef server::cancelable_action::cancel_it_action action_type; - hpx::post(gid); - } - }; -}} // namespace examples::stubs - -#endif diff --git a/examples/cancelable_action/cancelable_action_client.cpp b/examples/cancelable_action/cancelable_action_client.cpp index 5d025fa10e2b..11e166230083 100644 --- a/examples/cancelable_action/cancelable_action_client.cpp +++ b/examples/cancelable_action/cancelable_action_client.cpp @@ -1,10 +1,11 @@ -// Copyright (c) 2007-2012 Hartmut Kaiser +// Copyright (c) 2007-2023 Hartmut Kaiser // // SPDX-License-Identifier: BSL-1.0 // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #include + #if !defined(HPX_COMPUTE_DEVICE_CODE) #include #include @@ -12,7 +13,7 @@ #include "cancelable_action/cancelable_action.hpp" /////////////////////////////////////////////////////////////////////////////// -void interrupt_do_it(examples::cancelable_action ca) +void interrupt_do_it(examples::cancelable_action const& ca) { // wait for one second before interrupting the (possibly remote) operation hpx::this_thread::sleep_for(std::chrono::seconds(1)); diff --git a/libs/full/parcelports/include/hpx/parcelports/init_all_parcelports.hpp b/libs/full/parcelports/include/hpx/parcelports/init_all_parcelports.hpp index 554173676522..2c4c2eb190db 100644 --- a/libs/full/parcelports/include/hpx/parcelports/init_all_parcelports.hpp +++ b/libs/full/parcelports/include/hpx/parcelports/init_all_parcelports.hpp @@ -10,10 +10,10 @@ #if defined(HPX_HAVE_NETWORKING) -namespace hpx::parcelset -{ +namespace hpx::parcelset { + // force linking with this module HPX_EXPORT void init_all_parcelports(); -} +} // namespace hpx::parcelset #endif