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
f8688545
Commit
f8688545
authored
Feb 14, 2019
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add message_queue::drop
parent
9602b7e5
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
5 deletions
+26
-5
libcaf_io/caf/io/basp/message_queue.hpp
libcaf_io/caf/io/basp/message_queue.hpp
+3
-0
libcaf_io/src/message_queue.cpp
libcaf_io/src/message_queue.cpp
+12
-5
libcaf_io/test/message_queue.cpp
libcaf_io/test/message_queue.cpp
+11
-0
No files found.
libcaf_io/caf/io/basp/message_queue.hpp
View file @
f8688545
...
@@ -69,6 +69,9 @@ public:
...
@@ -69,6 +69,9 @@ public:
void
push
(
execution_unit
*
ctx
,
uint64_t
id
,
strong_actor_ptr
receiver
,
void
push
(
execution_unit
*
ctx
,
uint64_t
id
,
strong_actor_ptr
receiver
,
mailbox_element_ptr
content
);
mailbox_element_ptr
content
);
/// Marks given ID as dropped, effectively skipping it without effect.
void
drop
(
execution_unit
*
ctx
,
uint64_t
id
);
/// Returns the next ascending ID.
/// Returns the next ascending ID.
uint64_t
new_id
();
uint64_t
new_id
();
};
};
...
...
libcaf_io/src/message_queue.cpp
View file @
f8688545
...
@@ -18,6 +18,8 @@
...
@@ -18,6 +18,8 @@
#include "caf/io/basp/message_queue.hpp"
#include "caf/io/basp/message_queue.hpp"
#include <iterator>
namespace
caf
{
namespace
caf
{
namespace
io
{
namespace
io
{
namespace
basp
{
namespace
basp
{
...
@@ -29,7 +31,6 @@ message_queue::message_queue() : next_id(0), next_undelivered(0) {
...
@@ -29,7 +31,6 @@ message_queue::message_queue() : next_id(0), next_undelivered(0) {
void
message_queue
::
push
(
execution_unit
*
ctx
,
uint64_t
id
,
void
message_queue
::
push
(
execution_unit
*
ctx
,
uint64_t
id
,
strong_actor_ptr
receiver
,
strong_actor_ptr
receiver
,
mailbox_element_ptr
content
)
{
mailbox_element_ptr
content
)
{
CAF_ASSERT
(
receiver
!=
nullptr
);
std
::
unique_lock
<
std
::
mutex
>
guard
{
lock
};
std
::
unique_lock
<
std
::
mutex
>
guard
{
lock
};
CAF_ASSERT
(
id
>=
next_undelivered
);
CAF_ASSERT
(
id
>=
next_undelivered
);
CAF_ASSERT
(
id
<
next_id
);
CAF_ASSERT
(
id
<
next_id
);
...
@@ -37,6 +38,7 @@ void message_queue::push(execution_unit* ctx, uint64_t id,
...
@@ -37,6 +38,7 @@ void message_queue::push(execution_unit* ctx, uint64_t id,
auto
last
=
pending
.
end
();
auto
last
=
pending
.
end
();
if
(
id
==
next_undelivered
)
{
if
(
id
==
next_undelivered
)
{
// Dispatch current head.
// Dispatch current head.
if
(
receiver
!=
nullptr
)
receiver
->
enqueue
(
std
::
move
(
content
),
ctx
);
receiver
->
enqueue
(
std
::
move
(
content
),
ctx
);
// Check whether we can deliver more.
// Check whether we can deliver more.
if
(
first
==
last
||
first
->
id
!=
next_undelivered
+
1
)
{
if
(
first
==
last
||
first
->
id
!=
next_undelivered
+
1
)
{
...
@@ -52,6 +54,7 @@ void message_queue::push(execution_unit* ctx, uint64_t id,
...
@@ -52,6 +54,7 @@ void message_queue::push(execution_unit* ctx, uint64_t id,
CAF_ASSERT
(
last_hit
!=
first
);
CAF_ASSERT
(
last_hit
!=
first
);
auto
new_last
=
last_hit
==
last
?
last
:
last_hit
+
1
;
auto
new_last
=
last_hit
==
last
?
last
:
last_hit
+
1
;
for
(
auto
i
=
first
;
i
!=
new_last
;
++
i
)
for
(
auto
i
=
first
;
i
!=
new_last
;
++
i
)
if
(
i
->
receiver
!=
nullptr
)
i
->
receiver
->
enqueue
(
std
::
move
(
i
->
content
),
ctx
);
i
->
receiver
->
enqueue
(
std
::
move
(
i
->
content
),
ctx
);
next_undelivered
+=
static_cast
<
size_t
>
(
std
::
distance
(
first
,
new_last
))
+
1
;
next_undelivered
+=
static_cast
<
size_t
>
(
std
::
distance
(
first
,
new_last
))
+
1
;
pending
.
erase
(
first
,
new_last
);
pending
.
erase
(
first
,
new_last
);
...
@@ -62,8 +65,12 @@ void message_queue::push(execution_unit* ctx, uint64_t id,
...
@@ -62,8 +65,12 @@ void message_queue::push(execution_unit* ctx, uint64_t id,
auto
pred
=
[
&
](
const
actor_msg
&
x
)
{
auto
pred
=
[
&
](
const
actor_msg
&
x
)
{
return
x
.
id
>=
id
;
return
x
.
id
>=
id
;
};
};
auto
i
=
std
::
find_if
(
first
,
last
,
pred
);
pending
.
emplace
(
std
::
find_if
(
first
,
last
,
pred
),
pending
.
emplace
(
i
,
actor_msg
{
id
,
std
::
move
(
receiver
),
std
::
move
(
content
)});
actor_msg
{
id
,
std
::
move
(
receiver
),
std
::
move
(
content
)});
}
void
message_queue
::
drop
(
execution_unit
*
ctx
,
uint64_t
id
)
{
push
(
ctx
,
id
,
nullptr
,
nullptr
);
}
}
uint64_t
message_queue
::
new_id
()
{
uint64_t
message_queue
::
new_id
()
{
...
...
libcaf_io/test/message_queue.cpp
View file @
f8688545
...
@@ -145,4 +145,15 @@ CAF_TEST(push order 2-1-0) {
...
@@ -145,4 +145,15 @@ CAF_TEST(push order 2-1-0) {
expect
((
ok_atom
,
int
),
from
(
self
).
to
(
testee
).
with
(
_
,
2
));
expect
((
ok_atom
,
int
),
from
(
self
).
to
(
testee
).
with
(
_
,
2
));
}
}
CAF_TEST
(
dropping
)
{
acquire_ids
(
3
);
push
(
2
);
disallow
((
ok_atom
,
int
),
from
(
self
).
to
(
testee
));
queue
.
drop
(
nullptr
,
1
);
disallow
((
ok_atom
,
int
),
from
(
self
).
to
(
testee
));
push
(
0
);
expect
((
ok_atom
,
int
),
from
(
self
).
to
(
testee
).
with
(
_
,
0
));
expect
((
ok_atom
,
int
),
from
(
self
).
to
(
testee
).
with
(
_
,
2
));
}
CAF_TEST_FIXTURE_SCOPE_END
()
CAF_TEST_FIXTURE_SCOPE_END
()
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