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
0f8c067e
Commit
0f8c067e
authored
Jun 29, 2012
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
maintenance & documentation
parent
b0fb47b1
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
217 additions
and
254 deletions
+217
-254
cppa/cppa.hpp
cppa/cppa.hpp
+132
-223
cppa/scheduler.hpp
cppa/scheduler.hpp
+75
-21
cppa/self.hpp
cppa/self.hpp
+2
-1
src/local_actor.cpp
src/local_actor.cpp
+6
-7
src/scheduler.cpp
src/scheduler.cpp
+2
-2
No files found.
cppa/cppa.hpp
View file @
0f8c067e
This diff is collapsed.
Click to expand it.
cppa/scheduler.hpp
View file @
0f8c067e
...
...
@@ -55,6 +55,20 @@ class scheduler_helper;
typedef
std
::
function
<
void
()
>
void_function
;
typedef
std
::
function
<
void
(
local_actor
*
)
>
init_callback
;
namespace
detail
{
// forwards self_type as actor_ptr, otherwise equal to std::forward
template
<
typename
T
>
struct
spawn_fwd_
{
static
inline
T
&&
_
(
T
&&
arg
)
{
return
std
::
move
(
arg
);
}
static
inline
T
&
_
(
T
&
arg
)
{
return
arg
;
}
static
inline
const
T
&
_
(
const
T
&
arg
)
{
return
arg
;
}
};
template
<
>
struct
spawn_fwd_
<
self_type
>
{
static
inline
actor_ptr
_
(
const
self_type
&
s
)
{
return
s
.
get
();
}
};
}
// namespace detail
/**
* @brief
*/
...
...
@@ -84,6 +98,31 @@ class scheduler {
virtual
void
enqueue
(
scheduled_actor
*
)
=
0
;
/**
* @brief Informs the scheduler about a converted context
* (a thread that acts as actor).
* @note Calls <tt>what->attach(...)</tt>.
*/
virtual
void
register_converted_context
(
local_actor
*
what
);
/**
* @brief Informs the scheduler about a hidden (non-actor)
* context that should be counted by await_others_done().
* @returns An {@link attachable} that the hidden context has to destroy
* if his lifetime ends.
*/
virtual
attachable
*
register_hidden_context
();
template
<
typename
Duration
,
typename
...
Data
>
void
delayed_send
(
const
channel_ptr
&
to
,
const
Duration
&
rel_time
,
Data
&&
...
data
)
{
static_assert
(
sizeof
...(
Data
)
>
0
,
"no message to send"
);
auto
sub
=
make_any_tuple
(
std
::
forward
<
Data
>
(
data
)...);
auto
tup
=
make_any_tuple
(
util
::
duration
{
rel_time
},
to
,
std
::
move
(
sub
));
delayed_send_helper
()
->
enqueue
(
self
,
std
::
move
(
tup
));
}
/**
* @brief Spawns a new actor that executes <code>fun()</code>
* with the scheduling policy @p hint if possible.
...
...
@@ -112,31 +151,46 @@ class scheduler {
*/
virtual
actor_ptr
spawn
(
scheduled_actor
*
what
,
init_callback
init_cb
)
=
0
;
/**
* @brief Informs the scheduler about a converted context
* (a thread that acts as actor).
* @note Calls <tt>what->attach(...)</tt>.
*/
virtual
void
register_converted_context
(
local_actor
*
what
);
// hide implementation details for documentation
# ifndef CPPA_DOCUMENTATION
template
<
typename
Fun
,
typename
Arg0
,
typename
...
Args
>
actor_ptr
spawn_impl
(
scheduling_hint
hint
,
Fun
&&
fun
,
Arg0
&&
arg0
,
Args
&&
...
args
)
{
return
this
->
spawn
(
std
::
bind
(
std
::
forward
<
Fun
>
(
fun
),
detail
::
spawn_fwd_
<
typename
util
::
rm_ref
<
Arg0
>::
type
>::
_
(
arg0
),
detail
::
spawn_fwd_
<
typename
util
::
rm_ref
<
Args
>::
type
>::
_
(
args
)...),
hint
);
}
/**
* @brief Informs the scheduler about a hidden (non-actor)
* context that should be counted by await_others_done().
* @returns An {@link attachable} that the hidden context has to destroy
* if his lifetime ends.
*/
virtual
attachable
*
register_hidden_context
();
template
<
typename
Fun
>
actor_ptr
spawn_impl
(
scheduling_hint
hint
,
Fun
&&
fun
)
{
return
this
->
spawn
(
std
::
forward
<
Fun
>
(
fun
),
hint
);
}
template
<
typename
Duration
,
typename
...
Data
>
void
delayed_send
(
const
actor_ptr
&
to
,
const
Duration
&
rel_time
,
Data
&&
...
data
)
{
static_assert
(
sizeof
...(
Data
)
>
0
,
"no message to send"
);
auto
sub
=
make_any_tuple
(
std
::
forward
<
Data
>
(
data
)...);
auto
tup
=
make_any_tuple
(
util
::
duration
{
rel_time
},
to
,
std
::
move
(
sub
));
delayed_send_helper
()
->
enqueue
(
self
,
std
::
move
(
tup
));
template
<
typename
InitCallback
,
typename
Fun
,
typename
Arg0
,
typename
...
Args
>
actor_ptr
spawn_cb_impl
(
scheduling_hint
hint
,
InitCallback
&&
init_cb
,
Fun
&&
fun
,
Arg0
&&
arg0
,
Args
&&
...
args
)
{
return
this
->
spawn
(
std
::
bind
(
std
::
forward
<
Fun
>
(
fun
),
detail
::
spawn_fwd_
<
typename
util
::
rm_ref
<
Arg0
>::
type
>::
_
(
arg0
),
detail
::
spawn_fwd_
<
typename
util
::
rm_ref
<
Args
>::
type
>::
_
(
args
)...),
hint
,
std
::
forward
<
InitCallback
>
(
init_cb
));
}
template
<
typename
InitCallback
,
typename
Fun
>
actor_ptr
spawn_cb_impl
(
scheduling_hint
hint
,
InitCallback
&&
init_cb
,
Fun
&&
fun
)
{
return
this
->
spawn
(
std
::
forward
<
Fun
>
(
fun
),
hint
,
std
::
forward
<
InitCallback
>
(
init_cb
));
}
# endif // CPPA_DOCUMENTATION
};
/**
...
...
cppa/self.hpp
View file @
0f8c067e
...
...
@@ -49,7 +49,8 @@ extern local_actor* self;
class
local_actor
;
// convertible<...> enables "actor_ptr this_actor = self;"
class
self_type
:
public
convertible
<
self_type
,
actor
*>
{
class
self_type
:
public
convertible
<
self_type
,
actor
*>
,
public
convertible
<
self_type
,
channel
*>
{
self_type
(
const
self_type
&
)
=
delete
;
self_type
&
operator
=
(
const
self_type
&
)
=
delete
;
...
...
src/local_actor.cpp
View file @
0f8c067e
...
...
@@ -68,8 +68,7 @@ class down_observer : public attachable {
}
// namespace <anonymous>
local_actor
::
local_actor
(
bool
sflag
)
:
m_chaining
(
sflag
),
m_trap_exit
(
false
),
m_is_scheduled
(
sflag
)
{
}
:
m_chaining
(
sflag
),
m_trap_exit
(
false
),
m_is_scheduled
(
sflag
)
{
}
void
local_actor
::
monitor
(
actor_ptr
whom
)
{
if
(
whom
)
whom
->
attach
(
new
down_observer
(
this
,
whom
));
...
...
@@ -85,14 +84,14 @@ void local_actor::on_exit() { }
void
local_actor
::
init
()
{
}
void
local_actor
::
join
(
const
group_ptr
&
what
)
{
if
(
!
what
)
return
;
attach
(
what
->
subscribe
(
this
));
if
(
what
)
attach
(
what
->
subscribe
(
this
));
}
void
local_actor
::
leave
(
const
group_ptr
&
what
)
{
if
(
!
what
)
return
;
attachable
::
token
group_token
(
typeid
(
group
::
unsubscriber
),
what
.
get
());
detach
(
group_token
);
if
(
what
)
{
attachable
::
token
group_token
(
typeid
(
group
::
unsubscriber
),
what
.
get
());
detach
(
group_token
);
}
}
}
// namespace cppa
src/scheduler.cpp
View file @
0f8c067e
...
...
@@ -108,8 +108,8 @@ void scheduler_helper::time_emitter(scheduler_helper::ptr_type m_self) {
bool
done
=
false
;
// message handling rules
auto
mfun
=
(
on
<
util
::
duration
,
actor
_ptr
,
anything
>
()
>>
[
&
](
const
util
::
duration
&
d
,
const
actor
_ptr
&
)
{
on
<
util
::
duration
,
channel
_ptr
,
anything
>
()
>>
[
&
](
const
util
::
duration
&
d
,
const
channel
_ptr
&
)
{
// calculate timeout
auto
timeout
=
now
();
timeout
+=
d
;
...
...
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