Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
typon-concurrency
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
typon
typon-concurrency
Commits
12355e1e
Commit
12355e1e
authored
Jul 20, 2022
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mutex.hpp: Optimise some atomics memory ordering
parent
f074f70a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
4 deletions
+6
-4
rt/include/typon/mutex.hpp
rt/include/typon/mutex.hpp
+6
-4
No files found.
rt/include/typon/mutex.hpp
View file @
12355e1e
...
...
@@ -25,6 +25,8 @@ namespace typon
std
::
atomic
<
std
::
uintptr_t
>
_stack
{
0
};
};
using
enum
std
::
memory_order
;
std
::
atomic
<
Node
*>
_state
{
nullptr
};
Node
*
_waiters
{
nullptr
};
...
...
@@ -36,12 +38,13 @@ namespace typon
bool
await_ready
()
noexcept
{
std
::
atomic
<
Node
*>
&
state
=
_mutex
->
_state
;
Node
*
next
=
nullptr
;
for
(;;)
{
// _next must be properly set before updating _state
_next
=
next
;
if
(
_mutex
->
_state
.
compare_exchange_weak
(
next
,
this
))
if
(
state
.
compare_exchange_weak
(
next
,
this
,
acq_rel
,
relaxed
))
{
return
!
next
;
}
...
...
@@ -64,12 +67,11 @@ namespace typon
Node
*
waiter
=
_mutex
->
_waiters
;
if
(
!
waiter
)
{
Node
*
state
=
this
;
if
(
_mutex
->
_state
.
compare_exchange_strong
(
state
,
nullptr
))
Node
*
next
=
this
;
if
(
_mutex
->
_state
.
compare_exchange_strong
(
next
,
nullptr
,
acq_rel
))
{
return
;
}
auto
next
=
state
;
while
(
next
!=
this
)
{
auto
tmp
=
next
->
_next
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment