Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
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
Operations
Operations
Metrics
Environments
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
cpp-libs
Actor Framework
Commits
f15bba63
Commit
f15bba63
authored
Apr 20, 2014
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed possible race in synchronized queue ops
parent
b85e2d99
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
6 deletions
+16
-6
cppa/intrusive/single_reader_queue.hpp
cppa/intrusive/single_reader_queue.hpp
+16
-6
No files found.
cppa/intrusive/single_reader_queue.hpp
View file @
f15bba63
...
@@ -148,7 +148,6 @@ class single_reader_queue {
...
@@ -148,7 +148,6 @@ class single_reader_queue {
*/
*/
inline
bool
can_fetch_more
()
{
inline
bool
can_fetch_more
()
{
auto
ptr
=
m_stack
.
load
();
auto
ptr
=
m_stack
.
load
();
//CPPA_REQUIRE(ptr != reader_blocked_dummy());
CPPA_REQUIRE
(
ptr
!=
nullptr
);
CPPA_REQUIRE
(
ptr
!=
nullptr
);
return
!
is_dummy
(
ptr
);
return
!
is_dummy
(
ptr
);
}
}
...
@@ -171,12 +170,15 @@ class single_reader_queue {
...
@@ -171,12 +170,15 @@ class single_reader_queue {
/**
/**
* @brief Tries to set this queue from state @p empty to state @p blocked.
* @brief Tries to set this queue from state @p empty to state @p blocked.
* @returns @p true if the state change was successful, otherwise @p false.
* @returns @p true if the state change was successful or if the mailbox
* was already blocked, otherwise @p false.
* @note This function does never fail spuriously.
* @note This function does never fail spuriously.
*/
*/
inline
bool
try_block
()
{
inline
bool
try_block
()
{
auto
e
=
stack_empty_dummy
();
auto
e
=
stack_empty_dummy
();
return
m_stack
.
compare_exchange_strong
(
e
,
reader_blocked_dummy
());
bool
res
=
m_stack
.
compare_exchange_strong
(
e
,
reader_blocked_dummy
());
// return true in case queue was already blocked
return
res
||
e
==
reader_blocked_dummy
();
}
}
/**
/**
...
@@ -245,13 +247,21 @@ class single_reader_queue {
...
@@ -245,13 +247,21 @@ class single_reader_queue {
template
<
class
Mutex
,
class
CondVar
,
class
TimePoint
>
template
<
class
Mutex
,
class
CondVar
,
class
TimePoint
>
pointer
synchronized_try_pop
(
Mutex
&
mtx
,
CondVar
&
cv
,
const
TimePoint
&
abs_time
)
{
pointer
synchronized_try_pop
(
Mutex
&
mtx
,
CondVar
&
cv
,
const
TimePoint
&
abs_time
)
{
return
(
synchronized_await
(
mtx
,
cv
,
abs_time
))
?
try_pop
()
:
nullptr
;
auto
res
=
try_pop
();
if
(
!
res
&&
synchronized_await
(
mtx
,
cv
,
abs_time
))
{
res
=
try_pop
();
}
return
res
;
}
}
template
<
class
Mutex
,
class
CondVar
>
template
<
class
Mutex
,
class
CondVar
>
pointer
synchronized_pop
(
Mutex
&
mtx
,
CondVar
&
cv
)
{
pointer
synchronized_pop
(
Mutex
&
mtx
,
CondVar
&
cv
)
{
synchronized_await
(
mtx
,
cv
);
auto
res
=
try_pop
();
return
try_pop
();
if
(
!
res
)
{
synchronized_await
(
mtx
,
cv
);
res
=
try_pop
();
}
return
res
;
}
}
template
<
class
Mutex
,
class
CondVar
>
template
<
class
Mutex
,
class
CondVar
>
...
...
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