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
4357bdf4
Commit
4357bdf4
authored
Aug 04, 2023
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Integrate review feedback
parent
20476587
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
27 additions
and
15 deletions
+27
-15
libcaf_core/caf/abstract_mailbox.hpp
libcaf_core/caf/abstract_mailbox.hpp
+2
-0
libcaf_core/caf/intrusive/linked_list.hpp
libcaf_core/caf/intrusive/linked_list.hpp
+13
-15
libcaf_core/caf/intrusive/linked_list.test.cpp
libcaf_core/caf/intrusive/linked_list.test.cpp
+11
-0
libcaf_core/caf/intrusive/stack.hpp
libcaf_core/caf/intrusive/stack.hpp
+1
-0
No files found.
libcaf_core/caf/abstract_mailbox.hpp
View file @
4357bdf4
...
@@ -73,6 +73,8 @@ public:
...
@@ -73,6 +73,8 @@ public:
}
}
/// @private
/// @private
/// @note Only used by the legacy test framework. Remove when dropping support
/// for it.
virtual
mailbox_element
*
peek
(
message_id
id
)
=
0
;
virtual
mailbox_element
*
peek
(
message_id
id
)
=
0
;
};
};
...
...
libcaf_core/caf/intrusive/linked_list.hpp
View file @
4357bdf4
...
@@ -65,9 +65,7 @@ public:
...
@@ -65,9 +65,7 @@ public:
linked_list
&
operator
=
(
linked_list
&&
other
)
noexcept
{
linked_list
&
operator
=
(
linked_list
&&
other
)
noexcept
{
clear
();
clear
();
if
(
other
.
empty
())
{
if
(
!
other
.
empty
())
{
init
();
}
else
{
head_
.
next
=
other
.
head_
.
next
;
head_
.
next
=
other
.
head_
.
next
;
tail_
.
next
=
other
.
tail_
.
next
;
tail_
.
next
=
other
.
tail_
.
next
;
tail_
.
next
->
next
=
&
tail_
;
tail_
.
next
->
next
=
&
tail_
;
...
@@ -92,28 +90,28 @@ public:
...
@@ -92,28 +90,28 @@ public:
return
size_
;
return
size_
;
}
}
/// Returns whether the
queue
has no elements.
/// Returns whether the
list
has no elements.
bool
empty
()
const
noexcept
{
bool
empty
()
const
noexcept
{
return
size
()
==
0
;
return
size
()
==
0
;
}
}
// -- modifiers -------------------------------------------------------------
// -- modifiers -------------------------------------------------------------
/// Removes all elements from the
queue
.
/// Removes all elements from the
list
.
void
clear
()
noexcept
{
void
clear
()
noexcept
{
typename
unique_pointer
::
deleter_type
fn
;
typename
unique_pointer
::
deleter_type
fn
;
drain
(
fn
);
drain
(
fn
);
}
}
/// Removes the first element from the
queue
and returns it.
/// Removes the first element from the
list
and returns it.
unique_pointer
pop_front
()
{
unique_pointer
pop_front
()
{
unique_pointer
result
;
unique_pointer
result
;
if
(
!
empty
())
{
if
(
!
empty
())
{
auto
ptr
=
promote
(
head_
.
next
);
auto
ptr
=
promote
(
head_
.
next
);
head_
.
next
=
ptr
->
next
;
head_
.
next
=
ptr
->
next
;
if
(
--
size_
==
0
)
{
if
(
--
size_
==
0
)
{
CAF_ASSERT
(
head_
.
next
==
&
(
tail_
)
);
CAF_ASSERT
(
head_
.
next
==
&
tail_
);
tail_
.
next
=
&
(
head_
)
;
tail_
.
next
=
&
head_
;
}
}
result
.
reset
(
ptr
);
result
.
reset
(
ptr
);
}
}
...
@@ -158,7 +156,7 @@ public:
...
@@ -158,7 +156,7 @@ public:
}
}
/// Returns an iterator to the last element or to the dummy before the first
/// Returns an iterator to the last element or to the dummy before the first
/// element if the
queue
is empty.
/// element if the
list
is empty.
iterator
before_end
()
noexcept
{
iterator
before_end
()
noexcept
{
return
tail_
.
next
;
return
tail_
.
next
;
}
}
...
@@ -176,14 +174,14 @@ public:
...
@@ -176,14 +174,14 @@ public:
return
promote
(
tail_
.
next
);
return
promote
(
tail_
.
next
);
}
}
/// Like `front`, but returns `nullptr` if the
queue
is empty.
/// Like `front`, but returns `nullptr` if the
list
is empty.
pointer
peek
()
noexcept
{
pointer
peek
()
noexcept
{
return
size_
>
0
?
front
()
:
nullptr
;
return
size_
>
0
?
front
()
:
nullptr
;
}
}
// -- insertion --------------------------------------------------------------
// -- insertion --------------------------------------------------------------
/// Appends `ptr` to the
queue
.
/// Appends `ptr` to the
list
.
/// @pre `ptr != nullptr`
/// @pre `ptr != nullptr`
void
push_back
(
pointer
ptr
)
noexcept
{
void
push_back
(
pointer
ptr
)
noexcept
{
CAF_ASSERT
(
ptr
!=
nullptr
);
CAF_ASSERT
(
ptr
!=
nullptr
);
...
@@ -193,7 +191,7 @@ public:
...
@@ -193,7 +191,7 @@ public:
++
size_
;
++
size_
;
}
}
/// Appends `ptr` to the
queue
.
/// Appends `ptr` to the
list
.
/// @pre `ptr != nullptr`
/// @pre `ptr != nullptr`
void
push_back
(
unique_pointer
ptr
)
noexcept
{
void
push_back
(
unique_pointer
ptr
)
noexcept
{
push_back
(
ptr
.
release
());
push_back
(
ptr
.
release
());
...
@@ -241,7 +239,7 @@ public:
...
@@ -241,7 +239,7 @@ public:
// -- algorithms -------------------------------------------------------------
// -- algorithms -------------------------------------------------------------
/// Tries to find an element in the
queue
that matches the given predicate.
/// Tries to find an element in the
list
that matches the given predicate.
template
<
class
Predicate
>
template
<
class
Predicate
>
pointer
find_if
(
Predicate
pred
)
{
pointer
find_if
(
Predicate
pred
)
{
for
(
auto
i
=
begin
();
i
!=
end
();
++
i
)
for
(
auto
i
=
begin
();
i
!=
end
();
++
i
)
...
@@ -275,10 +273,10 @@ private:
...
@@ -275,10 +273,10 @@ private:
node_type
head_
;
node_type
head_
;
/// Dummy past-the-last-element node. The `tail_->next` pointer is pointing to
/// Dummy past-the-last-element node. The `tail_->next` pointer is pointing to
/// the last element in the
queue or to `head_` if the queue
is empty.
/// the last element in the
list or to `head_` if the list
is empty.
node_type
tail_
;
node_type
tail_
;
/// Stores the total size of all items in the
queue
.
/// Stores the total size of all items in the
list
.
size_t
size_
=
0
;
size_t
size_
=
0
;
};
};
...
...
libcaf_core/caf/intrusive/linked_list.test.cpp
View file @
4357bdf4
...
@@ -143,4 +143,15 @@ TEST("lists allow iterator-based access") {
...
@@ -143,4 +143,15 @@ TEST("lists allow iterator-based access") {
12
);
12
);
}
}
TEST
(
"pop_front removes the oldest element of a list and returns it"
)
{
list_type
uut
;
fill
(
uut
,
1
,
2
,
3
);
check_eq
(
uut
.
pop_front
()
->
value
,
1
);
if
(
check_eq
(
uut
.
size
(),
2u
))
check_eq
(
uut
.
pop_front
()
->
value
,
1
);
if
(
check_eq
(
uut
.
size
(),
1u
))
check_eq
(
uut
.
pop_front
()
->
value
,
1
);
check
(
uut
.
empty
());
}
CAF_TEST_MAIN
()
CAF_TEST_MAIN
()
libcaf_core/caf/intrusive/stack.hpp
View file @
4357bdf4
...
@@ -6,6 +6,7 @@
...
@@ -6,6 +6,7 @@
namespace
caf
::
intrusive
{
namespace
caf
::
intrusive
{
/// A simple stack implementation with singly-linked nodes.
template
<
class
T
>
template
<
class
T
>
class
stack
{
class
stack
{
public:
public:
...
...
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