From fdd1bce80bf975e34ad7fc6371be4a5e5665d103 Mon Sep 17 00:00:00 2001 From: Hartmut Kaiser Date: Wed, 20 Mar 2024 14:31:12 -0500 Subject: [PATCH] Ignoring locks to avoid exceptions --- .circleci/config.yml | 3 +- .github/workflows/linux_debug.yml | 3 + .github/workflows/linux_debug_fetch_hwloc.yml | 3 + .github/workflows/macos_debug.yml | 3 + .github/workflows/macos_debug_fetch_hwloc.yml | 3 + .github/workflows/windows_clang_debug.yml | 4 +- .github/workflows/windows_debug_vs2019.yml | 3 + .github/workflows/windows_debug_vs2022.yml | 3 + .../windows_debug_vs2022_fetch_hwloc.yml | 4 + .jenkins/lsu/env-common.sh | 3 + CMakeLists.txt | 8 +- .../hpx/components/iostreams/ostream.hpp | 8 +- libs/core/assertion/CMakeLists.txt | 2 +- libs/core/futures/CMakeLists.txt | 1 + .../hpx/futures/detail/future_data.hpp | 9 +- .../io_service/src/io_service_thread_pool.cpp | 4 +- libs/core/lcos_local/CMakeLists.txt | 1 + .../include/hpx/lcos_local/and_gate.hpp | 2 +- .../include/hpx/lcos_local/channel.hpp | 4 +- .../lcos_local/detail/preprocess_future.hpp | 28 ++-- .../include/hpx/lcos_local/trigger.hpp | 4 +- libs/core/lock_registration/CMakeLists.txt | 17 ++- .../detail/register_locks.hpp | 125 +++++++++++++++--- .../lock_registration/src/register_locks.cpp | 121 ++++++++++------- libs/core/runtime_local/CMakeLists.txt | 1 + .../core/runtime_local/src/interval_timer.cpp | 2 +- libs/core/schedulers/CMakeLists.txt | 1 + .../include/hpx/schedulers/thread_queue.hpp | 2 +- libs/core/synchronization/CMakeLists.txt | 3 +- .../include/hpx/synchronization/barrier.hpp | 4 +- .../synchronization/condition_variable.hpp | 4 +- .../hpx/synchronization/shared_mutex.hpp | 5 +- .../src/detail/condition_variable.cpp | 4 +- .../src/detail/counting_semaphore.cpp | 4 +- .../src/detail/sliding_semaphore.cpp | 4 +- libs/core/synchronization/src/mutex.cpp | 1 + libs/core/thread_support/CMakeLists.txt | 12 +- libs/core/type_support/CMakeLists.txt | 4 +- .../hpx/type_support}/assert_owns_lock.hpp | 3 +- libs/full/agas/src/addressing_service.cpp | 2 +- .../src/server/primary_namespace_server.cpp | 4 +- libs/full/collectives/CMakeLists.txt | 2 + .../detail/communication_set_node.hpp | 4 +- .../hpx/collectives/detail/communicator.hpp | 7 +- .../tests/unit/concurrent_collectives.cpp | 11 +- .../include/hpx/parcelset/parcelport_impl.hpp | 7 - 46 files changed, 306 insertions(+), 151 deletions(-) rename libs/core/{thread_support/include/hpx/thread_support => type_support/include/hpx/type_support}/assert_owns_lock.hpp (95%) diff --git a/.circleci/config.yml b/.circleci/config.yml index 014765077dda..c42efad5aaa4 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,5 +1,6 @@ # Copyright (c) 2017-2018 Thomas Heller # Copyright (c) 2015 Martin Stumpf +# Copyright (c) 2022-2024 Hartmut Kaiser # # SPDX-License-Identifier: BSL-1.0 # Distributed under the Boost Software License, Version 1.0. (See accompanying @@ -777,7 +778,7 @@ jobs: # is enabled, and other machines may fail similarly. # # Having to reconfigure here forces everything to be rebuilt, thus - # we disable it all together. + # we disable it altogether. # # cmake \ # -DHPX_WITH_DATAPAR_VC=Off . diff --git a/.github/workflows/linux_debug.yml b/.github/workflows/linux_debug.yml index c6c1685f0250..551e6d7215b2 100644 --- a/.github/workflows/linux_debug.yml +++ b/.github/workflows/linux_debug.yml @@ -1,4 +1,5 @@ # Copyright (c) 2020 ETH Zurich +# Copyright (c) 2024 The STE||AR Group # # SPDX-License-Identifier: BSL-1.0 # Distributed under the Boost Software License, Version 1.0. (See accompanying @@ -28,6 +29,8 @@ jobs: -DHPX_WITH_EXAMPLES=ON \ -DHPX_WITH_TESTS=ON \ -DHPX_WITH_TESTS_MAX_THREADS_PER_LOCALITY=2 \ + -DHPX_WITH_VERIFY_LOCKS=ON \ + -DHPX_WITH_VERIFY_LOCKS_BACKTRACE=ON \ -DHPX_WITH_CHECK_MODULE_DEPENDENCIES=On - name: Build shell: bash diff --git a/.github/workflows/linux_debug_fetch_hwloc.yml b/.github/workflows/linux_debug_fetch_hwloc.yml index 0ec32cda5c0d..df887921e4ad 100644 --- a/.github/workflows/linux_debug_fetch_hwloc.yml +++ b/.github/workflows/linux_debug_fetch_hwloc.yml @@ -1,4 +1,5 @@ # Copyright (c) 2024 Vedant Nimje +# Copyright (c) 2024 The STE||AR Group # # SPDX-License-Identifier: BSL-1.0 # Distributed under the Boost Software License, Version 1.0. (See accompanying @@ -32,6 +33,8 @@ jobs: -DHPX_WITH_EXAMPLES=ON \ -DHPX_WITH_TESTS=ON \ -DHPX_WITH_TESTS_MAX_THREADS_PER_LOCALITY=2 \ + -DHPX_WITH_VERIFY_LOCKS=ON \ + -DHPX_WITH_VERIFY_LOCKS_BACKTRACE=ON \ -DHPX_WITH_CHECK_MODULE_DEPENDENCIES=On - name: Build diff --git a/.github/workflows/macos_debug.yml b/.github/workflows/macos_debug.yml index 3ddb09f960f0..de39c7c871f5 100644 --- a/.github/workflows/macos_debug.yml +++ b/.github/workflows/macos_debug.yml @@ -1,4 +1,5 @@ # Copyright (c) 2020 Mikael Simberg +# Copyright (c) 2024 The STE||AR Group # # SPDX-License-Identifier: BSL-1.0 # Distributed under the Boost Software License, Version 1.0. (See accompanying @@ -38,6 +39,8 @@ jobs: -DHPX_WITH_EXAMPLES=ON \ -DHPX_WITH_TESTS=ON \ -DHPX_WITH_TESTS_MAX_THREADS_PER_LOCALITY=3 \ + -DHPX_WITH_VERIFY_LOCKS=ON \ + -DHPX_WITH_VERIFY_LOCKS_BACKTRACE=ON \ -DHPX_WITH_CHECK_MODULE_DEPENDENCIES=ON - name: Build shell: bash diff --git a/.github/workflows/macos_debug_fetch_hwloc.yml b/.github/workflows/macos_debug_fetch_hwloc.yml index e8ad7ab94dca..628baf14827a 100644 --- a/.github/workflows/macos_debug_fetch_hwloc.yml +++ b/.github/workflows/macos_debug_fetch_hwloc.yml @@ -1,4 +1,5 @@ # Copyright (c) 2024 Vedant Nimje +# Copyright (c) 2024 The STE||AR Group # # SPDX-License-Identifier: BSL-1.0 # Distributed under the Boost Software License, Version 1.0. (See accompanying @@ -39,6 +40,8 @@ jobs: -DHPX_WITH_EXAMPLES=ON \ -DHPX_WITH_TESTS=ON \ -DHPX_WITH_TESTS_MAX_THREADS_PER_LOCALITY=3 \ + -DHPX_WITH_VERIFY_LOCKS=ON \ + -DHPX_WITH_VERIFY_LOCKS_BACKTRACE=ON \ -DHPX_WITH_CHECK_MODULE_DEPENDENCIES=ON - name: Build shell: bash diff --git a/.github/workflows/windows_clang_debug.yml b/.github/workflows/windows_clang_debug.yml index e888de86cb0f..2da4c6b4a9e6 100644 --- a/.github/workflows/windows_clang_debug.yml +++ b/.github/workflows/windows_clang_debug.yml @@ -1,5 +1,5 @@ # Copyright (c) 2020 Mikael Simberg -# Copyright (c) 2022 Hartmut Kaiser +# Copyright (c) 2022-2024 Hartmut Kaiser # # SPDX-License-Identifier: BSL-1.0 # Distributed under the Boost Software License, Version 1.0. (See accompanying @@ -37,6 +37,8 @@ jobs: -DHPX_WITH_DEPRECATION_WARNINGS=OFF \ -DHPX_WITH_TESTS_MAX_THREADS_PER_LOCALITY=2 \ -DHPX_COROUTINES_WITH_SWAP_CONTEXT_EMULATION=ON \ + -DHPX_WITH_VERIFY_LOCKS=ON \ + -DHPX_WITH_VERIFY_LOCKS_BACKTRACE=ON \ -DHPX_WITH_CHECK_MODULE_DEPENDENCIES=On \ - name: Build shell: bash diff --git a/.github/workflows/windows_debug_vs2019.yml b/.github/workflows/windows_debug_vs2019.yml index 48a50dfd105d..4ef381b46f08 100644 --- a/.github/workflows/windows_debug_vs2019.yml +++ b/.github/workflows/windows_debug_vs2019.yml @@ -1,4 +1,5 @@ # Copyright (c) 2020 Mikael Simberg +# Copyright (c) 2024 The STE||AR Group # # SPDX-License-Identifier: BSL-1.0 # Distributed under the Boost Software License, Version 1.0. (See accompanying @@ -36,6 +37,8 @@ jobs: -DHPX_WITH_DEPRECATION_WARNINGS=OFF \ -DHPX_WITH_TESTS_MAX_THREADS_PER_LOCALITY=2 \ -DHPX_COROUTINES_WITH_SWAP_CONTEXT_EMULATION=ON \ + -DHPX_WITH_VERIFY_LOCKS=ON \ + -DHPX_WITH_VERIFY_LOCKS_BACKTRACE=ON \ -DHPX_WITH_CHECK_MODULE_DEPENDENCIES=On - name: Build shell: bash diff --git a/.github/workflows/windows_debug_vs2022.yml b/.github/workflows/windows_debug_vs2022.yml index d9dead6fc17c..74d23bfc4973 100644 --- a/.github/workflows/windows_debug_vs2022.yml +++ b/.github/workflows/windows_debug_vs2022.yml @@ -1,4 +1,5 @@ # Copyright (c) 2020 Mikael Simberg +# Copyright (c) 2024 The STE||AR Group # # SPDX-License-Identifier: BSL-1.0 # Distributed under the Boost Software License, Version 1.0. (See accompanying @@ -36,6 +37,8 @@ jobs: -DHPX_WITH_DEPRECATION_WARNINGS=OFF \ -DHPX_WITH_TESTS_MAX_THREADS_PER_LOCALITY=2 \ -DHPX_COROUTINES_WITH_SWAP_CONTEXT_EMULATION=ON \ + -DHPX_WITH_VERIFY_LOCKS=ON \ + -DHPX_WITH_VERIFY_LOCKS_BACKTRACE=ON \ -DHPX_WITH_CHECK_MODULE_DEPENDENCIES=On - name: Build shell: bash diff --git a/.github/workflows/windows_debug_vs2022_fetch_hwloc.yml b/.github/workflows/windows_debug_vs2022_fetch_hwloc.yml index b4e70a76850b..5054c2468412 100644 --- a/.github/workflows/windows_debug_vs2022_fetch_hwloc.yml +++ b/.github/workflows/windows_debug_vs2022_fetch_hwloc.yml @@ -1,4 +1,5 @@ # Copyright (c) 2024 Vedant Nimje +# Copyright (c) 2024 The STE||AR Group # # SPDX-License-Identifier: BSL-1.0 # Distributed under the Boost Software License, Version 1.0. (See accompanying @@ -37,6 +38,9 @@ jobs: -DHPX_WITH_DEPRECATION_WARNINGS=OFF \ -DHPX_WITH_TESTS_MAX_THREADS_PER_LOCALITY=2 \ -DHPX_COROUTINES_WITH_SWAP_CONTEXT_EMULATION=ON \ + -DHPX_COROUTINES_WITH_SWAP_CONTEXT_EMULATION=ON \ + -DHPX_WITH_VERIFY_LOCKS=ON \ + -DHPX_WITH_VERIFY_LOCKS_BACKTRACE=ON \ -DHPX_WITH_CHECK_MODULE_DEPENDENCIES=On - name: Build shell: bash diff --git a/.jenkins/lsu/env-common.sh b/.jenkins/lsu/env-common.sh index f0bd7e5dd00b..15e4b4e91f3f 100644 --- a/.jenkins/lsu/env-common.sh +++ b/.jenkins/lsu/env-common.sh @@ -1,4 +1,5 @@ # Copyright (c) 2021 ETH Zurich +# Copyright (c) 2024 The STE||AR Group # # SPDX-License-Identifier: BSL-1.0 # Distributed under the Boost Software License, Version 1.0. (See accompanying @@ -9,6 +10,8 @@ configure_extra_options+=" -DHPX_WITH_CHECK_MODULE_DEPENDENCIES=ON" if [ "${build_type}" = "Debug" ]; then configure_extra_options+=" -DHPX_WITH_PARCELPORT_COUNTERS=ON" configure_extra_options+=" -DLCI_DEBUG=ON" + configure_extra_options+=" -DHPX_WITH_VERIFY_LOCKS=ON" +# configure_extra_options+=" -DHPX_WITH_VERIFY_LOCKS_BACKTRACE=ON" fi ctest_extra_args+=" --verbose " diff --git a/CMakeLists.txt b/CMakeLists.txt index febddff9ad22..e24967c30db5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1392,15 +1392,9 @@ hpx_option( OFF CATEGORY "Debugging" ) -set(HPX_WITH_VERIFY_LOCKS_DEFAULT OFF) -if(${CMAKE_BUILD_TYPE} STREQUAL "Debug") - set(HPX_WITH_VERIFY_LOCKS_DEFAULT ON) -endif() - hpx_option( HPX_WITH_VERIFY_LOCKS BOOL - "Enable lock verification code (default: OFF, enabled in debug builds)" - ${HPX_WITH_VERIFY_LOCKS_DEFAULT} + "Enable lock verification code (default: OFF, enabled in debug builds)" OFF CATEGORY "Debugging" ADVANCED ) diff --git a/components/iostreams/include/hpx/components/iostreams/ostream.hpp b/components/iostreams/include/hpx/components/iostreams/ostream.hpp index 7d1889d326eb..3918eaa8e7ec 100644 --- a/components/iostreams/include/hpx/components/iostreams/ostream.hpp +++ b/components/iostreams/include/hpx/components/iostreams/ostream.hpp @@ -269,14 +269,13 @@ namespace hpx { namespace iostreams { // Create the next buffer, returns the previous buffer buffer next = this->detail::buffer::init_locked(); - // Unlock the mutex before we cleanup. + // Unlock the mutex before we clean up. l.unlock(); // since mtx_ is recursive and apply will do an AGAS lookup, // we need to ignore the lock here in case we are called // recursively - hpx::util::ignore_while_checking il(&l); - HPX_UNUSED(il); + [[maybe_unused]] hpx::util::ignore_while_checking il(&l); // Perform the write operation, then destroy the old buffer and // stream. @@ -367,8 +366,7 @@ namespace hpx { namespace iostreams { ostream& operator<<(std_stream_type& (*manip_fun)(std_stream_type&) ) { std::unique_lock l(*mtx_); - util::ignore_while_checking ignore(&l); - HPX_UNUSED(ignore); + [[maybe_unused]] util::ignore_while_checking ignore(&l); return streaming_operator_lazy(manip_fun); } diff --git a/libs/core/assertion/CMakeLists.txt b/libs/core/assertion/CMakeLists.txt index 51574fa2fb7c..3a281e484a2d 100644 --- a/libs/core/assertion/CMakeLists.txt +++ b/libs/core/assertion/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2019 The STE||AR-Group +# Copyright (c) 2019-2024 The STE||AR-Group # # SPDX-License-Identifier: BSL-1.0 # Distributed under the Boost Software License, Version 1.0. (See accompanying diff --git a/libs/core/futures/CMakeLists.txt b/libs/core/futures/CMakeLists.txt index a7b48127e601..3387538bd92b 100644 --- a/libs/core/futures/CMakeLists.txt +++ b/libs/core/futures/CMakeLists.txt @@ -72,6 +72,7 @@ add_hpx_module( hpx_errors hpx_functional hpx_logging + hpx_lock_registration hpx_memory hpx_serialization hpx_synchronization diff --git a/libs/core/futures/include/hpx/futures/detail/future_data.hpp b/libs/core/futures/include/hpx/futures/detail/future_data.hpp index c0be2e72a328..2f108651a6d1 100644 --- a/libs/core/futures/include/hpx/futures/detail/future_data.hpp +++ b/libs/core/futures/include/hpx/futures/detail/future_data.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2007-2023 Hartmut Kaiser +// Copyright (c) 2007-2024 Hartmut Kaiser // // SPDX-License-Identifier: BSL-1.0 // Distributed under the Boost Software License, Version 1.0. (See accompanying @@ -17,12 +17,13 @@ #include #include #include +#include #include #include #include -#include #include #include +#include #include #include @@ -467,6 +468,7 @@ namespace hpx::lcos::detail { // At this point the lock needs to be acquired to safely access the // registered continuations std::unique_lock l(mtx_); + [[maybe_unused]] util::ignore_while_checking il(&l); // handle all threads waiting for the future to become ready auto on_completed = HPX_MOVE(on_completed_); @@ -514,6 +516,7 @@ namespace hpx::lcos::detail { // Note: cv.notify_one() above 'consumes' the lock 'l' and leaves // it unlocked when returning. HPX_ASSERT_DOESNT_OWN_LOCK(l); + il.reset_owns_registration(); // invoke the callback (continuation) function if (!on_completed.empty()) @@ -544,6 +547,7 @@ namespace hpx::lcos::detail { // At this point the lock needs to be acquired to safely access the // registered continuations std::unique_lock l(mtx_); + [[maybe_unused]] util::ignore_while_checking il(&l); // handle all threads waiting for the future to become ready auto on_completed = HPX_MOVE(on_completed_); @@ -591,6 +595,7 @@ namespace hpx::lcos::detail { // Note: cv.notify_one() above 'consumes' the lock 'l' and leaves // it unlocked when returning. HPX_ASSERT_DOESNT_OWN_LOCK(l); + il.reset_owns_registration(); // invoke the callback (continuation) function if (!on_completed.empty()) diff --git a/libs/core/io_service/src/io_service_thread_pool.cpp b/libs/core/io_service/src/io_service_thread_pool.cpp index ec05ba5775a4..ee0772aa685e 100644 --- a/libs/core/io_service/src/io_service_thread_pool.cpp +++ b/libs/core/io_service/src/io_service_thread_pool.cpp @@ -78,10 +78,10 @@ namespace hpx::threads::detail { /////////////////////////////////////////////////////////////////////////// bool io_service_thread_pool::run( - std::unique_lock& l, std::size_t num_threads) + [[maybe_unused]] std::unique_lock& l, + std::size_t num_threads) { HPX_ASSERT(l.owns_lock()); - HPX_UNUSED(l); util::barrier startup(1); return threads_->run(num_threads, false, &startup); } diff --git a/libs/core/lcos_local/CMakeLists.txt b/libs/core/lcos_local/CMakeLists.txt index f9ad5b60cb50..d4978905a229 100644 --- a/libs/core/lcos_local/CMakeLists.txt +++ b/libs/core/lcos_local/CMakeLists.txt @@ -56,5 +56,6 @@ add_hpx_module( hpx_pack_traversal hpx_errors hpx_memory + hpx_type_support CMAKE_SUBDIRS examples tests ) diff --git a/libs/core/lcos_local/include/hpx/lcos_local/and_gate.hpp b/libs/core/lcos_local/include/hpx/lcos_local/and_gate.hpp index 96fe88bdd5a5..bf5134ae1a8f 100644 --- a/libs/core/lcos_local/include/hpx/lcos_local/and_gate.hpp +++ b/libs/core/lcos_local/include/hpx/lcos_local/and_gate.hpp @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include #include diff --git a/libs/core/lcos_local/include/hpx/lcos_local/channel.hpp b/libs/core/lcos_local/include/hpx/lcos_local/channel.hpp index a92c7a685223..1c0ba4c93a7e 100644 --- a/libs/core/lcos_local/include/hpx/lcos_local/channel.hpp +++ b/libs/core/lcos_local/include/hpx/lcos_local/channel.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2022 Hartmut Kaiser +// Copyright (c) 2016-2024 Hartmut Kaiser // // SPDX-License-Identifier: BSL-1.0 // Distributed under the Boost Software License, Version 1.0. (See accompanying @@ -18,9 +18,9 @@ #include #include #include -#include #include #include +#include #include #include diff --git a/libs/core/lcos_local/include/hpx/lcos_local/detail/preprocess_future.hpp b/libs/core/lcos_local/include/hpx/lcos_local/detail/preprocess_future.hpp index 9fa015d211a3..dbe789a20939 100644 --- a/libs/core/lcos_local/include/hpx/lcos_local/detail/preprocess_future.hpp +++ b/libs/core/lcos_local/include/hpx/lcos_local/detail/preprocess_future.hpp @@ -70,8 +70,8 @@ namespace hpx::serialization::detail { void trigger() { - // hpx::lcos::local::promise<>::set_value() might need to acquire - // a lock, as such, we check the our triggering condition inside a + // hpx::lcos::local::promise<>::set_value() might need to acquire a + // lock, as such, we check our triggering condition inside a // critical section and trigger the promise outside of it. bool set_value = false; @@ -195,17 +195,15 @@ namespace hpx::serialization::detail { }; } // namespace hpx::serialization::detail -namespace hpx::util { - - // This is explicitly instantiated to ensure that the id is stable across - // shared libraries. - template <> - struct extra_data_helper +// This is explicitly instantiated to ensure that the id is stable across +// shared libraries. +template <> +struct hpx::util::extra_data_helper< + hpx::serialization::detail::preprocess_futures> +{ + HPX_CORE_EXPORT static hpx::util::extra_data_id_type id() noexcept; + static constexpr void reset( + hpx::serialization::detail::preprocess_futures*) noexcept { - HPX_CORE_EXPORT static extra_data_id_type id() noexcept; - static constexpr void reset( - serialization::detail::preprocess_futures*) noexcept - { - } - }; -} // namespace hpx::util + } +}; diff --git a/libs/core/lcos_local/include/hpx/lcos_local/trigger.hpp b/libs/core/lcos_local/include/hpx/lcos_local/trigger.hpp index f9272e2a930f..72d7ed8f91a1 100644 --- a/libs/core/lcos_local/include/hpx/lcos_local/trigger.hpp +++ b/libs/core/lcos_local/include/hpx/lcos_local/trigger.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2007-2022 Hartmut Kaiser +// Copyright (c) 2007-2024 Hartmut Kaiser // // SPDX-License-Identifier: BSL-1.0 // Distributed under the Boost Software License, Version 1.0. (See accompanying @@ -15,8 +15,8 @@ #include #include #include -#include #include +#include #include #include diff --git a/libs/core/lock_registration/CMakeLists.txt b/libs/core/lock_registration/CMakeLists.txt index a45f99381d73..ec7a46a2e45c 100644 --- a/libs/core/lock_registration/CMakeLists.txt +++ b/libs/core/lock_registration/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2021 The STE||AR-Group +# Copyright (c) 2019-2024 The STE||AR-Group # # SPDX-License-Identifier: BSL-1.0 # Distributed under the Boost Software License, Version 1.0. (See accompanying @@ -9,13 +9,24 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") set(lock_registration_headers hpx/lock_registration/detail/register_locks.hpp) set(lock_registration_sources register_locks.cpp) +if(HPX_WITH_VERIFY_LOCKS_BACKTRACE) + set(additional_dependencies hpx_debugging) +endif() + include(HPX_AddModule) add_hpx_module( core lock_registration GLOBAL_HEADER_GEN ON + ADD_TO_GLOBAL_HEADER "hpx/lock_registration/detail/register_locks.hpp" SOURCES ${lock_registration_sources} HEADERS ${lock_registration_headers} - DEPENDENCIES hpx_assertion hpx_concepts hpx_config hpx_errors hpx_functional - hpx_type_support + DEPENDENCIES + hpx_assertion + hpx_concepts + hpx_config + hpx_errors + hpx_functional + hpx_type_support + ${additional_dependencies} CMAKE_SUBDIRS examples tests ) diff --git a/libs/core/lock_registration/include/hpx/lock_registration/detail/register_locks.hpp b/libs/core/lock_registration/include/hpx/lock_registration/detail/register_locks.hpp index e043eb33711c..e2c84259a9ca 100644 --- a/libs/core/lock_registration/include/hpx/lock_registration/detail/register_locks.hpp +++ b/libs/core/lock_registration/include/hpx/lock_registration/detail/register_locks.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2007-2022 Hartmut Kaiser +// Copyright (c) 2007-2024 Hartmut Kaiser // Copyright (c) 2014 Thomas Heller // // SPDX-License-Identifier: BSL-1.0 @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include #include @@ -22,6 +22,8 @@ #include #endif +#include + /////////////////////////////////////////////////////////////////////////////// namespace hpx::util { @@ -41,6 +43,11 @@ namespace hpx::util { explicit lock_data(std::size_t trace_depth); lock_data(register_lock_data* data, std::size_t trace_depth); + lock_data(lock_data const&) = delete; + lock_data(lock_data&&) = delete; + lock_data& operator=(lock_data const&) = delete; + lock_data& operator=(lock_data&&) = delete; + ~lock_data(); bool ignore_; @@ -61,6 +68,11 @@ namespace hpx::util { { } + held_locks_data(held_locks_data const&) = delete; + held_locks_data(held_locks_data&&) = delete; + held_locks_data& operator=(held_locks_data const&) = delete; + held_locks_data& operator=(held_locks_data&&) = delete; + held_locks_map map_; bool enabled_; bool ignore_all_locks_; @@ -75,10 +87,10 @@ namespace hpx::util { HPX_CORE_EXPORT void enable_lock_detection() noexcept; HPX_CORE_EXPORT void disable_lock_detection() noexcept; HPX_CORE_EXPORT void trace_depth_lock_detection(std::size_t value) noexcept; - HPX_CORE_EXPORT void ignore_lock(void const* lock) noexcept; - HPX_CORE_EXPORT void reset_ignored(void const* lock) noexcept; - HPX_CORE_EXPORT void ignore_all_locks() noexcept; - HPX_CORE_EXPORT void reset_ignored_all() noexcept; + HPX_CORE_EXPORT bool ignore_lock(void const* lock) noexcept; + HPX_CORE_EXPORT bool reset_ignored(void const* lock) noexcept; + HPX_CORE_EXPORT bool ignore_all_locks() noexcept; + HPX_CORE_EXPORT bool reset_ignored_all() noexcept; using registered_locks_error_handler_type = hpx::function; @@ -104,14 +116,27 @@ namespace hpx::util { struct ignore_all_while_checking { ignore_all_while_checking() noexcept + : owns_registration_(ignore_all_locks()) { - ignore_all_locks(); } + ignore_all_while_checking(ignore_all_while_checking const&) = delete; + ignore_all_while_checking(ignore_all_while_checking&&) = delete; + ignore_all_while_checking& operator=( + ignore_all_while_checking const&) = delete; + ignore_all_while_checking& operator=( + ignore_all_while_checking&&) = delete; + ~ignore_all_while_checking() noexcept { - reset_ignored_all(); + if (owns_registration_) + { + reset_ignored_all(); + } } + + private: + bool owns_registration_; }; namespace detail { @@ -120,21 +145,75 @@ namespace hpx::util { } template >> + typename Enable = std::enable_if_t && + detail::has_owns_lock_v>> struct ignore_while_checking + { + explicit ignore_while_checking(Lock const* lock) noexcept + : mtx_(lock->owns_lock() ? lock->mutex() : nullptr) + , owns_registration_(false) + { + if (mtx_ != nullptr) + { + owns_registration_ = ignore_lock(mtx_); + } + } + + ignore_while_checking(ignore_while_checking const&) = delete; + ignore_while_checking(ignore_while_checking&&) = delete; + ignore_while_checking& operator=(ignore_while_checking const&) = delete; + ignore_while_checking& operator=(ignore_while_checking&&) = delete; + + ~ignore_while_checking() + { + if (mtx_ != nullptr && owns_registration_) + { + reset_ignored(mtx_); + } + } + + void reset_owns_registration() noexcept + { + owns_registration_ = false; + } + + private: + void const* mtx_; + bool owns_registration_; + }; + + template + struct ignore_while_checking && + !detail::has_owns_lock_v>> { explicit ignore_while_checking(Lock const* lock) noexcept : mtx_(lock->mutex()) + , owns_registration_(ignore_lock(mtx_)) { - ignore_lock(mtx_); } + ignore_while_checking(ignore_while_checking const&) = delete; + ignore_while_checking(ignore_while_checking&&) = delete; + ignore_while_checking& operator=(ignore_while_checking const&) = delete; + ignore_while_checking& operator=(ignore_while_checking&&) = delete; + ~ignore_while_checking() { - reset_ignored(mtx_); + if (owns_registration_) + { + reset_ignored(mtx_); + } + } + + void reset_owns_registration() noexcept + { + owns_registration_ = false; } + private: void const* mtx_; + bool owns_registration_; }; // The following functions are used to store the held locks information @@ -157,6 +236,8 @@ namespace hpx::util { explicit constexpr ignore_while_checking(Lock const* /*lock*/) noexcept { } + + constexpr void reset_owns_registration() noexcept {} }; struct ignore_all_while_checking @@ -181,11 +262,23 @@ namespace hpx::util { std::size_t /*value*/) noexcept { } - constexpr inline void ignore_lock(void const* /*lock*/) noexcept {} - constexpr inline void reset_ignored(void const* /*lock*/) noexcept {} + constexpr inline bool ignore_lock(void const* /*lock*/) noexcept + { + return true; + } + constexpr inline bool reset_ignored(void const* /*lock*/) noexcept + { + return true; + } - constexpr inline void ignore_all_locks() noexcept {} - constexpr inline void reset_ignored_all() noexcept {} + constexpr inline bool ignore_all_locks() noexcept + { + return true; + } + constexpr inline bool reset_ignored_all() noexcept + { + return true; + } struct held_locks_data { @@ -200,3 +293,5 @@ namespace hpx::util { #endif } // namespace hpx::util + +#include diff --git a/libs/core/lock_registration/src/register_locks.cpp b/libs/core/lock_registration/src/register_locks.cpp index fe76203f8dea..5106165347ed 100644 --- a/libs/core/lock_registration/src/register_locks.cpp +++ b/libs/core/lock_registration/src/register_locks.cpp @@ -12,10 +12,13 @@ #include #include #include +#ifdef HPX_HAVE_VERIFY_LOCKS_BACKTRACE +#include +#endif #include #include -#include +#include #include /////////////////////////////////////////////////////////////////////////////// @@ -38,7 +41,7 @@ namespace hpx::util { : ignore_(false) , user_data_(data) #ifdef HPX_HAVE_VERIFY_LOCKS_BACKTRACE - , backtrace_(hpx::detail::trace(trace_depth)) + , backtrace_(hpx::util::trace(trace_depth)) #endif { } @@ -51,20 +54,26 @@ namespace hpx::util { struct held_locks_data_ptr { held_locks_data_ptr() - : data_(new held_locks_data) + : data_(std::make_unique()) { } void reinitialize() { - data_.reset(new held_locks_data); + data_ = std::make_unique(); } // note: this invalidates the stored pointer - this is intentional - std::unique_ptr release() noexcept + std::unique_ptr release() && noexcept { HPX_ASSERT(!!data_); - return HPX_MOVE(data_); + + std::unique_ptr result; + + using std::swap; + swap(result, data_); + + return result; } void set(std::unique_ptr&& data) noexcept @@ -81,7 +90,7 @@ namespace hpx::util { static held_locks_data_ptr& get_held_locks() { - static thread_local held_locks_data_ptr held_locks; + thread_local held_locks_data_ptr held_locks; if (!held_locks.data_) { held_locks.reinitialize(); @@ -112,9 +121,15 @@ namespace hpx::util { return !get_held_locks().data_->ignore_all_locks_; } - static void set_ignore_all_locks(bool enable) + static bool set_ignore_all_locks(bool enable) { - get_held_locks().data_->ignore_all_locks_ = enable; + bool& val= get_held_locks().data_->ignore_all_locks_; + if (val != enable) + { + val = enable; + return true; + } + return false; } }; @@ -126,7 +141,7 @@ namespace hpx::util { // retrieve the current thread_local data about held locks std::unique_ptr get_held_locks_data() { - return detail::register_locks::get_held_locks().release(); + return HPX_MOVE(detail::register_locks::get_held_locks()).release(); } // set the current thread_local data about held locks @@ -151,7 +166,10 @@ namespace hpx::util { detail::register_locks::lock_detection_trace_depth_ = value; } - static registered_locks_error_handler_type registered_locks_error_handler; + namespace { + + registered_locks_error_handler_type registered_locks_error_handler; + } void set_registered_locks_error_handler( registered_locks_error_handler_type f) noexcept @@ -159,7 +177,10 @@ namespace hpx::util { registered_locks_error_handler = HPX_MOVE(f); } - static register_locks_predicate_type register_locks_predicate; + namespace { + + register_locks_predicate_type register_locks_predicate; + } void set_register_locks_predicate(register_locks_predicate_type f) noexcept { @@ -180,23 +201,21 @@ namespace hpx::util { register_locks::held_locks_map& held_locks = register_locks::get_lock_map(); - register_locks::held_locks_map::iterator it = - held_locks.find(lock); - if (it != held_locks.end()) + if (held_locks.find(lock) != held_locks.end()) return false; // this lock is already registered std::pair p; if (!data) { - p = held_locks.insert(std::make_pair(lock, - detail::lock_data( - register_locks::lock_detection_trace_depth_))); + p = held_locks.emplace( + lock, register_locks::lock_detection_trace_depth_); } else { - p = held_locks.insert(std::make_pair(lock, - detail::lock_data(data, - register_locks::lock_detection_trace_depth_))); + p = held_locks.emplace(std::piecewise_construct, + std::forward_as_tuple(lock), + std::forward_as_tuple( + data, register_locks::lock_detection_trace_depth_)); } return p.second; } @@ -221,9 +240,7 @@ namespace hpx::util { register_locks::held_locks_map& held_locks = register_locks::get_lock_map(); - register_locks::held_locks_map::iterator it = - held_locks.find(lock); - if (it == held_locks.end()) + if (held_locks.find(lock) == held_locks.end()) return false; // this lock is not registered held_locks.erase(lock); @@ -242,10 +259,8 @@ namespace hpx::util { inline bool some_locks_are_not_ignored( register_locks::held_locks_map const& held_locks) noexcept { - using iterator = register_locks::held_locks_map::const_iterator; - - iterator end = held_locks.end(); - for (iterator it = held_locks.begin(); it != end; ++it) + auto const end = held_locks.end(); + for (auto it = held_locks.begin(); it != end; ++it) { //lock_data const& data = *(*it).second; if (!it->second.ignore_) @@ -266,20 +281,19 @@ namespace hpx::util { if (enabled && register_locks::lock_detection_enabled_ && (!register_locks_predicate || register_locks_predicate())) { - register_locks::held_locks_map& held_locks = - register_locks::get_lock_map(); - // we create a log message if there are still registered locks for // this OS-thread - if (!held_locks.empty()) + if (register_locks::held_locks_map const& held_locks = + register_locks::get_lock_map(); + !held_locks.empty()) { // Temporarily disable verifying locks in case verify_no_locks // gets called recursively. - auto old_value = detail::register_locks::get_lock_enabled(); + auto old_value = register_locks::get_lock_enabled(); - detail::register_locks::set_lock_enabled(false); + register_locks::set_lock_enabled(false); auto on_exit = hpx::experimental::scope_exit([old_value] { - detail::register_locks::set_lock_enabled(old_value); + register_locks::set_lock_enabled(old_value); }); if (detail::some_locks_are_not_ignored(held_locks)) @@ -324,7 +338,7 @@ namespace hpx::util { namespace detail { - void set_ignore_status(void const* lock, bool status) + bool set_ignore_status(void const* lock, bool status) { if (register_locks::lock_detection_enabled_ && (!register_locks_predicate || register_locks_predicate())) @@ -332,64 +346,69 @@ namespace hpx::util { register_locks::held_locks_map& held_locks = register_locks::get_lock_map(); - register_locks::held_locks_map::iterator it = - held_locks.find(lock); + auto const it = held_locks.find(lock); if (it == held_locks.end()) { // this can happen if the lock was registered to be ignored // on a different OS thread - // HPX_THROW_EXCEPTION( - // hpx::error::invalid_status, "set_ignore_status", - // "The given lock has not been registered."); - return; + return false; } - it->second.ignore_ = status; + if (it->second.ignore_ != status) + { + it->second.ignore_ = status; + return true; + } } + return false; } } // namespace detail - void ignore_lock(void const* lock) noexcept + bool ignore_lock(void const* lock) noexcept { try { - detail::set_ignore_status(lock, true); + return detail::set_ignore_status(lock, true); } catch (...) { + return false; } } - void reset_ignored(void const* lock) noexcept + bool reset_ignored(void const* lock) noexcept { try { - detail::set_ignore_status(lock, false); + return detail::set_ignore_status(lock, false); } catch (...) { + return false; } } - void ignore_all_locks() noexcept + bool ignore_all_locks() noexcept { try { - detail::register_locks::set_ignore_all_locks(true); + return detail::register_locks::set_ignore_all_locks(true); } catch (...) { + return false; } } - void reset_ignored_all() noexcept + bool reset_ignored_all() noexcept { try { - detail::register_locks::set_ignore_all_locks(false); + return detail::register_locks::set_ignore_all_locks(false); } catch (...) { + return false; } } } // namespace hpx::util diff --git a/libs/core/runtime_local/CMakeLists.txt b/libs/core/runtime_local/CMakeLists.txt index 85865b6bd8db..31b45764a2be 100644 --- a/libs/core/runtime_local/CMakeLists.txt +++ b/libs/core/runtime_local/CMakeLists.txt @@ -109,5 +109,6 @@ add_hpx_module( hpx_threadmanager hpx_timing hpx_topology + hpx_type_support CMAKE_SUBDIRS examples tests ) diff --git a/libs/core/runtime_local/src/interval_timer.cpp b/libs/core/runtime_local/src/interval_timer.cpp index dc904e559e99..692873e1bb99 100644 --- a/libs/core/runtime_local/src/interval_timer.cpp +++ b/libs/core/runtime_local/src/interval_timer.cpp @@ -11,9 +11,9 @@ #include #include #include -#include #include #include +#include #include #include diff --git a/libs/core/schedulers/CMakeLists.txt b/libs/core/schedulers/CMakeLists.txt index 0476a76a8893..12f5fdea6f60 100644 --- a/libs/core/schedulers/CMakeLists.txt +++ b/libs/core/schedulers/CMakeLists.txt @@ -63,5 +63,6 @@ add_hpx_module( hpx_logging hpx_synchronization hpx_threading_base + hpx_type_support CMAKE_SUBDIRS examples tests ) diff --git a/libs/core/schedulers/include/hpx/schedulers/thread_queue.hpp b/libs/core/schedulers/include/hpx/schedulers/thread_queue.hpp index 57e4521109eb..f0092f4998a9 100644 --- a/libs/core/schedulers/include/hpx/schedulers/thread_queue.hpp +++ b/libs/core/schedulers/include/hpx/schedulers/thread_queue.hpp @@ -15,13 +15,13 @@ #include #include #include -#include #include #include #include #include #include #include +#include #if defined(HPX_HAVE_THREAD_MINIMAL_DEADLOCK_DETECTION) #include diff --git a/libs/core/synchronization/CMakeLists.txt b/libs/core/synchronization/CMakeLists.txt index fe5434333db6..741798a9a997 100644 --- a/libs/core/synchronization/CMakeLists.txt +++ b/libs/core/synchronization/CMakeLists.txt @@ -82,7 +82,8 @@ add_hpx_module( hpx_memory hpx_threading_base hpx_thread_support - hpx_topology hpx_timing + hpx_topology + hpx_type_support CMAKE_SUBDIRS examples tests ) diff --git a/libs/core/synchronization/include/hpx/synchronization/barrier.hpp b/libs/core/synchronization/include/hpx/synchronization/barrier.hpp index 52f29227cf35..15693424816c 100644 --- a/libs/core/synchronization/include/hpx/synchronization/barrier.hpp +++ b/libs/core/synchronization/include/hpx/synchronization/barrier.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2007-2023 Hartmut Kaiser +// Copyright (c) 2007-2024 Hartmut Kaiser // Copyright (c) 2016 Thomas Heller // // SPDX-License-Identifier: BSL-1.0 @@ -17,8 +17,8 @@ #include #include #include -#include #include +#include #include #include diff --git a/libs/core/synchronization/include/hpx/synchronization/condition_variable.hpp b/libs/core/synchronization/include/hpx/synchronization/condition_variable.hpp index 5c142ce03596..90699e91d9ca 100644 --- a/libs/core/synchronization/include/hpx/synchronization/condition_variable.hpp +++ b/libs/core/synchronization/include/hpx/synchronization/condition_variable.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2007-2023 Hartmut Kaiser +// Copyright (c) 2007-2024 Hartmut Kaiser // Copyright (c) 2022 Bhumit Attarde // Copyright (c) 2013 Agustin Berge // @@ -21,9 +21,9 @@ #include #include #include -#include #include #include +#include #include #include diff --git a/libs/core/synchronization/include/hpx/synchronization/shared_mutex.hpp b/libs/core/synchronization/include/hpx/synchronization/shared_mutex.hpp index b713dcacbc10..35c14cdaf2ca 100644 --- a/libs/core/synchronization/include/hpx/synchronization/shared_mutex.hpp +++ b/libs/core/synchronization/include/hpx/synchronization/shared_mutex.hpp @@ -1,6 +1,6 @@ // (C) Copyright 2006-2008 Anthony Williams // (C) Copyright 2011 Bryce Lelbach -// (C) Copyright 2022-2023 Hartmut Kaiser +// (C) Copyright 2022-2024 Hartmut Kaiser // // SPDX-License-Identifier: BSL-1.0 // Distributed under the Boost Software License, Version 1.0. (See accompanying @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include #include @@ -71,6 +71,7 @@ namespace hpx::detail { [[maybe_unused]] util::ignore_while_checking il(&lk); exclusive_cond.notify_one_no_unlock(lk); shared_cond.notify_all(HPX_MOVE(lk)); + il.reset_owns_registration(); } bool set_state(shared_state& s1, shared_state& s) noexcept diff --git a/libs/core/synchronization/src/detail/condition_variable.cpp b/libs/core/synchronization/src/detail/condition_variable.cpp index a51a0543914f..56d2469d949a 100644 --- a/libs/core/synchronization/src/detail/condition_variable.cpp +++ b/libs/core/synchronization/src/detail/condition_variable.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2007-2023 Hartmut Kaiser +// Copyright (c) 2007-2024 Hartmut Kaiser // Copyright (c) 2013-2015 Agustin Berge // // SPDX-License-Identifier: BSL-1.0 @@ -14,10 +14,10 @@ #include #include #include -#include #include #include #include +#include #include #include diff --git a/libs/core/synchronization/src/detail/counting_semaphore.cpp b/libs/core/synchronization/src/detail/counting_semaphore.cpp index 6248663e9fb3..7eeb415c2788 100644 --- a/libs/core/synchronization/src/detail/counting_semaphore.cpp +++ b/libs/core/synchronization/src/detail/counting_semaphore.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2007-2022 Hartmut Kaiser +// Copyright (c) 2007-2024 Hartmut Kaiser // Copyright (c) 2011 Bryce Lelbach // // SPDX-License-Identifier: BSL-1.0 @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include #include diff --git a/libs/core/synchronization/src/detail/sliding_semaphore.cpp b/libs/core/synchronization/src/detail/sliding_semaphore.cpp index ef9a5b6c2fa4..394a61b5da3f 100644 --- a/libs/core/synchronization/src/detail/sliding_semaphore.cpp +++ b/libs/core/synchronization/src/detail/sliding_semaphore.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2023 Hartmut Kaiser +// Copyright (c) 2016-2024 Hartmut Kaiser // // SPDX-License-Identifier: BSL-1.0 // Distributed under the Boost Software License, Version 1.0. (See accompanying @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include #include diff --git a/libs/core/synchronization/src/mutex.cpp b/libs/core/synchronization/src/mutex.cpp index 581fc4172706..dd238f8eb1c7 100644 --- a/libs/core/synchronization/src/mutex.cpp +++ b/libs/core/synchronization/src/mutex.cpp @@ -128,6 +128,7 @@ namespace hpx { #if defined(HPX_MSVC) #pragma warning(pop) #endif + il.reset_owns_registration(); } } diff --git a/libs/core/thread_support/CMakeLists.txt b/libs/core/thread_support/CMakeLists.txt index 03511da64195..fb994c4f634d 100644 --- a/libs/core/thread_support/CMakeLists.txt +++ b/libs/core/thread_support/CMakeLists.txt @@ -1,22 +1,18 @@ -# Copyright (c) 2019 The STE||AR-Group +# Copyright (c) 2019-2024 The STE||AR-Group # # 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) set(thread_support_headers - hpx/thread_support/assert_owns_lock.hpp - hpx/thread_support/atomic_count.hpp - hpx/thread_support/set_thread_name.hpp - hpx/thread_support/spinlock.hpp - hpx/thread_support/thread_specific_ptr.hpp + hpx/thread_support/atomic_count.hpp hpx/thread_support/set_thread_name.hpp + hpx/thread_support/spinlock.hpp hpx/thread_support/thread_specific_ptr.hpp hpx/thread_support/unlock_guard.hpp ) # cmake-format: off set(thread_support_compat_headers hpx/thread_support.hpp => hpx/modules/thread_support.hpp - hpx/util/assert_owns_lock.hpp => hpx/modules/thread_support.hpp hpx/util/atomic_count.hpp => hpx/modules/thread_support.hpp hpx/util/set_thread_name.hpp => hpx/modules/thread_support.hpp hpx/util/thread_specific_ptr.hpp => hpx/modules/thread_support.hpp @@ -33,6 +29,6 @@ add_hpx_module( SOURCES ${thread_support_sources} HEADERS ${thread_support_headers} COMPAT_HEADERS ${thread_support_compat_headers} - MODULE_DEPENDENCIES hpx_assertion hpx_config hpx_concepts hpx_type_support + MODULE_DEPENDENCIES hpx_assertion hpx_config hpx_concepts CMAKE_SUBDIRS examples tests ) diff --git a/libs/core/type_support/CMakeLists.txt b/libs/core/type_support/CMakeLists.txt index d3c9ef8c3e3a..5aacf92de760 100644 --- a/libs/core/type_support/CMakeLists.txt +++ b/libs/core/type_support/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2023 The STE||AR-Group +# Copyright (c) 2019-2024 The STE||AR-Group # # SPDX-License-Identifier: BSL-1.0 # Distributed under the Boost Software License, Version 1.0. (See accompanying @@ -7,6 +7,7 @@ set(type_support_headers hpx/type_support/detail/with_result_of.hpp hpx/type_support/detail/wrap_int.hpp + hpx/type_support/assert_owns_lock.hpp hpx/type_support/bit_cast.hpp hpx/type_support/construct_at.hpp hpx/type_support/decay.hpp @@ -42,6 +43,7 @@ endif() set(type_support_compat_headers hpx/type_support.hpp => hpx/modules/type_support.hpp hpx/util/always_void.hpp => hpx/modules/type_support.hpp + hpx/util/assert_owns_lock.hpp => hpx/modules/type_support.hpp hpx/util/decay.hpp => hpx/modules/type_support.hpp hpx/util/detected.hpp => hpx/modules/type_support.hpp hpx/util/identity.hpp => hpx/modules/type_support.hpp diff --git a/libs/core/thread_support/include/hpx/thread_support/assert_owns_lock.hpp b/libs/core/type_support/include/hpx/type_support/assert_owns_lock.hpp similarity index 95% rename from libs/core/thread_support/include/hpx/thread_support/assert_owns_lock.hpp rename to libs/core/type_support/include/hpx/type_support/assert_owns_lock.hpp index 98f3756a2ac6..5c5f85f76c22 100644 --- a/libs/core/thread_support/include/hpx/thread_support/assert_owns_lock.hpp +++ b/libs/core/type_support/include/hpx/type_support/assert_owns_lock.hpp @@ -1,5 +1,5 @@ // Copyright (c) 2013 Agustin Berge -// Copyright (c) 2022 Hartmut Kaiser +// Copyright (c) 2022-2024 Hartmut Kaiser // // SPDX-License-Identifier: BSL-1.0 // Distributed under the Boost Software License, Version 1.0. (See accompanying @@ -10,7 +10,6 @@ #include #include #include -#include #include diff --git a/libs/full/agas/src/addressing_service.cpp b/libs/full/agas/src/addressing_service.cpp index bea6e6525b28..dd44cf57b7b1 100644 --- a/libs/full/agas/src/addressing_service.cpp +++ b/libs/full/agas/src/addressing_service.cpp @@ -33,8 +33,8 @@ #include #include #include -#include #include +#include #include #include diff --git a/libs/full/agas_base/src/server/primary_namespace_server.cpp b/libs/full/agas_base/src/server/primary_namespace_server.cpp index baa22de5ddad..e81cb0e84fbe 100644 --- a/libs/full/agas_base/src/server/primary_namespace_server.cpp +++ b/libs/full/agas_base/src/server/primary_namespace_server.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2011 Bryce Adelstein-Lelbach -// Copyright (c) 2012-2023 Hartmut Kaiser +// Copyright (c) 2012-2024 Hartmut Kaiser // Copyright (c) 2016 Thomas Heller // // SPDX-License-Identifier: BSL-1.0 @@ -16,8 +16,8 @@ #include #include #include -#include #include +#include #include #include diff --git a/libs/full/collectives/CMakeLists.txt b/libs/full/collectives/CMakeLists.txt index 0c5910f9043d..c9921579badb 100644 --- a/libs/full/collectives/CMakeLists.txt +++ b/libs/full/collectives/CMakeLists.txt @@ -22,9 +22,11 @@ set(collectives_headers hpx/collectives/communication_set.hpp hpx/collectives/channel_communicator.hpp hpx/collectives/create_communicator.hpp + hpx/collectives/detail/barrier_node.hpp hpx/collectives/detail/channel_communicator.hpp hpx/collectives/detail/communication_set_node.hpp hpx/collectives/detail/communicator.hpp + hpx/collectives/detail/latch.hpp hpx/collectives/exclusive_scan.hpp hpx/collectives/fold.hpp hpx/collectives/gather.hpp diff --git a/libs/full/collectives/include/hpx/collectives/detail/communication_set_node.hpp b/libs/full/collectives/include/hpx/collectives/detail/communication_set_node.hpp index b343a5743858..e19b6b112361 100644 --- a/libs/full/collectives/include/hpx/collectives/detail/communication_set_node.hpp +++ b/libs/full/collectives/include/hpx/collectives/detail/communication_set_node.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2020 Hartmut Kaiser +// Copyright (c) 2020-2024 Hartmut Kaiser // // SPDX-License-Identifier: BSL-1.0 // Distributed under the Boost Software License, Version 1.0. (See accompanying @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include diff --git a/libs/full/collectives/include/hpx/collectives/detail/communicator.hpp b/libs/full/collectives/include/hpx/collectives/detail/communicator.hpp index 844f91de9c67..2104d20fc2e3 100644 --- a/libs/full/collectives/include/hpx/collectives/detail/communicator.hpp +++ b/libs/full/collectives/include/hpx/collectives/detail/communicator.hpp @@ -16,9 +16,10 @@ #include #include #include +#include #include #include -#include +#include #include #include @@ -307,7 +308,7 @@ namespace hpx::collectives::detail { // re-acquired here (if `on_ready` happens to run on a new // thread asynchronously). std::unique_lock l(mtx_, std::try_to_lock); - [[maybe_unused]] util::ignore_while_checking il(&l); + //[[maybe_unused]] util::ignore_while_checking il(&l); // Verify that there is no overlap between different types of // operations on the same communicator. @@ -356,7 +357,7 @@ namespace hpx::collectives::detail { }; std::unique_lock l(mtx_); - [[maybe_unused]] util::ignore_while_checking il(&l); + [[maybe_unused]] util::ignore_all_while_checking il; // Verify that there is no overlap between different types of // operations on the same communicator. diff --git a/libs/full/collectives/tests/unit/concurrent_collectives.cpp b/libs/full/collectives/tests/unit/concurrent_collectives.cpp index bf0552f88c7a..7d7a3eeb8881 100644 --- a/libs/full/collectives/tests/unit/concurrent_collectives.cpp +++ b/libs/full/collectives/tests/unit/concurrent_collectives.cpp @@ -93,7 +93,10 @@ struct generations template void load(Archive& ar, unsigned) { + // clang-format off ar & data; + // clang-format on + for (auto& [k, v] : data) { v.current = 0; @@ -103,7 +106,9 @@ struct generations template void save(Archive& ar, unsigned) const { + // clang-format off ar & data; + // clang-format on } HPX_SERIALIZATION_SPLIT_MEMBER(); @@ -414,7 +419,8 @@ double test_local_all_reduce(std::vector const& comms) double elapsed = 0.; std::size_t gen = 0; - for (std::uint32_t i = 0; local.get_next_generation("all_reduce", gen); ++i) + for ([[maybe_unused]] std::uint32_t i = 0; + local.get_next_generation("all_reduce", gen); ++i) { std::vector> sites; sites.reserve(num_sites); @@ -458,7 +464,8 @@ double test_local_all_to_all(std::vector const& comms) double elapsed = 0.; std::size_t gen = 0; - for (std::uint32_t i = 0; local.get_next_generation("all_to_all", gen); ++i) + for ([[maybe_unused]] std::uint32_t i = 0; + local.get_next_generation("all_to_all", gen); ++i) { std::vector> sites; sites.reserve(num_sites); diff --git a/libs/full/parcelset/include/hpx/parcelset/parcelport_impl.hpp b/libs/full/parcelset/include/hpx/parcelset/parcelport_impl.hpp index 62b64d596241..8527e0e77509 100644 --- a/libs/full/parcelset/include/hpx/parcelset/parcelport_impl.hpp +++ b/libs/full/parcelset/include/hpx/parcelset/parcelport_impl.hpp @@ -315,7 +315,6 @@ namespace hpx::parcelset { { enqueue_parcels( dest, HPX_MOVE(parcels), HPX_MOVE(handlers)); - get_connection_and_send_parcels(dest); } }); @@ -712,9 +711,6 @@ namespace hpx::parcelset { std::unique_lock const l(mtx_); - // We ignore the lock here. It might happen that while enqueuing, - // we need to acquire a lock. This should not cause any problems - // (famous last words) [[maybe_unused]] util::ignore_while_checking il(&l); mapped_type& e = pending_parcels_[locality_id]; @@ -736,9 +732,6 @@ namespace hpx::parcelset { std::unique_lock const l(mtx_); - // We ignore the lock here. It might happen that while enqueuing, - // we need to acquire a lock. This should not cause any problems - // (famous last words) [[maybe_unused]] util::ignore_while_checking il(&l); HPX_ASSERT(parcels.size() == handlers.size());