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
acc1fa08
Commit
acc1fa08
authored
Dec 06, 2017
by
Dominik Charousset
Committed by
Dominik Charousset
Feb 06, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add task_queue::peek_all member function
parent
1e8bf53a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
1 deletion
+58
-1
libcaf_core/caf/intrusive/task_queue.hpp
libcaf_core/caf/intrusive/task_queue.hpp
+36
-1
libcaf_core/test/task_queue.cpp
libcaf_core/test/task_queue.cpp
+22
-0
No files found.
libcaf_core/caf/intrusive/task_queue.hpp
View file @
acc1fa08
...
@@ -59,6 +59,8 @@ public:
...
@@ -59,6 +59,8 @@ public:
using
iterator
=
forward_iterator
<
value_type
>
;
using
iterator
=
forward_iterator
<
value_type
>
;
using
const_iterator
=
forward_iterator
<
const
value_type
>
;
// -- constructors, destructors, and assignment operators -------------------
// -- constructors, destructors, and assignment operators -------------------
task_queue
(
policy_type
p
)
:
old_last_
(
nullptr
),
policy_
(
std
::
move
(
p
))
{
task_queue
(
policy_type
p
)
:
old_last_
(
nullptr
),
policy_
(
std
::
move
(
p
))
{
...
@@ -124,6 +126,13 @@ public:
...
@@ -124,6 +126,13 @@ public:
return
ptr
!=
&
tail_
?
promote
(
ptr
)
:
nullptr
;
return
ptr
!=
&
tail_
?
promote
(
ptr
)
:
nullptr
;
}
}
/// Applies `f` to each element in the queue.
template
<
class
F
>
void
peek_all
(
F
f
)
const
{
for
(
auto
i
=
begin
();
i
!=
end
();
++
i
)
f
(
*
promote
(
i
.
ptr
));
}
// -- modifiers -------------------------------------------------------------
// -- modifiers -------------------------------------------------------------
/// Removes all elements from the queue.
/// Removes all elements from the queue.
...
@@ -165,21 +174,48 @@ public:
...
@@ -165,21 +174,48 @@ public:
inc_total_task_size
(
policy_
.
task_size
(
x
));
inc_total_task_size
(
policy_
.
task_size
(
x
));
}
}
// -- iterator access --------------------------------------------------------
/// Returns an iterator to the dummy before the first element.
/// Returns an iterator to the dummy before the first element.
iterator
before_begin
()
noexcept
{
iterator
before_begin
()
noexcept
{
return
&
head_
;
return
&
head_
;
}
}
/// Returns an iterator to the dummy before the first element.
const_iterator
before_begin
()
const
noexcept
{
return
&
head_
;
}
/// Returns an iterator to the dummy before the first element.
/// Returns an iterator to the dummy before the first element.
iterator
begin
()
noexcept
{
iterator
begin
()
noexcept
{
return
head_
.
next
;
return
head_
.
next
;
}
}
/// Returns an iterator to the dummy before the first element.
const_iterator
begin
()
const
noexcept
{
return
head_
.
next
;
}
/// Returns an iterator to the dummy before the first element.
const_iterator
cbegin
()
const
noexcept
{
return
head_
.
next
;
}
/// Returns a pointer to the dummy past the last element.
/// Returns a pointer to the dummy past the last element.
iterator
end
()
noexcept
{
iterator
end
()
noexcept
{
return
&
tail_
;
return
&
tail_
;
}
}
/// Returns a pointer to the dummy past the last element.
const_iterator
end
()
const
noexcept
{
return
&
tail_
;
}
/// Returns a pointer to the dummy past the last element.
const_iterator
cend
()
const
noexcept
{
return
&
tail_
;
}
/// Returns a pointer to the first element.
/// Returns a pointer to the first element.
pointer
front
()
noexcept
{
pointer
front
()
noexcept
{
return
promote
(
head_
.
next
);
return
promote
(
head_
.
next
);
...
@@ -292,7 +328,6 @@ protected:
...
@@ -292,7 +328,6 @@ protected:
policy_type
policy_
;
policy_type
policy_
;
};
};
}
// namespace intrusive
}
// namespace intrusive
}
// namespace caf
}
// namespace caf
...
...
libcaf_core/test/task_queue.cpp
View file @
acc1fa08
...
@@ -143,6 +143,28 @@ CAF_TEST(peek) {
...
@@ -143,6 +143,28 @@ CAF_TEST(peek) {
CAF_CHECK_EQUAL
(
queue
.
peek
()
->
value
,
1
);
CAF_CHECK_EQUAL
(
queue
.
peek
()
->
value
,
1
);
}
}
CAF_TEST
(
peek_all
)
{
auto
queue_to_string
=
[
&
]
{
std
::
string
str
;
auto
peek_fun
=
[
&
](
const
inode
&
x
)
{
if
(
!
str
.
empty
())
str
+=
", "
;
str
+=
std
::
to_string
(
x
.
value
);
};
queue
.
peek_all
(
peek_fun
);
return
str
;
};
CAF_CHECK_EQUAL
(
queue_to_string
(),
""
);
queue
.
emplace_back
(
1
);
CAF_CHECK_EQUAL
(
queue_to_string
(),
"1"
);
queue
.
emplace_back
(
2
);
CAF_CHECK_EQUAL
(
queue_to_string
(),
"1, 2"
);
queue
.
emplace_back
(
3
);
CAF_CHECK_EQUAL
(
queue_to_string
(),
"1, 2, 3"
);
queue
.
emplace_back
(
4
);
CAF_CHECK_EQUAL
(
queue_to_string
(),
"1, 2, 3, 4"
);
}
CAF_TEST
(
task_size
)
{
CAF_TEST
(
task_size
)
{
fill
(
queue
,
1
,
2
,
3
);
fill
(
queue
,
1
,
2
,
3
);
CAF_CHECK_EQUAL
(
queue
.
total_task_size
(),
6
);
CAF_CHECK_EQUAL
(
queue
.
total_task_size
(),
6
);
...
...
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