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
0c774e3e
Commit
0c774e3e
authored
Oct 14, 2013
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added priorities to delayed / timed messages
parent
31bcfc16
Changes
9
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
101 additions
and
167 deletions
+101
-167
cppa/local_actor.hpp
cppa/local_actor.hpp
+1
-1
cppa/scheduler.hpp
cppa/scheduler.hpp
+10
-19
cppa/send.hpp
cppa/send.hpp
+51
-92
cppa/util/duration.hpp
cppa/util/duration.hpp
+1
-0
manual/StronglyTypedActors.tex
manual/StronglyTypedActors.tex
+1
-1
src/local_actor.cpp
src/local_actor.cpp
+3
-3
src/scheduler.cpp
src/scheduler.cpp
+13
-34
src/send.cpp
src/send.cpp
+20
-17
unit_testing/test_typed_spawn.cpp
unit_testing/test_typed_spawn.cpp
+1
-0
No files found.
cppa/local_actor.hpp
View file @
0c774e3e
...
...
@@ -314,7 +314,7 @@ class local_actor : public extend<actor>::with<memory_cached> {
void
reply_message
(
any_tuple
&&
what
);
void
forward_message
(
const
actor_ptr
&
new_receiver
);
void
forward_message
(
const
actor_ptr
&
new_receiver
,
message_priority
prio
);
inline
const
actor_ptr
&
chained_actor
();
...
...
cppa/scheduler.hpp
View file @
0c774e3e
...
...
@@ -108,35 +108,26 @@ class scheduler {
virtual
attachable
*
register_hidden_context
();
template
<
typename
Duration
,
typename
...
Data
>
void
delayed_send
(
const
channel_ptr
&
to
,
void
delayed_send
(
message_header
hdr
,
const
Duration
&
rel_time
,
any_tuple
data
)
{
auto
tup
=
make_any_tuple
(
atom
(
"SEND"
),
util
::
duration
{
rel_time
},
to
,
std
::
move
(
hdr
)
,
std
::
move
(
data
));
auto
dsh
=
delayed_send_helper
();
dsh
->
enqueue
({
self
,
dsh
},
std
::
move
(
tup
));
delayed_send_helper
()
->
enqueue
(
nullptr
,
std
::
move
(
tup
));
}
template
<
typename
Duration
,
typename
...
Data
>
void
delayed_reply
(
const
actor_ptr
&
to
,
void
delayed_reply
(
message_header
hdr
,
const
Duration
&
rel_time
,
message_id
id
,
any_tuple
data
)
{
CPPA_REQUIRE
(
!
id
.
valid
()
||
id
.
is_response
());
if
(
id
.
valid
())
{
auto
tup
=
make_any_tuple
(
atom
(
"REPLY"
),
util
::
duration
{
rel_time
},
to
,
id
,
std
::
move
(
data
));
auto
dsh
=
delayed_send_helper
();
dsh
->
enqueue
({
self
,
dsh
},
std
::
move
(
tup
));
}
else
{
this
->
delayed_send
(
to
,
rel_time
,
std
::
move
(
data
));
}
CPPA_REQUIRE
(
hdr
.
id
.
valid
()
&&
hdr
.
id
.
is_response
());
auto
tup
=
make_any_tuple
(
atom
(
"SEND"
),
util
::
duration
{
rel_time
},
std
::
move
(
hdr
),
std
::
move
(
data
));
delayed_send_helper
()
->
enqueue
(
nullptr
,
std
::
move
(
tup
));
}
/**
...
...
cppa/send.hpp
View file @
0c774e3e
This diff is collapsed.
Click to expand it.
cppa/util/duration.hpp
View file @
0c774e3e
...
...
@@ -82,6 +82,7 @@ class duration {
"only seconds, milliseconds or microseconds allowed"
);
}
// convert minutes to seconds
template
<
class
Rep
>
constexpr
duration
(
std
::
chrono
::
duration
<
Rep
,
std
::
ratio
<
60
,
1
>
>
d
)
:
unit
(
time_unit
::
seconds
),
count
(
d
.
count
()
*
60
)
{
}
...
...
manual/StronglyTypedActors.tex
View file @
0c774e3e
...
...
@@ -8,7 +8,7 @@ Typed actors use \lstinline^typed_actor_ptr<...>^ instead of \lstinline^actor_pt
For example, an actor responding to two integers with a dobule would use the type
\lstinline
^
typed
_
actor
_
ptr<replies
_
to<int, int>::with<double>>
^
.
All functions for message passing, linking and monitoring are overloaded to accept both types of actors.
As of version 0.8, strongly typed actors cannot be published
(this is a
planned feature for future releases).
As of version 0.8, strongly typed actors cannot be published
and do not support message priorities (those are
planned feature for future releases).
\subsection
{
Spawning Typed Actors
}
\label
{
sec:strong:spawn
}
...
...
src/local_actor.cpp
View file @
0c774e3e
...
...
@@ -158,10 +158,10 @@ void local_actor::reply_message(any_tuple&& what) {
}
}
void
local_actor
::
forward_message
(
const
actor_ptr
&
new_receiver
)
{
if
(
new_receiver
==
nullptr
)
return
;
void
local_actor
::
forward_message
(
const
actor_ptr
&
dest
,
message_priority
p
)
{
if
(
dest
==
nullptr
)
return
;
auto
&
id
=
m_current_node
->
mid
;
new_receiver
->
enqueue
({
last_sender
(),
new_receiver
,
id
},
m_current_node
->
msg
);
dest
->
enqueue
({
last_sender
(),
dest
,
id
,
p
},
m_current_node
->
msg
);
// treat this message as asynchronous message from now on
id
=
message_id
{};
}
...
...
src/scheduler.cpp
View file @
0c774e3e
...
...
@@ -66,17 +66,9 @@ class delayed_msg {
public:
delayed_msg
(
const
channel_ptr
&
arg0
,
const
actor_ptr
&
arg1
,
message_id
,
any_tuple
&&
arg3
)
:
ptr_a
(
arg0
),
from
(
arg1
),
msg
(
move
(
arg3
))
{
}
delayed_msg
(
const
actor_ptr
&
arg0
,
const
actor_ptr
&
arg1
,
message_id
arg2
,
any_tuple
&&
arg3
)
:
ptr_b
(
arg0
),
from
(
arg1
),
id
(
arg2
),
msg
(
move
(
arg3
))
{
}
delayed_msg
(
message_header
&&
arg1
,
any_tuple
&&
arg2
)
:
hdr
(
move
(
arg1
)),
msg
(
move
(
arg2
))
{
}
delayed_msg
(
delayed_msg
&&
)
=
default
;
delayed_msg
(
const
delayed_msg
&
)
=
default
;
...
...
@@ -84,18 +76,13 @@ class delayed_msg {
delayed_msg
&
operator
=
(
const
delayed_msg
&
)
=
default
;
inline
void
eval
()
{
CPPA_REQUIRE
(
ptr_a
||
ptr_b
);
if
(
ptr_a
)
ptr_a
->
enqueue
(
from
,
move
(
msg
));
else
ptr_b
->
enqueue
({
from
,
id
},
move
(
msg
));
hdr
.
deliver
(
std
::
move
(
msg
));
}
private:
channel_ptr
ptr_a
;
actor_ptr
ptr_b
;
actor_ptr
from
;
message_id
id
;
any_tuple
msg
;
message_header
hdr
;
any_tuple
msg
;
};
...
...
@@ -140,16 +127,14 @@ class scheduler_helper {
};
template
<
class
Map
,
class
T
>
template
<
class
Map
>
inline
void
insert_dmsg
(
Map
&
storage
,
const
util
::
duration
&
d
,
const
T
&
to
,
const
actor_ptr
&
sender
,
any_tuple
&&
tup
,
message_id
id
=
message_id
{})
{
const
util
::
duration
&
d
,
message_header
&&
hdr
,
any_tuple
&&
tup
)
{
auto
tout
=
hrc
::
now
();
tout
+=
d
;
delayed_msg
dmsg
{
to
,
sender
,
id
,
move
(
tup
)};
delayed_msg
dmsg
{
move
(
hdr
)
,
move
(
tup
)};
storage
.
insert
(
std
::
make_pair
(
std
::
move
(
tout
),
std
::
move
(
dmsg
)));
}
...
...
@@ -163,15 +148,9 @@ void scheduler_helper::timer_loop(scheduler_helper::ptr_type m_self) {
// message handling rules
auto
mfun
=
(
on
(
atom
(
"SEND"
),
arg_match
)
>>
[
&
](
const
util
::
duration
&
d
,
const
channel_ptr
&
pt
r
,
message_header
&
hd
r
,
any_tuple
&
tup
)
{
insert_dmsg
(
messages
,
d
,
ptr
,
msg_ptr
->
sender
,
move
(
tup
));
},
on
(
atom
(
"REPLY"
),
arg_match
)
>>
[
&
](
const
util
::
duration
&
d
,
const
actor_ptr
&
ptr
,
message_id
id
,
any_tuple
&
tup
)
{
insert_dmsg
(
messages
,
d
,
ptr
,
msg_ptr
->
sender
,
move
(
tup
),
id
);
insert_dmsg
(
messages
,
d
,
move
(
hdr
),
move
(
tup
));
},
on
(
atom
(
"DIE"
))
>>
[
&
]
{
done
=
true
;
...
...
src/send.cpp
View file @
0c774e3e
...
...
@@ -34,10 +34,10 @@
namespace
cppa
{
message_future
sync_send_tuple
(
actor_
ptr
whom
,
any_tuple
what
)
{
if
(
!
whom
)
throw
std
::
invalid_argument
(
"whom == nullptr"
);
message_future
sync_send_tuple
(
actor_
destination
dest
,
any_tuple
what
)
{
if
(
!
dest
.
receiver
)
throw
std
::
invalid_argument
(
"whom == nullptr"
);
auto
req
=
self
->
new_request_id
();
message_header
hdr
{
self
,
std
::
move
(
whom
),
req
};
message_header
hdr
{
self
,
std
::
move
(
dest
.
receiver
),
req
,
dest
.
priority
};
if
(
self
->
chaining_enabled
())
{
if
(
hdr
.
receiver
->
chained_enqueue
(
hdr
,
std
::
move
(
what
)))
{
self
->
chained_actor
(
hdr
.
receiver
.
downcast
<
actor
>
());
...
...
@@ -47,27 +47,30 @@ message_future sync_send_tuple(actor_ptr whom, any_tuple what) {
return
req
.
response_id
();
}
void
delayed_send_tuple
(
c
onst
channel_ptr
&
to
,
const
util
::
duration
&
r
el_
time
,
void
delayed_send_tuple
(
c
hannel_destination
dest
,
const
util
::
duration
&
rtime
,
any_tuple
data
)
{
if
(
to
)
get_scheduler
()
->
delayed_send
(
to
,
rel_time
,
std
::
move
(
data
));
if
(
dest
.
receiver
)
{
message_header
hdr
{
self
,
std
::
move
(
dest
.
receiver
),
dest
.
priority
};
get_scheduler
()
->
delayed_send
(
std
::
move
(
hdr
),
rtime
,
std
::
move
(
data
));
}
}
void
delayed_reply_tuple
(
const
util
::
duration
&
rel_time
,
actor_ptr
whom
,
message_id
mid
,
any_tuple
data
)
{
if
(
whom
)
get_scheduler
()
->
delayed_reply
(
whom
,
rel_time
,
mid
,
std
::
move
(
data
))
;
message_future
timed_sync_send_tuple
(
actor_destination
dest
,
const
util
::
duration
&
rtime
,
any_tuple
what
)
{
auto
mf
=
sync_send_tuple
(
std
::
move
(
dest
),
std
::
move
(
what
));
message_header
hdr
{
self
,
self
,
mf
.
id
()};
auto
tmp
=
make_any_tuple
(
atom
(
"TIMEOUT"
));
get_scheduler
()
->
delayed_send
(
std
::
move
(
hdr
),
rtime
,
std
::
move
(
tmp
));
return
mf
;
}
void
delayed_reply_tuple
(
const
util
::
duration
&
rel_time
,
void
delayed_reply_tuple
(
const
util
::
duration
&
rtime
,
message_id
mid
,
any_tuple
data
)
{
delayed_reply_tuple
(
rel_time
,
self
->
last_sender
(),
mid
,
std
::
move
(
data
));
message_header
hdr
{
self
,
self
->
last_sender
(),
mid
};
get_scheduler
()
->
delayed_send
(
std
::
move
(
hdr
),
rtime
,
std
::
move
(
data
));
}
void
delayed_reply_tuple
(
const
util
::
duration
&
rel_time
,
any_tuple
data
)
{
...
...
unit_testing/test_typed_spawn.cpp
View file @
0c774e3e
...
...
@@ -66,6 +66,7 @@ class typed_testee : public typed_actor<replies_to<my_request>::with<bool>> {
int
main
()
{
CPPA_TEST
(
test_typed_spawn
);
announce
<
my_request
>
(
&
my_request
::
a
,
&
my_request
::
b
);
auto
sptr
=
spawn_typed_server
();
sync_send
(
sptr
,
my_request
{
2
,
2
}).
await
(
...
...
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