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
f5aa0825
Commit
f5aa0825
authored
May 29, 2015
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #308 from ufownl/topic/spawn_in_multiple_groups
spawn_in_group variant that allows for multiple groups
parents
d6fc83de
920deb05
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
91 additions
and
14 deletions
+91
-14
libcaf_core/caf/local_actor.hpp
libcaf_core/caf/local_actor.hpp
+36
-5
libcaf_core/caf/spawn.hpp
libcaf_core/caf/spawn.hpp
+45
-5
libcaf_core/caf/spawn_fwd.hpp
libcaf_core/caf/spawn_fwd.hpp
+10
-4
No files found.
libcaf_core/caf/local_actor.hpp
View file @
f5aa0825
...
@@ -92,22 +92,53 @@ class local_actor : public abstract_actor, public resumable {
...
@@ -92,22 +92,53 @@ class local_actor : public abstract_actor, public resumable {
return
eval_opts
(
Os
,
std
::
move
(
res
));
return
eval_opts
(
Os
,
std
::
move
(
res
));
}
}
template
<
class
T
,
spawn_options
Os
,
class
...
Ts
>
template
<
class
T
,
spawn_options
Os
=
no_spawn_options
,
class
Groups
,
actor
spawn_in_group
(
const
group
&
grp
,
Ts
&&
...
xs
)
{
class
...
Ts
>
actor
spawn_in_groups
(
const
Groups
&
grps
,
Ts
&&
...
xs
)
{
constexpr
auto
os
=
make_unbound
(
Os
);
constexpr
auto
os
=
make_unbound
(
Os
);
auto
res
=
spawn_class
<
T
,
os
>
(
host
(),
group_subscriber
{
grp
},
auto
res
=
spawn_class
<
T
,
os
>
(
host
(),
groups_subscriber
<
decltype
(
std
::
begin
(
grps
))
>
{
std
::
begin
(
grps
),
std
::
end
(
grps
)},
std
::
forward
<
Ts
>
(
xs
)...);
std
::
forward
<
Ts
>
(
xs
)...);
return
eval_opts
(
Os
,
std
::
move
(
res
));
return
eval_opts
(
Os
,
std
::
move
(
res
));
}
}
template
<
spawn_options
Os
=
no_spawn_options
,
class
...
Ts
>
template
<
class
T
,
spawn_options
Os
=
no_spawn_options
,
class
...
Ts
>
actor
spawn_in_groups
(
std
::
initializer_list
<
group
>
grps
,
Ts
&&
...
xs
)
{
return
spawn_in_groups
<
T
,
Os
,
std
::
initializer_list
<
group
>
>
(
grps
,
std
::
forward
<
Ts
>
(
xs
)...);
}
template
<
class
T
,
spawn_options
Os
=
no_spawn_options
,
class
...
Ts
>
actor
spawn_in_group
(
const
group
&
grp
,
Ts
&&
...
xs
)
{
actor
spawn_in_group
(
const
group
&
grp
,
Ts
&&
...
xs
)
{
return
spawn_in_groups
<
T
,
Os
>
({
grp
},
std
::
forward
<
Ts
>
(
xs
)...);
}
template
<
spawn_options
Os
=
no_spawn_options
,
class
Groups
,
class
...
Ts
>
actor
spawn_in_groups
(
const
Groups
&
grps
,
Ts
&&
...
xs
)
{
constexpr
auto
os
=
make_unbound
(
Os
);
constexpr
auto
os
=
make_unbound
(
Os
);
auto
res
=
spawn_functor
<
os
>
(
host
(),
group_subscriber
{
grp
},
auto
res
=
spawn_functor
<
os
>
(
host
(),
groups_subscriber
<
decltype
(
std
::
begin
(
grps
))
>
{
std
::
begin
(
grps
),
std
::
end
(
grps
)},
std
::
forward
<
Ts
>
(
xs
)...);
std
::
forward
<
Ts
>
(
xs
)...);
return
eval_opts
(
Os
,
std
::
move
(
res
));
return
eval_opts
(
Os
,
std
::
move
(
res
));
}
}
template
<
spawn_options
Os
=
no_spawn_options
,
class
...
Ts
>
actor
spawn_in_groups
(
std
::
initializer_list
<
group
>
grps
,
Ts
&&
...
xs
)
{
return
spawn_in_groups
<
Os
,
std
::
initializer_list
<
group
>
>
(
grps
,
std
::
forward
<
Ts
>
(
xs
)...);
}
template
<
spawn_options
Os
=
no_spawn_options
,
class
...
Ts
>
actor
spawn_in_group
(
const
group
&
grp
,
Ts
&&
...
xs
)
{
return
spawn_in_groups
<
Os
>
({
grp
},
std
::
forward
<
Ts
>
(
xs
)...);
}
/****************************************************************************
/****************************************************************************
* spawn typed actors *
* spawn typed actors *
****************************************************************************/
****************************************************************************/
...
...
libcaf_core/caf/spawn.hpp
View file @
f5aa0825
...
@@ -170,16 +170,58 @@ actor spawn(Ts&&... xs) {
...
@@ -170,16 +170,58 @@ actor spawn(Ts&&... xs) {
std
::
forward
<
Ts
>
(
xs
)...);
std
::
forward
<
Ts
>
(
xs
)...);
}
}
/**
* Returns a new actor that immediately, i.e., before this function
* returns, joins `grps` of type `C` using `xs` as constructor arguments
*/
template
<
class
C
,
spawn_options
Os
=
no_spawn_options
,
class
Groups
,
class
...
Ts
>
actor
spawn_in_groups
(
const
Groups
&
grps
,
Ts
&&
...
xs
)
{
return
spawn_class
<
C
,
Os
>
(
nullptr
,
groups_subscriber
<
decltype
(
std
::
begin
(
grps
))
>
{
std
::
begin
(
grps
),
std
::
end
(
grps
)},
std
::
forward
<
Ts
>
(
xs
)...);
}
template
<
class
C
,
spawn_options
Os
=
no_spawn_options
,
class
...
Ts
>
actor
spawn_in_groups
(
std
::
initializer_list
<
group
>
grps
,
Ts
&&
...
xs
)
{
return
spawn_in_groups
<
C
,
Os
,
std
::
initializer_list
<
group
>
>
(
grps
,
std
::
forward
<
Ts
>
(
xs
)...);
}
/**
/**
* Returns a new actor that immediately, i.e., before this function
* Returns a new actor that immediately, i.e., before this function
* returns, joins `grp` of type `C` using `xs` as constructor arguments
* returns, joins `grp` of type `C` using `xs` as constructor arguments
*/
*/
template
<
class
C
,
spawn_options
Os
=
no_spawn_options
,
class
...
Ts
>
template
<
class
C
,
spawn_options
Os
=
no_spawn_options
,
class
...
Ts
>
actor
spawn_in_group
(
const
group
&
grp
,
Ts
&&
...
xs
)
{
actor
spawn_in_group
(
const
group
&
grp
,
Ts
&&
...
xs
)
{
return
spawn_class
<
C
,
Os
>
(
nullptr
,
group_subscriber
{
grp
},
return
spawn_in_groups
<
C
,
Os
>
({
grp
},
std
::
forward
<
Ts
>
(
xs
)...);
}
/**
* Returns a new actor that immediately, i.e., before this function
* returns, joins `grps`. The first element of `xs` must
* be the functor, the remaining arguments its arguments.
*/
template
<
spawn_options
Os
=
no_spawn_options
,
class
Groups
,
class
...
Ts
>
actor
spawn_in_groups
(
const
Groups
&
grps
,
Ts
&&
...
xs
)
{
static_assert
(
sizeof
...(
Ts
)
>
0
,
"too few arguments provided"
);
return
spawn_functor
<
Os
>
(
nullptr
,
groups_subscriber
<
decltype
(
std
::
begin
(
grps
))
>
{
std
::
begin
(
grps
),
std
::
end
(
grps
)},
std
::
forward
<
Ts
>
(
xs
)...);
std
::
forward
<
Ts
>
(
xs
)...);
}
}
template
<
spawn_options
Os
=
no_spawn_options
,
class
...
Ts
>
actor
spawn_in_groups
(
std
::
initializer_list
<
group
>
grps
,
Ts
&&
...
xs
)
{
return
spawn_in_groups
<
Os
,
std
::
initializer_list
<
group
>
>
(
grps
,
std
::
forward
<
Ts
>
(
xs
)...);
}
/**
/**
* Returns a new actor that immediately, i.e., before this function
* Returns a new actor that immediately, i.e., before this function
* returns, joins `grp`. The first element of `xs` must
* returns, joins `grp`. The first element of `xs` must
...
@@ -187,9 +229,7 @@ actor spawn_in_group(const group& grp, Ts&&... xs) {
...
@@ -187,9 +229,7 @@ actor spawn_in_group(const group& grp, Ts&&... xs) {
*/
*/
template
<
spawn_options
Os
=
no_spawn_options
,
class
...
Ts
>
template
<
spawn_options
Os
=
no_spawn_options
,
class
...
Ts
>
actor
spawn_in_group
(
const
group
&
grp
,
Ts
&&
...
xs
)
{
actor
spawn_in_group
(
const
group
&
grp
,
Ts
&&
...
xs
)
{
static_assert
(
sizeof
...(
Ts
)
>
0
,
"too few arguments provided"
);
return
spawn_in_groups
<
Os
>
({
grp
},
std
::
forward
<
Ts
>
(
xs
)...);
return
spawn_functor
<
Os
>
(
nullptr
,
group_subscriber
{
grp
},
std
::
forward
<
Ts
>
(
xs
)...);
}
}
/**
/**
...
...
libcaf_core/caf/spawn_fwd.hpp
View file @
f5aa0825
...
@@ -48,19 +48,25 @@ actor spawn_functor(execution_unit* host,
...
@@ -48,19 +48,25 @@ actor spawn_functor(execution_unit* host,
F
fun
,
F
fun
,
Ts
&&
...
xs
);
Ts
&&
...
xs
);
class
group_subscriber
{
template
<
class
InputIt
>
class
groups_subscriber
{
public:
public:
inline
group_subscriber
(
const
group
&
grp
)
:
m_grp
(
grp
)
{
inline
groups_subscriber
(
InputIt
first
,
InputIt
last
)
:
m_first
(
first
),
m_last
(
last
)
{
// nop
// nop
}
}
template
<
class
T
>
template
<
class
T
>
inline
void
operator
()(
T
*
ptr
)
const
{
inline
void
operator
()(
T
*
ptr
)
const
{
ptr
->
join
(
m_grp
);
for
(
auto
i
=
m_first
;
i
!=
m_last
;
++
i
)
{
ptr
->
join
(
*
i
);
}
}
}
private:
private:
group
m_grp
;
InputIt
m_first
;
InputIt
m_last
;
};
};
struct
empty_before_launch_callback
{
struct
empty_before_launch_callback
{
...
...
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