Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
typon
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
cython-plus
typon
Commits
349a8d21
Commit
349a8d21
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
afb4b7d4
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 @
349a8d21
...
...
@@ -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