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
cd92284c
Commit
cd92284c
authored
Sep 13, 2014
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Minimize locking in double_ended_queue::prepend
parent
9dcebc5d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
11 deletions
+23
-11
libcaf_core/caf/detail/double_ended_queue.hpp
libcaf_core/caf/detail/double_ended_queue.hpp
+23
-11
No files found.
libcaf_core/caf/detail/double_ended_queue.hpp
View file @
cd92284c
...
@@ -133,23 +133,35 @@ class double_ended_queue {
...
@@ -133,23 +133,35 @@ class double_ended_queue {
m_tail
=
tmp
;
m_tail
=
tmp
;
}
}
// acquires both locks
// acquires both locks
if empty()
void
prepend
(
pointer
value
)
{
void
prepend
(
pointer
value
)
{
CAF_REQUIRE
(
value
!=
nullptr
);
CAF_REQUIRE
(
value
!=
nullptr
);
node
*
tmp
=
new
node
(
value
);
node
*
tmp
=
new
node
(
value
);
node
*
first
=
nullptr
;
auto
insert
=
[
&
]
{
auto
next
=
first
->
next
.
load
();
// m_first always points to a dummy with no value,
// hence we put the new element second
tmp
->
next
=
next
;
first
->
next
=
tmp
;
};
// acquire both locks since we might touch m_last too
// acquire both locks since we might touch m_last too
lock_guard
guard1
(
m_head_lock
);
lock_guard
guard1
(
m_head_lock
);
lock_guard
guard2
(
m_tail_lock
);
first
=
m_head
.
load
();
auto
first
=
m_head
.
load
();
if
(
first
==
m_tail
)
{
auto
next
=
first
->
next
.
load
();
// acquire second lock as well and move tail after insertion
// m_first always points to a dummy with no value,
lock_guard
guard2
(
m_tail_lock
);
// hence we put the new element second
// condition still strue?
tmp
->
next
=
next
;
if
(
first
==
m_tail
)
{
first
->
next
=
tmp
;
insert
();
// in case the queue is empty, we need to swing last forward
m_tail
=
tmp
;
if
(
m_tail
==
first
)
{
return
;
m_tail
=
tmp
;
}
// else: someone called append() in the meantime,
// release lock and insert as usual
}
}
// insertion without second lock is safe
insert
();
}
}
// acquires only one lock, returns nullptr on failure
// acquires only one lock, returns nullptr on failure
...
...
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