Skip to content

Commit

Permalink
Trying to streamline shared_mutex
Browse files Browse the repository at this point in the history
  • Loading branch information
hkaiser committed Oct 19, 2023
1 parent f988598 commit 5ce01b4
Show file tree
Hide file tree
Showing 8 changed files with 594 additions and 231 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include <hpx/thread_support/assert_owns_lock.hpp>
#include <hpx/thread_support/unlock_guard.hpp>
#include <hpx/timing/steady_clock.hpp>
#include <hpx/type_support/unused.hpp>

#include <mutex>
#include <utility>
Expand Down Expand Up @@ -158,7 +157,7 @@ namespace hpx {
///
/// \returns \a notify_one returns \a void.
///
void notify_one(error_code& ec = throws)
void notify_one(error_code& ec = throws) const
{
std::unique_lock<mutex_type> l(data_->mtx_);
data_->cond_.notify_one(HPX_MOVE(l), ec);
Expand All @@ -173,7 +172,7 @@ namespace hpx {
///
/// \returns \a notify_all returns \a void.
///
void notify_all(error_code& ec = throws)
void notify_all(error_code& ec = throws) const
{
std::unique_lock<mutex_type> l(data_->mtx_);
data_->cond_.notify_all(HPX_MOVE(l), ec);
Expand Down Expand Up @@ -214,8 +213,7 @@ namespace hpx {

auto const data = data_; // keep data alive

util::ignore_all_while_checking const ignore_lock;
HPX_UNUSED(ignore_lock);
[[maybe_unused]] util::ignore_all_while_checking const ignore_lock;

std::unique_lock<mutex_type> l(data->mtx_);
unlock_guard<std::unique_lock<Mutex>> unlock(lock);
Expand Down Expand Up @@ -321,8 +319,7 @@ namespace hpx {

auto const data = data_; // keep data alive

util::ignore_all_while_checking const ignore_lock;
HPX_UNUSED(ignore_lock);
[[maybe_unused]] util::ignore_all_while_checking const ignore_lock;

std::unique_lock<mutex_type> l(data->mtx_);
unlock_guard<std::unique_lock<Mutex>> unlock(lock);
Expand Down Expand Up @@ -620,7 +617,7 @@ namespace hpx {
///
/// \returns \a notify_one returns \a void.
///
void notify_one(error_code& ec = throws)
void notify_one(error_code& ec = throws) const
{
std::unique_lock<mutex_type> l(data_->mtx_);
data_->cond_.notify_one(HPX_MOVE(l), ec);
Expand Down Expand Up @@ -651,7 +648,7 @@ namespace hpx {
///
/// \returns \a notify_all returns \a void.
///
void notify_all(error_code& ec = throws)
void notify_all(error_code& ec = throws) const
{
std::unique_lock<mutex_type> l(data_->mtx_);
data_->cond_.notify_all(HPX_MOVE(l), ec);
Expand Down Expand Up @@ -702,8 +699,7 @@ namespace hpx {

auto const data = data_; // keep data alive

util::ignore_all_while_checking const ignore_lock;
HPX_UNUSED(ignore_lock);
[[maybe_unused]] util::ignore_all_while_checking const ignore_lock;

std::unique_lock<mutex_type> l(data->mtx_);
unlock_guard<Lock> unlock(lock);
Expand Down Expand Up @@ -819,8 +815,7 @@ namespace hpx {

auto const data = data_; // keep data alive

util::ignore_all_while_checking const ignore_lock;
HPX_UNUSED(ignore_lock);
[[maybe_unused]] util::ignore_all_while_checking const ignore_lock;

std::unique_lock<mutex_type> l(data->mtx_);
unlock_guard<Lock> unlock(lock);
Expand Down Expand Up @@ -1069,14 +1064,14 @@ namespace hpx {

while (!pred())
{
util::ignore_all_while_checking const ignore_lock;
HPX_UNUSED(ignore_lock);
[[maybe_unused]] util::ignore_all_while_checking const
ignore_lock;

std::unique_lock<mutex_type> l(data->mtx_);
if (stoken.stop_requested())
{
// pred() has already evaluated to false since we last
// a acquired lock
// an acquired lock
return false;
}

Expand Down Expand Up @@ -1164,8 +1159,8 @@ namespace hpx {
{
bool should_stop;
{
util::ignore_all_while_checking const ignore_lock;
HPX_UNUSED(ignore_lock);
[[maybe_unused]] util::ignore_all_while_checking const
ignore_lock;

std::unique_lock<mutex_type> l(data->mtx_);
if (stoken.stop_requested())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2007-2022 Hartmut Kaiser
// Copyright (c) 2007-2023 Hartmut Kaiser
// Copyright (c) 2013-2015 Agustin Berge
//
// SPDX-License-Identifier: BSL-1.0
Expand Down Expand Up @@ -55,17 +55,31 @@ namespace hpx::lcos::local::detail {

// Return false if no more threads are waiting (returns true if queue is
// non-empty).
HPX_CORE_EXPORT bool notify_one(std::unique_lock<mutex_type> lock,
threads::thread_priority priority, error_code& ec = throws);
HPX_CORE_EXPORT bool notify_one(std::unique_lock<mutex_type>& lock,
threads::thread_priority priority, bool unlock,
error_code& ec = throws);

HPX_CORE_EXPORT void notify_all(std::unique_lock<mutex_type> lock,
threads::thread_priority priority, error_code& ec = throws);

bool notify_one(std::unique_lock<mutex_type> lock,
threads::thread_priority priority, error_code& ec = throws)
{
return notify_one(lock, priority, true, ec);
}

bool notify_one(
std::unique_lock<mutex_type> lock, error_code& ec = throws)
{
return notify_one(
HPX_MOVE(lock), threads::thread_priority::default_, ec);
lock, threads::thread_priority::default_, true, ec);
}

bool notify_one_no_unlock(
std::unique_lock<mutex_type>& lock, error_code& ec = throws)
{
return notify_one(
lock, threads::thread_priority::default_, false, ec);
}

void notify_all(
Expand Down
Loading

0 comments on commit 5ce01b4

Please sign in to comment.