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 555504e54182..0646c6a81dad 100644 --- a/libs/core/futures/include/hpx/futures/detail/future_data.hpp +++ b/libs/core/futures/include/hpx/futures/detail/future_data.hpp @@ -656,7 +656,9 @@ namespace hpx::lcos::detail { std::destroy_at(exception_ptr); break; } - default: + case empty: + [[fallthrough]]; + case ready: break; } @@ -1020,10 +1022,17 @@ namespace hpx::lcos::detail { { target.set_thread_id(threads::get_self_id()); } + ~reset_id() { target_.set_thread_id(threads::invalid_thread_id); } + + reset_id(reset_id const&) = delete; + reset_id(reset_id&&) = delete; + reset_id& operator=(reset_id const&) = delete; + reset_id& operator=(reset_id&&) = delete; + cancelable_task_base& target_; }; @@ -1046,7 +1055,6 @@ namespace hpx::lcos::detail { hpx::intrusive_ptr this_( this); // keep alive - std::unique_lock l(mtx_); hpx::detail::try_catch_exception_ptr( [&]() { if (!this->started_test_and_set()) diff --git a/libs/core/futures/include/hpx/futures/future.hpp b/libs/core/futures/include/hpx/futures/future.hpp index 297a302362ae..49fef24cda4b 100644 --- a/libs/core/futures/include/hpx/futures/future.hpp +++ b/libs/core/futures/include/hpx/futures/future.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2007-2022 Hartmut Kaiser +// Copyright (c) 2007-2023 Hartmut Kaiser // Copyright (c) 2013 Agustin Berge // // SPDX-License-Identifier: BSL-1.0 @@ -169,12 +169,12 @@ namespace hpx::lcos::detail { { if (ar.is_preprocessing()) { - hpx::traits::detail::shared_state_ptr_for_t state = + auto shared_state = hpx::traits::future_access::get_shared_state(f); - state->execute_deferred(); + shared_state->execute_deferred(); - preprocess_future(ar, *state); + preprocess_future(ar, *shared_state); } else { @@ -221,12 +221,12 @@ namespace hpx::lcos::detail { { if (ar.is_preprocessing()) { - hpx::traits::detail::shared_state_ptr_for_t state = + auto shared_state = hpx::traits::future_access::get_shared_state(f); - state->execute_deferred(); + shared_state->execute_deferred(); - preprocess_future(ar, *state); + preprocess_future(ar, *shared_state); } else { @@ -323,9 +323,12 @@ namespace hpx::lcos::detail { template <> struct future_value : future_data_result { - HPX_FORCEINLINE static void get(hpx::util::unused_type) noexcept {} + HPX_FORCEINLINE static constexpr void get( + hpx::util::unused_type) noexcept + { + } - static void get_default() noexcept {} + static constexpr void get_default() noexcept {} }; /////////////////////////////////////////////////////////////////////////// @@ -477,6 +480,7 @@ namespace hpx::lcos::detail { public: future_base() noexcept = default; + ~future_base() = default; explicit future_base(hpx::intrusive_ptr const& p) : shared_state_(p) @@ -746,6 +750,11 @@ namespace hpx { { } + invalidate(invalidate const&) = delete; + invalidate(invalidate&&) = delete; + invalidate& operator=(invalidate const&) = delete; + invalidate& operator=(invalidate&&) = delete; + ~invalidate() { f_.shared_state_.reset(); @@ -792,6 +801,8 @@ namespace hpx { // - other.valid() == false. future(future&& other) noexcept = default; + future(future const& other) noexcept = delete; + // Effects: constructs a future object by moving the instance referred // to by rhs and unwrapping the inner future. // Postconditions: @@ -848,6 +859,8 @@ namespace hpx { // - other.valid() == false. future& operator=(future&& other) noexcept = default; + future& operator=(future const& other) noexcept = delete; + // Returns: shared_future(HPX_MOVE(*this)). // Postcondition: valid() == false. shared_future share() noexcept @@ -877,9 +890,8 @@ namespace hpx { invalidate on_exit(*this); using result_type = typename shared_state_type::result_type; - result_type* result = - lcos::detail::future_get_result::call( - this->shared_state_); + auto* result = lcos::detail::future_get_result::call( + this->shared_state_); // no error has been reported, return the result return lcos::detail::future_value::get(HPX_MOVE(*result)); @@ -1500,8 +1512,7 @@ namespace hpx { { return hpx::make_exceptional_future(std::current_exception()); } - - return future(); + return {}; } /////////////////////////////////////////////////////////////////////////// diff --git a/libs/core/futures/include/hpx/futures/futures_factory.hpp b/libs/core/futures/include/hpx/futures/futures_factory.hpp index 685261a8a97b..de8f7b7cd61f 100644 --- a/libs/core/futures/include/hpx/futures/futures_factory.hpp +++ b/libs/core/futures/include/hpx/futures/futures_factory.hpp @@ -78,7 +78,7 @@ namespace hpx::lcos::local { task_object& operator=(task_object const&) = delete; task_object& operator=(task_object&&) = delete; - ~task_object() = default; + ~task_object() override = default; void do_run() noexcept override { @@ -230,7 +230,7 @@ namespace hpx::lcos::local { task_object_allocator const&) = delete; task_object_allocator& operator=(task_object_allocator&&) = delete; - ~task_object_allocator() = default; + ~task_object_allocator() override = default; private: void destroy() noexcept override @@ -570,8 +570,6 @@ namespace hpx::lcos::local { base_allocator>::template rebind_alloc; using traits = std::allocator_traits; - using init_no_addref = typename shared_state::init_no_addref; - using unique_ptr = std::unique_ptr>; @@ -673,8 +671,6 @@ namespace hpx::lcos::local { base_allocator>::template rebind_alloc; using traits = std::allocator_traits; - using init_no_addref = typename shared_state::init_no_addref; - using unique_ptr = std::unique_ptr>; @@ -817,7 +813,6 @@ namespace hpx::lcos::local { HPX_THROW_EXCEPTION(hpx::error::task_moved, "futures_factory::operator()", "futures_factory invalid (has it been moved?)"); - return; } task_->run(); } @@ -840,7 +835,6 @@ namespace hpx::lcos::local { HPX_THROW_EXCEPTION(hpx::error::task_moved, "futures_factory::post()", "futures_factory invalid (has it been moved?)"); - return threads::invalid_thread_id; } return task_->post(pool, annotation, HPX_MOVE(policy), ec); } @@ -882,7 +876,6 @@ namespace hpx::lcos::local { HPX_THROW_EXCEPTION(hpx::error::task_moved, "futures_factory::set_exception", "futures_factory invalid (has it been moved?)"); - return; } task_->set_exception(e); } diff --git a/libs/core/futures/include/hpx/futures/packaged_continuation.hpp b/libs/core/futures/include/hpx/futures/packaged_continuation.hpp index 5f52260f03f4..f6935c300ef7 100644 --- a/libs/core/futures/include/hpx/futures/packaged_continuation.hpp +++ b/libs/core/futures/include/hpx/futures/packaged_continuation.hpp @@ -154,10 +154,17 @@ namespace hpx::lcos::detail { if (threads::get_self_ptr() != nullptr) target.set_id(threads::get_self_id()); } + + reset_id(reset_id const&) = delete; + reset_id(reset_id&&) = delete; + reset_id& operator=(reset_id const&) = delete; + reset_id& operator=(reset_id&&) = delete; + ~reset_id() { target_.set_id(threads::invalid_thread_id); } + continuation& target_; }; @@ -168,7 +175,7 @@ namespace hpx::lcos::detail { typename Enable = std::enable_if_t< !std::is_same_v, continuation>>> // NOLINTNEXTLINE(bugprone-forwarding-reference-overload) - continuation(Func&& f) + explicit continuation(Func&& f) : started_(false) , id_(threads::invalid_thread_id) , f_(HPX_FORWARD(Func, f)) @@ -193,7 +200,6 @@ namespace hpx::lcos::detail { HPX_THROW_EXCEPTION(hpx::error::task_already_started, "continuation::ensure_started", "this task has already been started"); - return; } started_ = true; } @@ -380,17 +386,13 @@ namespace hpx::lcos::detail { }; } // namespace hpx::lcos::detail -namespace hpx::traits::detail { - - template - struct shared_state_allocator< - lcos::detail::continuation, Allocator> - { - using type = lcos::detail::continuation_allocator; - }; -} // namespace hpx::traits::detail +template +struct hpx::traits::detail::shared_state_allocator< + hpx::lcos::detail::continuation, Allocator> +{ + using type = + lcos::detail::continuation_allocator; +}; /////////////////////////////////////////////////////////////////////////////// namespace hpx::lcos::detail { @@ -503,7 +505,7 @@ namespace hpx::lcos::detail { public: using init_no_addref = typename base_type::init_no_addref; - unwrap_continuation_allocator(other_allocator const& alloc) + explicit unwrap_continuation_allocator(other_allocator const& alloc) : alloc_(alloc) { } @@ -529,16 +531,13 @@ namespace hpx::lcos::detail { }; } // namespace hpx::lcos::detail -namespace hpx::traits::detail { - - template - struct shared_state_allocator, - Allocator> - { - using type = - lcos::detail::unwrap_continuation_allocator; - }; -} // namespace hpx::traits::detail +template +struct hpx::traits::detail::shared_state_allocator< + hpx::lcos::detail::unwrap_continuation, Allocator> +{ + using type = + lcos::detail::unwrap_continuation_allocator; +}; namespace hpx::lcos::detail { diff --git a/libs/core/futures/include/hpx/futures/packaged_task.hpp b/libs/core/futures/include/hpx/futures/packaged_task.hpp index d262c6c49063..41de27a415e9 100644 --- a/libs/core/futures/include/hpx/futures/packaged_task.hpp +++ b/libs/core/futures/include/hpx/futures/packaged_task.hpp @@ -83,7 +83,6 @@ namespace hpx { HPX_THROW_EXCEPTION(hpx::error::no_state, "packaged_task::operator()", "this packaged_task has no valid shared state"); - return; } // synchronous execution of the embedded function (object) @@ -164,7 +163,8 @@ namespace std { //-V1061 }; template - void swap(hpx::packaged_task& lhs, hpx::packaged_task& rhs) + void swap( + hpx::packaged_task& lhs, hpx::packaged_task& rhs) noexcept { lhs.swap(rhs); } diff --git a/libs/core/futures/include/hpx/futures/promise.hpp b/libs/core/futures/include/hpx/futures/promise.hpp index 94ba27255dfd..9dd7370a94c7 100644 --- a/libs/core/futures/include/hpx/futures/promise.hpp +++ b/libs/core/futures/include/hpx/futures/promise.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2007-2013 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 @@ -172,7 +172,6 @@ namespace hpx { HPX_THROW_EXCEPTION(hpx::error::no_state, "detail::promise_base::set_value", "this promise has no valid shared state"); - return; } if (shared_state_->is_ready()) @@ -180,7 +179,6 @@ namespace hpx { HPX_THROW_EXCEPTION(hpx::error::promise_already_satisfied, "detail::promise_base::set_value", "result has already been stored for this promise"); - return; } shared_state_->set_value(HPX_FORWARD(Ts, ts)...); @@ -194,7 +192,6 @@ namespace hpx { HPX_THROW_EXCEPTION(hpx::error::no_state, "detail::promise_base::set_exception", "this promise has no valid shared state"); - return; } if (shared_state_->is_ready()) @@ -202,7 +199,6 @@ namespace hpx { HPX_THROW_EXCEPTION(hpx::error::promise_already_satisfied, "detail::promise_base::set_exception", "result has already been stored for this promise"); - return; } shared_state_->set_exception(HPX_FORWARD(T, value)); @@ -277,6 +273,8 @@ namespace hpx { // Postcondition: other has no shared state. promise(promise&& other) noexcept = default; + promise(promise const& other) = delete; + // Effects: Abandons any shared state ~promise() = default; @@ -285,6 +283,8 @@ namespace hpx { // Returns: *this. promise& operator=(promise&& other) noexcept = default; + promise& operator=(promise const& other) = delete; + // Effects: Exchanges the shared state of *this and other. // Postcondition: *this has the shared state (if any) that other had // prior to the call to swap. other has the shared state @@ -411,6 +411,8 @@ namespace hpx { // Postcondition: other has no shared state. promise(promise&& other) noexcept = default; + promise(promise const& other) = delete; + // Effects: Abandons any shared state ~promise() = default; @@ -419,6 +421,8 @@ namespace hpx { // Returns: *this. promise& operator=(promise&& other) noexcept = default; + promise& operator=(promise const& other) = delete; + // Effects: Exchanges the shared state of *this and other. // Postcondition: *this has the shared state (if any) that other had // prior to the call to swap. other has the shared state @@ -503,6 +507,8 @@ namespace hpx { // Postcondition: other has no shared state. promise(promise&& other) noexcept = default; + promise(promise const& other) noexcept = delete; + // Effects: Abandons any shared state ~promise() = default; @@ -511,6 +517,8 @@ namespace hpx { // Returns: *this. promise& operator=(promise&& other) noexcept = default; + promise& operator=(promise const& other) noexcept = delete; + // Effects: Exchanges the shared state of *this and other. // Postcondition: *this has the shared state (if any) that other had // prior to the call to swap. other has the shared state @@ -572,12 +580,6 @@ namespace hpx { // - no_state if *this has no shared state. using base_type::set_exception; }; - - template - void swap(promise& x, promise& y) noexcept - { - x.swap(y); - } } // namespace hpx namespace hpx::lcos::local { @@ -595,4 +597,10 @@ namespace std { struct uses_allocator, Allocator> : std::true_type { }; + + template + void swap(hpx::promise& x, hpx::promise& y) noexcept + { + x.swap(y); + } } // namespace std diff --git a/libs/core/futures/include/hpx/futures/traits/acquire_future.hpp b/libs/core/futures/include/hpx/futures/traits/acquire_future.hpp index f99c3811ec89..d52e44767c25 100644 --- a/libs/core/futures/include/hpx/futures/traits/acquire_future.hpp +++ b/libs/core/futures/include/hpx/futures/traits/acquire_future.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2007-2022 Hartmut Kaiser +// Copyright (c) 2007-2023 Hartmut Kaiser // Copyright (c) 2016 Agustin Berge // // SPDX-License-Identifier: BSL-1.0 @@ -31,8 +31,7 @@ namespace hpx::traits { } template - struct acquire_future - : detail::acquire_future_impl::type> + struct acquire_future : detail::acquire_future_impl> { }; diff --git a/libs/core/futures/include/hpx/futures/traits/detail/future_await_traits.hpp b/libs/core/futures/include/hpx/futures/traits/detail/future_await_traits.hpp index 4f19516f2e83..5f588599ee73 100644 --- a/libs/core/futures/include/hpx/futures/traits/detail/future_await_traits.hpp +++ b/libs/core/futures/include/hpx/futures/traits/detail/future_await_traits.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 @@ -45,8 +45,8 @@ namespace hpx::lcos::detail { return is_ready_; } - constexpr void await_suspend(coroutine_handle<>) const noexcept {} - constexpr void await_resume() const noexcept {} + static constexpr void await_suspend(coroutine_handle<>) noexcept {} + static constexpr void await_resume() noexcept {} }; /////////////////////////////////////////////////////////////////////////// @@ -150,7 +150,7 @@ namespace hpx::lcos::detail { HPX_MOVE(shared_state)); } - constexpr suspend_never initial_suspend() const noexcept + static constexpr suspend_never initial_suspend() noexcept { return suspend_never{}; } diff --git a/libs/core/futures/include/hpx/futures/traits/detail/future_traits.hpp b/libs/core/futures/include/hpx/futures/traits/detail/future_traits.hpp index a722df284622..0d35537c946c 100644 --- a/libs/core/futures/include/hpx/futures/traits/detail/future_traits.hpp +++ b/libs/core/futures/include/hpx/futures/traits/detail/future_traits.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2007-2022 Hartmut Kaiser +// Copyright (c) 2007-2023 Hartmut Kaiser // Copyright (c) 2013 Agustin Berge // // SPDX-License-Identifier: BSL-1.0 @@ -7,7 +7,6 @@ #pragma once -#include #include #include diff --git a/libs/core/futures/include/hpx/futures/traits/future_then_result.hpp b/libs/core/futures/include/hpx/futures/traits/future_then_result.hpp index 8daee136cfed..5a4155a64daa 100644 --- a/libs/core/futures/include/hpx/futures/traits/future_then_result.hpp +++ b/libs/core/futures/include/hpx/futures/traits/future_then_result.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2007-2022 Hartmut Kaiser +// Copyright (c) 2007-2023 Hartmut Kaiser // Copyright (c) 2013 Agustin Berge // // SPDX-License-Identifier: BSL-1.0 @@ -21,6 +21,7 @@ namespace hpx::traits { /////////////////////////////////////////////////////////////////////////// namespace detail { + template struct continuation_not_callable { @@ -37,7 +38,7 @@ namespace hpx::traits { template struct future_then_result { - typedef typename continuation_not_callable::type type; + using type = typename continuation_not_callable::type; }; template diff --git a/libs/core/futures/include/hpx/futures/traits/promise_local_result.hpp b/libs/core/futures/include/hpx/futures/traits/promise_local_result.hpp index 2b36944499b2..87660a5bebda 100644 --- a/libs/core/futures/include/hpx/futures/traits/promise_local_result.hpp +++ b/libs/core/futures/include/hpx/futures/traits/promise_local_result.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 @@ -6,7 +6,6 @@ #pragma once -#include #include namespace hpx::traits { diff --git a/libs/core/io_service/include/hpx/io_service/io_service_pool.hpp b/libs/core/io_service/include/hpx/io_service/io_service_pool.hpp index 39f163bfd081..00c018edf91e 100644 --- a/libs/core/io_service/include/hpx/io_service/io_service_pool.hpp +++ b/libs/core/io_service/include/hpx/io_service/io_service_pool.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2007-2022 Hartmut Kaiser +// Copyright (c) 2007-2023 Hartmut Kaiser // // Parts of this code were taken from the Boost.Asio library // Copyright (c) 2003-2007 Christopher M. Kohlhoff (chris at kohlhoff dot com) @@ -122,8 +122,8 @@ namespace hpx::util { using io_service_ptr = std::unique_ptr; using work_type = std::unique_ptr; - HPX_FORCEINLINE work_type initialize_work( - asio::io_context& io_service) const + HPX_FORCEINLINE static work_type initialize_work( + asio::io_context& io_service) { return work_type( std::make_unique(io_service)); diff --git a/libs/core/synchronization/include/hpx/synchronization/async_rw_mutex.hpp b/libs/core/synchronization/include/hpx/synchronization/async_rw_mutex.hpp index 3827ca6596e8..fd75a5dff827 100644 --- a/libs/core/synchronization/include/hpx/synchronization/async_rw_mutex.hpp +++ b/libs/core/synchronization/include/hpx/synchronization/async_rw_mutex.hpp @@ -205,11 +205,11 @@ namespace hpx::experimental { async_rw_mutex_access_type::readwrite> { private: - static_assert(!std::is_void::value, + static_assert(!std::is_void_v, "Cannot mix void and non-void type in " "async_rw_mutex_access_wrapper wrapper (ReadWriteT is void, " "ReadT is non-void)"); - static_assert(!std::is_void::value, + static_assert(!std::is_void_v, "Cannot mix void and non-void type in " "async_rw_mutex_access_wrapper wrapper (ReadT is void, " "ReadWriteT is non-void)"); @@ -540,10 +540,10 @@ namespace hpx::experimental { class async_rw_mutex { private: - static_assert(!std::is_void::value, + static_assert(!std::is_void_v, "Cannot mix void and non-void type in async_rw_mutex (ReadWriteT " "is void, ReadT is non-void)"); - static_assert(!std::is_void::value, + static_assert(!std::is_void_v, "Cannot mix void and non-void type in async_rw_mutex (ReadT is " "void, ReadWriteT is non-void)"); @@ -567,7 +567,7 @@ namespace hpx::experimental { async_rw_mutex() = delete; template , async_rw_mutex>::value>> + !std::is_same_v, async_rw_mutex>>> explicit async_rw_mutex(U&& u, allocator_type const& alloc = {}) : value(HPX_FORWARD(U, u)) , alloc(alloc) diff --git a/libs/core/synchronization/include/hpx/synchronization/barrier.hpp b/libs/core/synchronization/include/hpx/synchronization/barrier.hpp index b115ba4996fd..39b9f492cc3b 100644 --- a/libs/core/synchronization/include/hpx/synchronization/barrier.hpp +++ b/libs/core/synchronization/include/hpx/synchronization/barrier.hpp @@ -161,7 +161,7 @@ namespace hpx { /// expected is 0 this object can only be destroyed.- /// end note] /// - /// \throws: Any exception thrown by CompletionFunction's move + /// Throws: Any exception thrown by CompletionFunction's move /// constructor. constexpr explicit barrier( std::ptrdiff_t expected, OnCompletion completion = OnCompletion()) @@ -216,7 +216,7 @@ namespace hpx { /// /// \returns: The constructed arrival_token object. /// - /// \throws: system_error when an exception is required + /// \throws system_error: when an exception is required /// ([thread.req.exception]). /// /// Error conditions: Any of the error conditions allowed for mutex @@ -241,7 +241,7 @@ namespace hpx { /// point for a previous phase, the call returns /// immediately. - end note ] /// - /// \throws: system_error when an exception is required + /// \throws system_error: when an exception is required /// ([thread.req.exception]). /// Error conditions: Any of the error conditions allowed for mutex /// types ([thread.mutex.requirements.mutex]). @@ -278,7 +278,7 @@ namespace hpx { /// the start of the phase completion step for the /// current phase. /// - /// \throws: system_error when an exception is required + /// \throws system_error: when an exception is required /// ([thread.req.exception]).Error conditions: /// Any of the error conditions allowed for mutex /// types ([thread.mutex.requirements.mutex]). diff --git a/libs/core/synchronization/include/hpx/synchronization/channel_mpmc.hpp b/libs/core/synchronization/include/hpx/synchronization/channel_mpmc.hpp index cdd4d1c01b16..7e5f15d833e8 100644 --- a/libs/core/synchronization/include/hpx/synchronization/channel_mpmc.hpp +++ b/libs/core/synchronization/include/hpx/synchronization/channel_mpmc.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2019-2022 Hartmut Kaiser +// Copyright (c) 2019-2023 Hartmut Kaiser // // SPDX-License-Identifier: BSL-1.0 // Distributed under the Boost Software License, Version 1.0. (See accompanying @@ -36,7 +36,7 @@ namespace hpx::lcos::local { constexpr bool is_full(std::size_t tail) const noexcept { - std::size_t numitems = size_ + tail - head_.data_; + std::size_t const numitems = size_ + tail - head_.data_; if (numitems < size_) { return numitems == size_ - 1; diff --git a/libs/core/synchronization/include/hpx/synchronization/channel_mpsc.hpp b/libs/core/synchronization/include/hpx/synchronization/channel_mpsc.hpp index f38ff45d6d54..6e7b880b75b0 100644 --- a/libs/core/synchronization/include/hpx/synchronization/channel_mpsc.hpp +++ b/libs/core/synchronization/include/hpx/synchronization/channel_mpsc.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2019-2022 Hartmut Kaiser +// Copyright (c) 2019-2023 Hartmut Kaiser // // SPDX-License-Identifier: BSL-1.0 // Distributed under the Boost Software License, Version 1.0. (See accompanying @@ -39,7 +39,7 @@ namespace hpx::lcos::local { bool is_full(std::size_t tail) const noexcept { - std::size_t numitems = + std::size_t const numitems = size_ + tail - head_.data_.load(std::memory_order_acquire); if (numitems < size_) @@ -217,7 +217,7 @@ namespace hpx::lcos::local { bool is_full(std::size_t tail) const noexcept { - std::size_t numitems = + std::size_t const numitems = size_ + tail - head_.data_.load(std::memory_order_acquire); if (numitems < size_) diff --git a/libs/core/synchronization/include/hpx/synchronization/channel_spsc.hpp b/libs/core/synchronization/include/hpx/synchronization/channel_spsc.hpp index a51fec49a0a9..ef5d2a897f83 100644 --- a/libs/core/synchronization/include/hpx/synchronization/channel_spsc.hpp +++ b/libs/core/synchronization/include/hpx/synchronization/channel_spsc.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2019-2022 Hartmut Kaiser +// Copyright (c) 2019-2023 Hartmut Kaiser // // SPDX-License-Identifier: BSL-1.0 // Distributed under the Boost Software License, Version 1.0. (See accompanying @@ -39,7 +39,7 @@ namespace hpx::lcos::local { private: HPX_FORCEINLINE bool is_full(std::size_t tail) const noexcept { - std::size_t numitems = + std::size_t const numitems = size_ + tail - head_.data_.load(std::memory_order_acquire); if (numitems < size_) @@ -202,7 +202,7 @@ namespace hpx::lcos::local { private: HPX_FORCEINLINE bool is_full(std::size_t tail) const noexcept { - std::size_t numitems = + std::size_t const numitems = size_ + tail - head_.data_.load(std::memory_order_acquire); if (numitems < size_) diff --git a/libs/core/synchronization/include/hpx/synchronization/condition_variable.hpp b/libs/core/synchronization/include/hpx/synchronization/condition_variable.hpp index 8111e35e5ad8..d29c9ab67779 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-2022 Hartmut Kaiser +// Copyright (c) 2007-2023 Hartmut Kaiser // Copyright (c) 2022 Bhumit Attarde // Copyright (c) 2013 Agustin Berge // @@ -143,6 +143,11 @@ namespace hpx { /// ~condition_variable() = default; + condition_variable(condition_variable const&) = delete; + condition_variable(condition_variable&&) = delete; + condition_variable& operator=(condition_variable const&) = delete; + condition_variable& operator=(condition_variable&&) = delete; + /// /// \brief If any threads are waiting on \a *this, calling \a notify_one /// unblocks one of the waiting threads. @@ -207,9 +212,9 @@ namespace hpx { { HPX_ASSERT_OWNS_LOCK(lock); - auto data = data_; // keep data alive + auto const data = data_; // keep data alive - util::ignore_all_while_checking ignore_lock; + util::ignore_all_while_checking const ignore_lock; HPX_UNUSED(ignore_lock); std::unique_lock l(data->mtx_); @@ -314,9 +319,9 @@ namespace hpx { { HPX_ASSERT_OWNS_LOCK(lock); - auto data = data_; // keep data alive + auto const data = data_; // keep data alive - util::ignore_all_while_checking ignore_lock; + util::ignore_all_while_checking const ignore_lock; HPX_UNUSED(ignore_lock); std::unique_lock l(data->mtx_); @@ -570,6 +575,12 @@ namespace hpx { /// ~condition_variable_any() = default; + condition_variable_any(condition_variable_any const&) = delete; + condition_variable_any(condition_variable_any&&) = delete; + condition_variable_any& operator=( + condition_variable_any const&) = delete; + condition_variable_any& operator=(condition_variable_any&&) = delete; + /// /// \brief If any threads are waiting on \a *this, calling \a notify_one /// unblocks one of the waiting threads. @@ -661,7 +672,7 @@ namespace hpx { /// /// \note If these functions fail to meet the postconditions (lock is /// locked by the calling thread), std::terminate is called. For - /// example, this could happen if relocking the mutex throws an + /// example, this could happen if re-locking the mutex throws an /// exception. /// /// The effects of `notify_one()/notify_all()` and each of the @@ -689,9 +700,9 @@ namespace hpx { { HPX_ASSERT_OWNS_LOCK(lock); - auto data = data_; // keep data alive + auto const data = data_; // keep data alive - util::ignore_all_while_checking ignore_lock; + util::ignore_all_while_checking const ignore_lock; HPX_UNUSED(ignore_lock); std::unique_lock l(data->mtx_); @@ -726,7 +737,7 @@ namespace hpx { /// /// \note If these functions fail to meet the postconditions (lock is /// locked by the calling thread), std::terminate is called. For - /// example, this could happen if relocking the mutex throws an + /// example, this could happen if re-locking the mutex throws an /// exception. /// /// The effects of `notify_one()/notify_all()` and each of the @@ -806,9 +817,9 @@ namespace hpx { { HPX_ASSERT_OWNS_LOCK(lock); - auto data = data_; // keep data alive + auto const data = data_; // keep data alive - util::ignore_all_while_checking ignore_lock; + util::ignore_all_while_checking const ignore_lock; HPX_UNUSED(ignore_lock); std::unique_lock l(data->mtx_); @@ -1058,7 +1069,7 @@ namespace hpx { while (!pred()) { - util::ignore_all_while_checking ignore_lock; + util::ignore_all_while_checking const ignore_lock; HPX_UNUSED(ignore_lock); std::unique_lock l(data->mtx_); @@ -1153,7 +1164,7 @@ namespace hpx { { bool should_stop; { - util::ignore_all_while_checking ignore_lock; + util::ignore_all_while_checking const ignore_lock; HPX_UNUSED(ignore_lock); std::unique_lock l(data->mtx_); diff --git a/libs/core/synchronization/include/hpx/synchronization/counting_semaphore.hpp b/libs/core/synchronization/include/hpx/synchronization/counting_semaphore.hpp index 07b33e7e89f1..a7289f0c993f 100644 --- a/libs/core/synchronization/include/hpx/synchronization/counting_semaphore.hpp +++ b/libs/core/synchronization/include/hpx/synchronization/counting_semaphore.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2007-2022 Hartmut Kaiser +// Copyright (c) 2007-2023 Hartmut Kaiser // Copyright (c) 2011 Bryce Lelbach // // SPDX-License-Identifier: BSL-1.0 @@ -77,7 +77,7 @@ namespace hpx { /// \namedrequirement{CopyAssignable}, /// or \namedrequirement{MoveAssignable}. /// - /// \note \a couting_semaphore's \a try_acquire() can spuriously fail. + /// \note \a counting_semaphore's \a try_acquire() can spuriously fail. /// /// \tparam LeastMaxValue \a counting_semaphore allows more than one /// concurrent access to the same resource, for diff --git a/libs/core/synchronization/include/hpx/synchronization/event.hpp b/libs/core/synchronization/include/hpx/synchronization/event.hpp index 66713393617b..282eac888619 100644 --- a/libs/core/synchronization/include/hpx/synchronization/event.hpp +++ b/libs/core/synchronization/include/hpx/synchronization/event.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2007-2012 Hartmut Kaiser +// Copyright (c) 2007-2023 Hartmut Kaiser // Copyright (c) 2011-2012 Bryce Adelstein-Lelbach // // SPDX-License-Identifier: BSL-1.0 @@ -30,14 +30,12 @@ namespace hpx::lcos::local { public: /// \brief Construct a new event semaphore event() noexcept - : mtx_() - , cond_() - , event_(false) + : event_(false) { } /// \brief Check if the event has occurred. - bool occurred() noexcept + bool occurred() const noexcept { return event_.load(std::memory_order_acquire); } diff --git a/libs/core/synchronization/include/hpx/synchronization/latch.hpp b/libs/core/synchronization/include/hpx/synchronization/latch.hpp index 012ec21c60ac..b800446e1806 100644 --- a/libs/core/synchronization/include/hpx/synchronization/latch.hpp +++ b/libs/core/synchronization/include/hpx/synchronization/latch.hpp @@ -25,13 +25,16 @@ namespace hpx { /// Latches are a thread coordination mechanism that allow one or more - /// threads to block until an operation is completed. An individual latch - /// is a singleuse object; once the operation has been completed, the latch + /// threads to block until an operation is completed. An individual latch is + /// a single-use object; once the operation has been completed, the latch /// cannot be reused. class latch { public: - HPX_NON_COPYABLE(latch); + latch(latch const&) = delete; + latch(latch&&) = delete; + latch& operator=(latch const&) = delete; + latch& operator=(latch&&) = delete; protected: using mutex_type = hpx::spinlock; @@ -44,9 +47,7 @@ namespace hpx { /// Postconditions: counter_ == count. /// explicit latch(std::ptrdiff_t count) - : mtx_() - , cond_() - , counter_(count) + : counter_(count) , notified_(count == 0) { } @@ -90,7 +91,7 @@ namespace hpx { { HPX_ASSERT(update >= 0); - std::ptrdiff_t new_count = (counter_ -= update); + std::ptrdiff_t const new_count = (counter_ -= update); HPX_ASSERT(new_count >= 0); // 26111: Caller failing to release lock 'this->mtx_.data_' @@ -168,7 +169,7 @@ namespace hpx { std::unique_lock l(mtx_.data_); - std::ptrdiff_t old_count = + std::ptrdiff_t const old_count = counter_.fetch_sub(update, std::memory_order_relaxed); HPX_ASSERT_LOCKED(l, old_count >= update); @@ -295,7 +296,7 @@ namespace hpx::lcos::local { return hpx::latch::try_wait(); } - void abort_all() + void abort_all() const { // 26115: Failing to release lock 'this->mtx_.data_' #if defined(HPX_MSVC) @@ -321,7 +322,7 @@ namespace hpx::lcos::local { { HPX_ASSERT(n >= 0); - std::ptrdiff_t old_count = + std::ptrdiff_t const old_count = counter_.fetch_add(n, std::memory_order_acq_rel); HPX_ASSERT(old_count > 0); @@ -337,7 +338,7 @@ namespace hpx::lcos::local { { HPX_ASSERT(n >= 0); - std::ptrdiff_t old_count = + std::ptrdiff_t const old_count = counter_.exchange(n, std::memory_order_acq_rel); HPX_ASSERT(old_count == 0); @@ -364,7 +365,7 @@ namespace hpx::lcos::local { { notified_ = false; - std::ptrdiff_t old_count = + std::ptrdiff_t const old_count = counter_.fetch_add(n + count, std::memory_order_relaxed); HPX_ASSERT(old_count == 0); @@ -373,7 +374,7 @@ namespace hpx::lcos::local { return true; } - std::ptrdiff_t old_count = + std::ptrdiff_t const old_count = counter_.fetch_add(n, std::memory_order_relaxed); HPX_ASSERT(old_count > 0); diff --git a/libs/core/synchronization/include/hpx/synchronization/no_mutex.hpp b/libs/core/synchronization/include/hpx/synchronization/no_mutex.hpp index a21e5d67ebf2..95fefe0bdd88 100644 --- a/libs/core/synchronization/include/hpx/synchronization/no_mutex.hpp +++ b/libs/core/synchronization/include/hpx/synchronization/no_mutex.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 @@ -17,14 +17,14 @@ namespace hpx { /// inconsistencies. struct no_mutex { - constexpr void lock() noexcept {} + static constexpr void lock() noexcept {} - constexpr bool try_lock() noexcept + static constexpr bool try_lock() noexcept { return true; } - constexpr void unlock() noexcept {} + static constexpr void unlock() noexcept {} }; } // namespace hpx diff --git a/libs/core/synchronization/include/hpx/synchronization/once.hpp b/libs/core/synchronization/include/hpx/synchronization/once.hpp index 8d1b3575e9a5..ad6bfb798b36 100644 --- a/libs/core/synchronization/include/hpx/synchronization/once.hpp +++ b/libs/core/synchronization/include/hpx/synchronization/once.hpp @@ -82,7 +82,7 @@ namespace hpx { /// /// \param flag an object, for which exactly one function gets executed /// \param f Callable object to invoke - /// \param args... arguments to pass to the function + /// \param args arguments to pass to the function /// /// \throws std::system_error if any condition prevents calls to \a /// call_once from executing as specified or any exception thrown by diff --git a/libs/core/synchronization/include/hpx/synchronization/recursive_mutex.hpp b/libs/core/synchronization/include/hpx/synchronization/recursive_mutex.hpp index 92a7b1d743e9..8b03ce89133f 100644 --- a/libs/core/synchronization/include/hpx/synchronization/recursive_mutex.hpp +++ b/libs/core/synchronization/include/hpx/synchronization/recursive_mutex.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 @@ -40,7 +40,7 @@ namespace hpx { public: // clang-format off - recursive_mutex_impl(char const* desc = "recursive_mutex_impl") + explicit recursive_mutex_impl(char const* desc = "recursive_mutex_impl") noexcept(noexcept( std::is_nothrow_constructible_v)) : recursion_count(0) @@ -57,7 +57,7 @@ namespace hpx { /// \throws Never throws. bool try_lock() { - auto ctx = hpx::execution_base::this_thread::agent(); + auto const ctx = hpx::execution_base::this_thread::agent(); HPX_ASSERT(ctx); return try_recursive_lock(ctx) || try_basic_lock(ctx); @@ -73,7 +73,7 @@ namespace hpx { /// HPX-thread. void lock() { - auto ctx = hpx::execution_base::this_thread::agent(); + auto const ctx = hpx::execution_base::this_thread::agent(); HPX_ASSERT(ctx); if (!try_recursive_lock(ctx)) diff --git a/libs/core/synchronization/include/hpx/synchronization/shared_mutex.hpp b/libs/core/synchronization/include/hpx/synchronization/shared_mutex.hpp index 8ae63161e877..24beb12e22db 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 Hartmut Kaiser +// (C) Copyright 2022-2023 Hartmut Kaiser // // SPDX-License-Identifier: BSL-1.0 // Distributed under the Boost Software License, Version 1.0. (See accompanying @@ -49,9 +49,6 @@ namespace hpx { public: shared_mutex() : state{0u, false, false, false} - , shared_cond() - , exclusive_cond() - , upgrade_cond() { } @@ -85,9 +82,7 @@ namespace hpx { { std::unique_lock lk(state_change); - bool const last_reader = !--state.shared_count; - - if (last_reader) + if (/*bool const last_reader = */ !--state.shared_count) { if (state.upgrade) { @@ -160,23 +155,21 @@ namespace hpx { if (state.exclusive || state.exclusive_waiting_blocked || state.upgrade) - return false; - - else { - ++state.shared_count; - state.upgrade = true; - return true; + return false; } + + ++state.shared_count; + state.upgrade = true; + return true; } void unlock_upgrade() { std::unique_lock lk(state_change); state.upgrade = false; - bool const last_reader = !--state.shared_count; - if (last_reader) + if (/*bool const last_reader = */ !--state.shared_count) { state.exclusive_waiting_blocked = false; release_waiters(); diff --git a/libs/core/synchronization/include/hpx/synchronization/spinlock.hpp b/libs/core/synchronization/include/hpx/synchronization/spinlock.hpp index d1ad1c88245c..e6fbbc1f1417 100644 --- a/libs/core/synchronization/include/hpx/synchronization/spinlock.hpp +++ b/libs/core/synchronization/include/hpx/synchronization/spinlock.hpp @@ -118,8 +118,7 @@ namespace hpx { { HPX_ITT_SYNC_PREPARE(this); - bool r = acquire_lock(); //-V707 - if (r) + if (acquire_lock()) { HPX_ITT_SYNC_ACQUIRED(this); util::register_lock(this); diff --git a/libs/core/synchronization/include/hpx/synchronization/spinlock_pool.hpp b/libs/core/synchronization/include/hpx/synchronization/spinlock_pool.hpp index 15aee07da7b5..517efdd327e1 100644 --- a/libs/core/synchronization/include/hpx/synchronization/spinlock_pool.hpp +++ b/libs/core/synchronization/include/hpx/synchronization/spinlock_pool.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2012-2022 Hartmut Kaiser +// Copyright (c) 2012-2023 Hartmut Kaiser // Copyright (c) 2014 Thomas Heller // // adapted from: @@ -60,14 +60,14 @@ namespace hpx { unlock(); } - void lock() noexcept( - noexcept(std::declval().lock())) + void lock() const + noexcept(noexcept(std::declval().lock())) { sp_.lock(); } - void unlock() noexcept( - noexcept(std::declval().unlock())) + void unlock() const + noexcept(noexcept(std::declval().unlock())) { sp_.unlock(); } diff --git a/libs/core/synchronization/include/hpx/synchronization/stop_token.hpp b/libs/core/synchronization/include/hpx/synchronization/stop_token.hpp index 5ec4c8c10359..bf3dbdda456a 100644 --- a/libs/core/synchronization/include/hpx/synchronization/stop_token.hpp +++ b/libs/core/synchronization/include/hpx/synchronization/stop_token.hpp @@ -70,7 +70,14 @@ namespace hpx { virtual void execute() noexcept = 0; void add_this_callback(stop_callback_base*& callbacks) noexcept; - bool remove_this_callback() noexcept; + bool remove_this_callback() const noexcept; + + stop_callback_base() = default; + + stop_callback_base(stop_callback_base const&) = delete; + stop_callback_base(stop_callback_base&&) = delete; + stop_callback_base& operator=(stop_callback_base const&) = delete; + stop_callback_base& operator=(stop_callback_base&&) = delete; protected: virtual ~stop_callback_base() = default; @@ -104,6 +111,11 @@ namespace hpx { { } + stop_state(stop_state const&) = delete; + stop_state(stop_state&&) = delete; + stop_state& operator=(stop_state const&) = delete; + stop_state& operator=(stop_state&&) = delete; + ~stop_state() { HPX_ASSERT((state_.load(std::memory_order_relaxed) & @@ -138,7 +150,7 @@ namespace hpx { HPX_CORE_EXPORT bool add_callback(stop_callback_base* cb) noexcept; HPX_CORE_EXPORT void remove_callback( - stop_callback_base* cb) noexcept; + stop_callback_base const* cb) noexcept; private: [[nodiscard]] static bool is_locked(std::uint64_t state) noexcept @@ -246,17 +258,10 @@ namespace hpx { // state] constexpr stop_token() noexcept = default; - stop_token(stop_token const& rhs) noexcept - : state_(rhs.state_) - { - } + stop_token(stop_token const& rhs) = default; stop_token(stop_token&&) noexcept = default; - stop_token& operator=(stop_token const& rhs) noexcept - { - state_ = rhs.state_; - return *this; - } + stop_token& operator=(stop_token const& rhs) = default; stop_token& operator=(stop_token&&) noexcept = default; // Effects: Releases ownership of the stop state, if any. @@ -366,7 +371,7 @@ namespace hpx { public: // 32.3.4.1 constructors, copy, and assignment - // Effects: Initialises *this to have ownership of a new stop state. + // Effects: Initializes *this to have ownership of a new stop state. // // Postconditions: stop_possible() is true and stop_requested() is false. // @@ -422,7 +427,7 @@ namespace hpx { { if (!stop_possible()) { - return stop_token(); + return {}; } return stop_token(state_); } @@ -458,7 +463,7 @@ namespace hpx { // // Returns: true if this call made a stop request; otherwise false /// makes a stop request for the associated stop-state, if any - bool request_stop() noexcept + bool request_stop() const noexcept { return !!state_ && state_->request_stop(); } @@ -537,13 +542,13 @@ namespace hpx { } // Effects: Unregisters the callback from the owned stop state, if any. - // The destructor does not block waiting for the execution of anrhs - // callback registered by an associated stop_callback. If the - // callback is concurrently executing on anrhs thread, then the - // return from the invocation of callback strongly happens before - // (6.9.2.1) callback is destroyed. If callback is executing on the - // current thread, then the destructor does not block (3.6) waiting - // for the return from the invocation of callback. Releases + // The destructor does not block waiting for the execution of + // another callback registered by an associated stop_callback. If + // the callback is concurrently executing on another thread, then + // the return from the invocation of callback strongly happens + // before (6.9.2.1) callback is destroyed. If callback is executing + // on the current thread, then the destructor does not block (3.6) + // waiting for the return from the invocation of callback. Releases // ownership of the stop state, if any. ~stop_callback() { @@ -623,7 +628,7 @@ namespace hpx { } // namespace hpx //////////////////////////////////////////////////////////////////////////////// -// Extensions to as preposed by P2300 +// Extensions to as proposed by P2300 namespace hpx::p2300_stop_token { // [stoptoken.inplace], class in_place_stop_token @@ -794,6 +799,8 @@ namespace hpx::p2300_stop_token { { } + ~in_place_stop_token() = default; + in_place_stop_token(in_place_stop_token const& rhs) noexcept = default; in_place_stop_token(in_place_stop_token&& rhs) noexcept diff --git a/libs/core/synchronization/src/detail/condition_variable.cpp b/libs/core/synchronization/src/detail/condition_variable.cpp index e74a4dfeadf0..7b86274f2af0 100644 --- a/libs/core/synchronization/src/detail/condition_variable.cpp +++ b/libs/core/synchronization/src/detail/condition_variable.cpp @@ -52,12 +52,16 @@ namespace hpx::lcos::local::detail { { } + reset_queue_entry(reset_queue_entry const&) = delete; + reset_queue_entry(reset_queue_entry&&) = delete; + reset_queue_entry& operator=(reset_queue_entry const&) = delete; + reset_queue_entry& operator=(reset_queue_entry&&) = delete; + ~reset_queue_entry() { if (e_.ctx_) { - condition_variable::queue_type* q = - static_cast(e_.q_); + auto* q = static_cast(e_.q_); q->erase(&e_); // remove entry from queue } } @@ -117,7 +121,7 @@ namespace hpx::lcos::local::detail { if (!queue_.empty()) { - auto ctx = queue_.front()->ctx_; + auto const ctx = queue_.front()->ctx_; // remove item from queue before error handling queue_.front()->ctx_.reset(); @@ -133,7 +137,7 @@ namespace hpx::lcos::local::detail { return false; } - bool not_empty = !queue_.empty(); + bool const not_empty = !queue_.empty(); lock.unlock(); ctx.resume(); @@ -192,7 +196,7 @@ namespace hpx::lcos::local::detail { return; } - util::ignore_while_checking il(&lock); + util::ignore_while_checking const il(&lock); HPX_UNUSED(il); ctx.resume(); @@ -222,7 +226,7 @@ namespace hpx::lcos::local::detail { HPX_ASSERT_OWNS_LOCK(lock); // enqueue the request and block this thread - auto this_ctx = hpx::execution_base::this_thread::agent(); + auto const this_ctx = hpx::execution_base::this_thread::agent(); queue_entry f(this_ctx, &queue_); queue_.push_back(f); diff --git a/libs/core/synchronization/src/detail/counting_semaphore.cpp b/libs/core/synchronization/src/detail/counting_semaphore.cpp index 560146b64d71..6248663e9fb3 100644 --- a/libs/core/synchronization/src/detail/counting_semaphore.cpp +++ b/libs/core/synchronization/src/detail/counting_semaphore.cpp @@ -63,7 +63,7 @@ namespace hpx::lcos::local::detail { { HPX_ASSERT_OWNS_LOCK(l); - if (!(value_ < count)) + if (value_ >= count) { // enter wait_locked only if there are sufficient credits available wait(l, count); @@ -108,7 +108,7 @@ namespace hpx::lcos::local::detail { { HPX_ASSERT_OWNS_LOCK(l); - std::ptrdiff_t count = static_cast(cond_.size(l)); + auto const count = static_cast(cond_.size(l)); signal(HPX_MOVE(l), count); return count; } diff --git a/libs/core/synchronization/src/detail/sliding_semaphore.cpp b/libs/core/synchronization/src/detail/sliding_semaphore.cpp index 956eb8055b7b..ef9a5b6c2fa4 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-2020 Hartmut Kaiser +// Copyright (c) 2016-2023 Hartmut Kaiser // // SPDX-License-Identifier: BSL-1.0 // Distributed under the Boost Software License, Version 1.0. (See accompanying @@ -22,7 +22,6 @@ namespace hpx::lcos::local::detail { std::int64_t max_difference, std::int64_t lower_limit) noexcept : max_difference_(max_difference) , lower_limit_(lower_limit) - , cond_() { } @@ -53,7 +52,7 @@ namespace hpx::lcos::local::detail { { HPX_ASSERT_OWNS_LOCK(l); - if (!(upper_limit - max_difference_ > lower_limit_)) + if (upper_limit - max_difference_ <= lower_limit_) { // enter wait_locked only if necessary wait(l, upper_limit); diff --git a/libs/core/synchronization/src/local_barrier.cpp b/libs/core/synchronization/src/local_barrier.cpp index 470f8062e4c8..637ffd67681e 100644 --- a/libs/core/synchronization/src/local_barrier.cpp +++ b/libs/core/synchronization/src/local_barrier.cpp @@ -34,8 +34,6 @@ namespace hpx::lcos::local { barrier::barrier(std::size_t expected) : number_of_threads_(expected) , total_(barrier_flag) - , mtx_() - , cond_() { } diff --git a/libs/core/synchronization/src/mutex.cpp b/libs/core/synchronization/src/mutex.cpp index 77802938def4..581fc4172706 100644 --- a/libs/core/synchronization/src/mutex.cpp +++ b/libs/core/synchronization/src/mutex.cpp @@ -48,7 +48,7 @@ namespace hpx { HPX_ITT_SYNC_PREPARE(this); std::unique_lock l(mtx_); - threads::thread_id_type self_id = threads::get_self_id(); + threads::thread_id_type const self_id = threads::get_self_id(); if (owner_id_ == self_id) { HPX_ITT_SYNC_CANCEL(this); @@ -86,7 +86,7 @@ namespace hpx { return false; } - threads::thread_id_type self_id = threads::get_self_id(); + threads::thread_id_type const self_id = threads::get_self_id(); util::register_lock(this); HPX_ITT_SYNC_ACQUIRED(this); owner_id_ = self_id; @@ -102,7 +102,7 @@ namespace hpx { util::unregister_lock(this); std::unique_lock l(mtx_); - threads::thread_id_type self_id = threads::get_self_id(); + threads::thread_id_type const self_id = threads::get_self_id(); if (HPX_UNLIKELY(owner_id_ != self_id)) { l.unlock(); @@ -148,7 +148,7 @@ namespace hpx { HPX_ITT_SYNC_PREPARE(this); std::unique_lock l(mtx_); - threads::thread_id_type self_id = threads::get_self_id(); + threads::thread_id_type const self_id = threads::get_self_id(); if (owner_id_ != threads::invalid_thread_id) { threads::thread_restart_state const reason = diff --git a/libs/core/synchronization/src/stop_token.cpp b/libs/core/synchronization/src/stop_token.cpp index 54500f123323..0dad189bd0d5 100644 --- a/libs/core/synchronization/src/stop_token.cpp +++ b/libs/core/synchronization/src/stop_token.cpp @@ -16,7 +16,7 @@ #include #include -namespace hpx { namespace detail { +namespace hpx::detail { /////////////////////////////////////////////////////////////////////////// void intrusive_ptr_add_ref(stop_state* p) noexcept @@ -27,7 +27,7 @@ namespace hpx { namespace detail { void intrusive_ptr_release(stop_state* p) noexcept { - std::uint64_t old_state = p->state_.fetch_sub( + std::uint64_t const old_state = p->state_.fetch_sub( stop_state::token_ref_increment, std::memory_order_acq_rel); if ((old_state & stop_state::token_ref_mask) == @@ -51,7 +51,7 @@ namespace hpx { namespace detail { } // returns true if the callback was successfully removed - bool stop_callback_base::remove_this_callback() noexcept + bool stop_callback_base::remove_this_callback() const noexcept { if (prev_ != nullptr) { @@ -179,7 +179,7 @@ namespace hpx { namespace detail { bool stop_state::add_callback(stop_callback_base* cb) noexcept { - scoped_lock_if_not_stopped l(*this, cb); + scoped_lock_if_not_stopped const l(*this, cb); if (!l) return false; @@ -189,7 +189,7 @@ namespace hpx { namespace detail { } /////////////////////////////////////////////////////////////////////////// - void stop_state::remove_callback(stop_callback_base* cb) noexcept + void stop_state::remove_callback(stop_callback_base const* cb) noexcept { { std::lock_guard l(*this); @@ -228,7 +228,7 @@ namespace hpx { namespace detail { /////////////////////////////////////////////////////////////////////////// struct scoped_lock_and_request_stop { - scoped_lock_and_request_stop(stop_state& state) noexcept + explicit scoped_lock_and_request_stop(stop_state& state) noexcept : state_(state) , has_lock_(state_.lock_and_request_stop()) { @@ -239,16 +239,25 @@ namespace hpx { namespace detail { state_.unlock(); } + scoped_lock_and_request_stop( + scoped_lock_and_request_stop const&) = delete; + scoped_lock_and_request_stop(scoped_lock_and_request_stop&&) = delete; + scoped_lock_and_request_stop& operator=( + scoped_lock_and_request_stop const&) = delete; + scoped_lock_and_request_stop& operator=( + scoped_lock_and_request_stop&&) = delete; + explicit operator bool() const noexcept { return has_lock_; } - void unlock() noexcept + void unlock() const noexcept { state_.unlock(); } + private: stop_state& state_; bool has_lock_; }; @@ -256,7 +265,7 @@ namespace hpx { namespace detail { bool stop_state::request_stop() noexcept { // Set the 'stop_requested' signal and acquired the lock. - scoped_lock_and_request_stop l(*this); + scoped_lock_and_request_stop const l(*this); if (!l) return false; // stop has already been requested. @@ -298,4 +307,4 @@ namespace hpx { namespace detail { return true; } -}} // namespace hpx::detail +} // namespace hpx::detail