-
-
Notifications
You must be signed in to change notification settings - Fork 542
performance: Optimize shared_mutex and fix C++20 modular build errors #7007
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 2 commits
d5bf3c3
6acdd90
47de6f4
a371a39
f00d4da
13ad2b2
5c3a426
38d7f22
e7605f4
1ed78e7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -121,9 +121,9 @@ namespace hpx::detail { | |||||
|
|
||||||
| bool try_lock_shared() | ||||||
| { | ||||||
| auto s = state.load(std::memory_order_acquire); | ||||||
| while (true) | ||||||
| { | ||||||
| auto s = state.load(std::memory_order_acquire); | ||||||
| if (s.data.exclusive || s.data.exclusive_waiting_blocked) | ||||||
| { | ||||||
| return false; | ||||||
|
|
@@ -136,15 +136,37 @@ namespace hpx::detail { | |||||
| { | ||||||
| break; | ||||||
| } | ||||||
| s = state.load(std::memory_order_acquire); | ||||||
| } | ||||||
|
hkaiser marked this conversation as resolved.
|
||||||
| return true; | ||||||
| } | ||||||
|
hkaiser marked this conversation as resolved.
|
||||||
|
|
||||||
| void unlock_shared() | ||||||
| bool try_unlock_shared_fast() | ||||||
| { | ||||||
| while (true) | ||||||
| { | ||||||
| auto s = state.load(std::memory_order_acquire); | ||||||
|
hkaiser marked this conversation as resolved.
Outdated
|
||||||
| if (s.data.exclusive || s.data.exclusive_waiting_blocked || | ||||||
| s.data.upgrade || s.data.shared_count <= 1) | ||||||
| { | ||||||
| return false; | ||||||
| } | ||||||
|
|
||||||
| auto s1 = s; | ||||||
| --s.data.shared_count; | ||||||
| if (set_state(s1, s)) | ||||||
| { | ||||||
| return true; | ||||||
| } | ||||||
| s = s1; | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| void unlock_shared() | ||||||
| { | ||||||
| auto s = state.load(std::memory_order_acquire); | ||||||
| while (true) | ||||||
| { | ||||||
| auto s1 = s; | ||||||
|
|
||||||
| if (--s.data.shared_count == 0) | ||||||
|
|
@@ -184,14 +206,15 @@ namespace hpx::detail { | |||||
| { | ||||||
| break; | ||||||
| } | ||||||
| s = state.load(std::memory_order_acquire); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| void lock() | ||||||
| { | ||||||
| auto s = state.load(std::memory_order_acquire); | ||||||
| while (true) | ||||||
| { | ||||||
| auto s = state.load(std::memory_order_acquire); | ||||||
| while (s.data.shared_count != 0 || s.data.exclusive) | ||||||
| { | ||||||
| auto s1 = s; | ||||||
|
|
@@ -214,14 +237,15 @@ namespace hpx::detail { | |||||
| { | ||||||
| break; | ||||||
| } | ||||||
| s = state.load(std::memory_order_acquire); | ||||||
|
hkaiser marked this conversation as resolved.
Outdated
|
||||||
| } | ||||||
| } | ||||||
|
|
||||||
| bool try_lock() | ||||||
| { | ||||||
| auto s = state.load(std::memory_order_acquire); | ||||||
| while (true) | ||||||
| { | ||||||
| auto s = state.load(std::memory_order_acquire); | ||||||
| if (s.data.shared_count || s.data.exclusive) | ||||||
| { | ||||||
| return false; | ||||||
|
|
@@ -234,15 +258,16 @@ namespace hpx::detail { | |||||
| { | ||||||
| break; | ||||||
| } | ||||||
| s = state.load(std::memory_order_acquire); | ||||||
| } | ||||||
| return true; | ||||||
| } | ||||||
|
|
||||||
| void unlock() | ||||||
| { | ||||||
| auto s = state.load(std::memory_order_acquire); | ||||||
| while (true) | ||||||
| { | ||||||
| auto s = state.load(std::memory_order_acquire); | ||||||
| auto s1 = s; | ||||||
|
|
||||||
| s.data.exclusive = false; | ||||||
|
|
@@ -255,6 +280,7 @@ namespace hpx::detail { | |||||
| release_waiters(lk); | ||||||
| break; | ||||||
| } | ||||||
| s = state.load(std::memory_order_acquire); | ||||||
|
hkaiser marked this conversation as resolved.
Outdated
|
||||||
| } | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -287,9 +313,9 @@ namespace hpx::detail { | |||||
|
|
||||||
| bool try_lock_upgrade() | ||||||
| { | ||||||
| auto s = state.load(std::memory_order_acquire); | ||||||
| while (true) | ||||||
| { | ||||||
| auto s = state.load(std::memory_order_acquire); | ||||||
| if (s.data.exclusive || s.data.exclusive_waiting_blocked || | ||||||
| s.data.upgrade) | ||||||
| { | ||||||
|
|
@@ -304,15 +330,16 @@ namespace hpx::detail { | |||||
| { | ||||||
| break; | ||||||
| } | ||||||
| s = state.load(std::memory_order_acquire); | ||||||
| } | ||||||
| return true; | ||||||
| } | ||||||
|
|
||||||
| void unlock_upgrade() | ||||||
| { | ||||||
| auto s = state.load(std::memory_order_acquire); | ||||||
| while (true) | ||||||
| { | ||||||
| auto s = state.load(std::memory_order_acquire); | ||||||
| auto s1 = s; | ||||||
|
|
||||||
| bool release = false; | ||||||
|
|
@@ -337,6 +364,7 @@ namespace hpx::detail { | |||||
| { | ||||||
| break; | ||||||
| } | ||||||
| s = state.load(std::memory_order_acquire); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -384,9 +412,9 @@ namespace hpx::detail { | |||||
|
|
||||||
| void unlock_and_lock_upgrade() | ||||||
| { | ||||||
| auto s = state.load(std::memory_order_acquire); | ||||||
| while (true) | ||||||
| { | ||||||
| auto s = state.load(std::memory_order_acquire); | ||||||
| auto s1 = s; | ||||||
|
|
||||||
| s.data.exclusive = false; | ||||||
|
|
@@ -401,14 +429,15 @@ namespace hpx::detail { | |||||
| release_waiters(lk); | ||||||
| break; | ||||||
| } | ||||||
| s = state.load(std::memory_order_acquire); | ||||||
|
hkaiser marked this conversation as resolved.
Outdated
|
||||||
| } | ||||||
| } | ||||||
|
|
||||||
| void unlock_and_lock_shared() | ||||||
| { | ||||||
| auto s = state.load(std::memory_order_acquire); | ||||||
| while (true) | ||||||
| { | ||||||
| auto s = state.load(std::memory_order_acquire); | ||||||
| auto s1 = s; | ||||||
|
|
||||||
| s.data.exclusive = false; | ||||||
|
|
@@ -422,14 +451,15 @@ namespace hpx::detail { | |||||
| release_waiters(lk); | ||||||
| break; | ||||||
| } | ||||||
| s = state.load(std::memory_order_acquire); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| bool try_unlock_shared_and_lock() | ||||||
| { | ||||||
| auto s = state.load(std::memory_order_acquire); | ||||||
| while (true) | ||||||
| { | ||||||
| auto s = state.load(std::memory_order_acquire); | ||||||
| if (s.data.exclusive || s.data.exclusive_waiting_blocked || | ||||||
| s.data.upgrade || s.data.shared_count != 1) | ||||||
| { | ||||||
|
|
@@ -444,15 +474,16 @@ namespace hpx::detail { | |||||
| { | ||||||
| break; | ||||||
| } | ||||||
| s = state.load(std::memory_order_acquire); | ||||||
| } | ||||||
| return true; | ||||||
| } | ||||||
|
|
||||||
| void unlock_upgrade_and_lock_shared() | ||||||
| { | ||||||
| auto s = state.load(std::memory_order_acquire); | ||||||
| while (true) | ||||||
| { | ||||||
| auto s = state.load(std::memory_order_acquire); | ||||||
| auto s1 = s; | ||||||
|
|
||||||
| s.data.exclusive_waiting_blocked = false; | ||||||
|
|
@@ -465,6 +496,7 @@ namespace hpx::detail { | |||||
| release_waiters(lk); | ||||||
| break; | ||||||
| } | ||||||
| s = state.load(std::memory_order_acquire); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -510,6 +542,8 @@ namespace hpx::detail { | |||||
| void lock_shared() | ||||||
| { | ||||||
| auto data = data_; | ||||||
| if (data->try_lock_shared()) | ||||||
| return; | ||||||
| data->lock_shared(); | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -522,6 +556,8 @@ namespace hpx::detail { | |||||
| void unlock_shared() | ||||||
| { | ||||||
| auto data = data_; | ||||||
| if (data->try_unlock_shared_fast()) | ||||||
| return; | ||||||
|
Comment on lines
+557
to
+558
|
||||||
| if (data->try_unlock_shared_fast()) | |
| return; |
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,75 @@ | ||||||||
| // (C) Copyright 2026 Arpit Khandelwal | ||||||||
| // | ||||||||
| // SPDX-License-Identifier: BSL-1.0 | ||||||||
| // Distributed under the Boost Software License, Version 1.0. (See accompanying | ||||||||
| // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||||||||
|
|
||||||||
| #include <hpx/config.hpp> | ||||||||
| #include <hpx/hpx.hpp> | ||||||||
| #include <hpx/hpx_init.hpp> | ||||||||
| #include <hpx/include/util.hpp> | ||||||||
| #include <hpx/modules/testing.hpp> | ||||||||
| #include <hpx/synchronization/shared_mutex.hpp> | ||||||||
|
|
||||||||
| #include <cstdint> | ||||||||
| #include <iostream> | ||||||||
|
||||||||
| #include <iostream> | |
| #include <iostream> | |
| #include <shared_mutex> |
Copilot
AI
Apr 19, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::shared_lock is used but the file does not include the standard header that defines it. This will fail to compile on standard library implementations where shared_lock is only provided by <shared_mutex> (it is not guaranteed to be available via the HPX headers included here). Add the appropriate standard include (or switch to an HPX-provided lock type if that’s the intended API).
Uh oh!
There was an error while loading. Please reload this page.