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/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..92a570ee926d 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_); @@ -544,6 +546,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_); 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..c062122c995c 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_; @@ -108,6 +120,13 @@ namespace hpx::util { 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(); @@ -120,8 +139,39 @@ 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) + { + if (mtx_ != nullptr) + { + 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) + { + reset_ignored(mtx_); + } + } + + void const* mtx_; + }; + + template + struct ignore_while_checking && + !detail::has_owns_lock_v>> { explicit ignore_while_checking(Lock const* lock) noexcept : mtx_(lock->mutex()) @@ -129,6 +179,11 @@ namespace hpx::util { 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_); @@ -200,3 +255,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..5952a1746b2f 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,17 +54,17 @@ 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_); @@ -81,7 +84,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(); @@ -126,7 +129,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 +154,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 +165,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 +189,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 +228,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 +247,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 +269,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)) @@ -332,8 +334,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); + auto const it = held_locks.find(lock); if (it == held_locks.end()) { // this can happen if the lock was registered to be ignored 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..163d71a18018 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 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/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..85f6d5486b58 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 diff --git a/libs/full/parcelset/include/hpx/parcelset/parcelport_impl.hpp b/libs/full/parcelset/include/hpx/parcelset/parcelport_impl.hpp index 62b64d596241..7cb9cdd218c6 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); } });