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
8021cd02
Commit
8021cd02
authored
Mar 14, 2011
by
neverlord
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed on()
parent
19af9398
Changes
17
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
209 additions
and
134 deletions
+209
-134
cppa.files
cppa.files
+3
-0
cppa/actor.hpp
cppa/actor.hpp
+4
-2
cppa/detail/actor_private.hpp
cppa/detail/actor_private.hpp
+5
-0
cppa/intrusive_ptr.hpp
cppa/intrusive_ptr.hpp
+26
-11
cppa/match.hpp
cppa/match.hpp
+3
-1
cppa/message_receiver.hpp
cppa/message_receiver.hpp
+2
-0
cppa/on.hpp
cppa/on.hpp
+15
-5
cppa/util.hpp
cppa/util.hpp
+2
-0
cppa/util/compare_tuples.hpp
cppa/util/compare_tuples.hpp
+43
-0
cppa/util/eval_type_lists.hpp
cppa/util/eval_type_lists.hpp
+1
-1
libcppa.Makefile
libcppa.Makefile
+1
-0
src/actor.cpp
src/actor.cpp
+21
-0
src/message_receiver.cpp
src/message_receiver.cpp
+4
-0
src/mock_scheduler.cpp
src/mock_scheduler.cpp
+2
-1
unit_testing/test__a_matches_b.cpp
unit_testing/test__a_matches_b.cpp
+6
-2
unit_testing/test__local_group.cpp
unit_testing/test__local_group.cpp
+59
-111
unit_testing/test__tuple.cpp
unit_testing/test__tuple.cpp
+12
-0
No files found.
cppa.files
View file @
8021cd02
...
@@ -93,3 +93,6 @@ cppa/detail/channel.hpp
...
@@ -93,3 +93,6 @@ cppa/detail/channel.hpp
cppa/message_receiver.hpp
cppa/message_receiver.hpp
src/message_receiver.cpp
src/message_receiver.cpp
src/actor.cpp
src/actor.cpp
src/actor_private.cpp
cppa/util/eval_first_n.hpp
cppa/util/first_n.hpp
cppa/actor.hpp
View file @
8021cd02
...
@@ -15,11 +15,13 @@ class actor : public message_receiver
...
@@ -15,11 +15,13 @@ class actor : public message_receiver
public:
public:
typedef
cppa
::
intrusive_ptr
<
detail
::
actor_p
ublic
>
ptr_type
;
typedef
cppa
::
intrusive_ptr
<
detail
::
actor_p
rivate
>
ptr_type
;
actor
()
=
default
;
actor
()
=
default
;
inline
actor
(
detail
::
actor_public
*
ptr
)
:
super
(
ptr
)
{
}
~
actor
();
inline
actor
(
detail
::
actor_private
*
ptr
)
:
super
(
ptr
)
{
}
inline
actor
(
const
ptr_type
&
ptr
)
:
super
(
ptr
)
{
}
inline
actor
(
const
ptr_type
&
ptr
)
:
super
(
ptr
)
{
}
...
...
cppa/detail/actor_private.hpp
View file @
8021cd02
#ifndef ACTOR_PRIVATE_HPP
#ifndef ACTOR_PRIVATE_HPP
#define ACTOR_PRIVATE_HPP
#define ACTOR_PRIVATE_HPP
#include <boost/thread/thread.hpp>
#include "cppa/invoke_rules.hpp"
#include "cppa/invoke_rules.hpp"
#include "cppa/untyped_tuple.hpp"
#include "cppa/untyped_tuple.hpp"
...
@@ -14,6 +16,9 @@ namespace cppa { namespace detail {
...
@@ -14,6 +16,9 @@ namespace cppa { namespace detail {
// private part of the actor interface (callable only from this_actor())
// private part of the actor interface (callable only from this_actor())
struct
actor_private
:
public
actor_public
struct
actor_private
:
public
actor_public
{
{
boost
::
thread
*
m_thread
;
inline
actor_private
()
:
m_thread
(
0
)
{
}
virtual
~
actor_private
();
virtual
const
message
&
receive
()
=
0
;
virtual
const
message
&
receive
()
=
0
;
virtual
const
message
&
last_dequeued
()
const
=
0
;
virtual
const
message
&
last_dequeued
()
const
=
0
;
virtual
void
receive
(
invoke_rules
&
)
=
0
;
virtual
void
receive
(
invoke_rules
&
)
=
0
;
...
...
cppa/intrusive_ptr.hpp
View file @
8021cd02
...
@@ -26,24 +26,32 @@ class intrusive_ptr : detail::comparable<intrusive_ptr<T>, T*>,
...
@@ -26,24 +26,32 @@ class intrusive_ptr : detail::comparable<intrusive_ptr<T>, T*>,
intrusive_ptr
()
:
m_ptr
(
0
)
{
}
intrusive_ptr
()
:
m_ptr
(
0
)
{
}
template
<
typename
Y
>
intrusive_ptr
(
Y
*
raw_ptr
)
{
set_ptr
(
raw_ptr
);
}
intrusive_ptr
(
T
*
raw_ptr
)
{
set_ptr
(
raw_ptr
);
}
intrusive_ptr
(
T
*
raw_ptr
)
{
set_ptr
(
raw_ptr
);
}
intrusive_ptr
(
intrusive_ptr
&&
other
)
:
m_ptr
(
other
.
m_pt
r
)
intrusive_ptr
(
const
intrusive_ptr
&
othe
r
)
{
{
other
.
m_ptr
=
0
;
set_ptr
(
other
.
m_ptr
)
;
}
}
intrusive_ptr
(
const
intrusive_ptr
&
other
)
{
set_ptr
(
other
.
m_ptr
);
}
intrusive_ptr
(
intrusive_ptr
&&
other
)
:
m_ptr
(
0
)
{
swap
(
other
);
}
template
<
typename
Y
>
template
<
typename
Y
>
intrusive_ptr
(
const
intrusive_ptr
<
Y
>&
other
)
intrusive_ptr
(
const
intrusive_ptr
<
Y
>&
other
)
{
{
static_assert
(
std
::
is_convertible
<
Y
*
,
T
*>::
value
,
"Y* is not assignable to T*"
);
set_ptr
(
const_cast
<
Y
*>
(
other
.
get
()));
set_ptr
(
const_cast
<
Y
*>
(
other
.
get
()));
}
}
template
<
typename
Y
>
intrusive_ptr
(
intrusive_ptr
<
Y
>&&
other
)
:
m_ptr
(
0
)
{
swap
(
other
);
}
~
intrusive_ptr
()
~
intrusive_ptr
()
{
{
if
(
m_ptr
&&
!
m_ptr
->
deref
())
if
(
m_ptr
&&
!
m_ptr
->
deref
())
...
@@ -77,11 +85,8 @@ class intrusive_ptr : detail::comparable<intrusive_ptr<T>, T*>,
...
@@ -77,11 +85,8 @@ class intrusive_ptr : detail::comparable<intrusive_ptr<T>, T*>,
intrusive_ptr
&
operator
=
(
const
intrusive_ptr
&
other
)
intrusive_ptr
&
operator
=
(
const
intrusive_ptr
&
other
)
{
{
if
(
get
()
!=
other
.
get
())
intrusive_ptr
tmp
(
other
);
{
swap
(
tmp
);
intrusive_ptr
tmp
(
other
);
swap
(
tmp
);
}
return
*
this
;
return
*
this
;
}
}
...
@@ -100,6 +105,16 @@ class intrusive_ptr : detail::comparable<intrusive_ptr<T>, T*>,
...
@@ -100,6 +105,16 @@ class intrusive_ptr : detail::comparable<intrusive_ptr<T>, T*>,
return
*
this
;
return
*
this
;
}
}
template
<
typename
Y
>
intrusive_ptr
&
operator
=
(
intrusive_ptr
<
Y
>&&
other
)
{
static_assert
(
std
::
is_convertible
<
Y
*
,
T
*>::
value
,
"Y* is not assignable to T*"
);
m_ptr
=
other
.
m_ptr
;
other
.
m_ptr
=
0
;
return
*
this
;
}
T
*
operator
->
()
{
return
m_ptr
;
}
T
*
operator
->
()
{
return
m_ptr
;
}
T
&
operator
*
()
{
return
*
m_ptr
;
}
T
&
operator
*
()
{
return
*
m_ptr
;
}
...
...
cppa/match.hpp
View file @
8021cd02
...
@@ -8,6 +8,7 @@
...
@@ -8,6 +8,7 @@
#include "cppa/tuple_view.hpp"
#include "cppa/tuple_view.hpp"
#include "cppa/untyped_tuple.hpp"
#include "cppa/untyped_tuple.hpp"
#include "cppa/util/compare_tuples.hpp"
#include "cppa/util/type_list.hpp"
#include "cppa/util/type_list.hpp"
#include "cppa/util/is_comparable.hpp"
#include "cppa/util/is_comparable.hpp"
#include "cppa/util/utype_iterator.hpp"
#include "cppa/util/utype_iterator.hpp"
...
@@ -51,7 +52,8 @@ bool match(const untyped_tuple& what, const ValuesTuple& vals,
...
@@ -51,7 +52,8 @@ bool match(const untyped_tuple& what, const ValuesTuple& vals,
{
{
std
::
vector
<
std
::
size_t
>
tmp
(
mappings
);
std
::
vector
<
std
::
size_t
>
tmp
(
mappings
);
view_type
view
(
what
.
vals
(),
std
::
move
(
tmp
));
view_type
view
(
what
.
vals
(),
std
::
move
(
tmp
));
return
view
==
vals
;
return
compare_first_elements
(
view
,
vals
);
// return view == vals;
}
}
return
false
;
return
false
;
}
}
...
...
cppa/message_receiver.hpp
View file @
8021cd02
...
@@ -33,6 +33,8 @@ class message_receiver :
...
@@ -33,6 +33,8 @@ class message_receiver :
{
{
}
}
virtual
~
message_receiver
();
message_receiver
()
=
default
;
message_receiver
()
=
default
;
message_receiver
(
message_receiver
&&
)
=
default
;
message_receiver
(
message_receiver
&&
)
=
default
;
...
...
cppa/on.hpp
View file @
8021cd02
...
@@ -5,6 +5,7 @@
...
@@ -5,6 +5,7 @@
#include "cppa/invoke_rules.hpp"
#include "cppa/invoke_rules.hpp"
#include "cppa/untyped_tuple.hpp"
#include "cppa/untyped_tuple.hpp"
#include "cppa/util/eval_first_n.hpp"
#include "cppa/util/filter_type_list.hpp"
#include "cppa/util/filter_type_list.hpp"
#include "cppa/detail/ref_counted_impl.hpp"
#include "cppa/detail/ref_counted_impl.hpp"
...
@@ -36,6 +37,12 @@ struct invoke_rule_builder
...
@@ -36,6 +37,12 @@ struct invoke_rule_builder
template
<
typename
Arg0
,
typename
...
Args
>
template
<
typename
Arg0
,
typename
...
Args
>
invoke_rule_builder
(
const
Arg0
&
arg0
,
const
Args
&
...
args
)
invoke_rule_builder
(
const
Arg0
&
arg0
,
const
Args
&
...
args
)
{
{
typedef
util
::
type_list
<
Arg0
,
Args
...
>
arg_types
;
static_assert
(
arg_types
::
type_list_size
<=
filtered_types
::
type_list_size
,
"too much arguments"
);
class
helper_impl
:
public
irb_helper
class
helper_impl
:
public
irb_helper
{
{
...
@@ -44,7 +51,9 @@ struct invoke_rule_builder
...
@@ -44,7 +51,9 @@ struct invoke_rule_builder
public:
public:
helper_impl
(
const
Arg0
&
arg0
,
const
Args
&
...
args
)
helper_impl
(
const
Arg0
&
arg0
,
const
Args
&
...
args
)
:
m_values
(
arg0
,
args
...)
{
}
:
m_values
(
arg0
,
args
...)
{
}
virtual
bool
value_cmp
(
const
untyped_tuple
&
t
,
virtual
bool
value_cmp
(
const
untyped_tuple
&
t
,
std
::
vector
<
std
::
size_t
>&
v
)
const
std
::
vector
<
std
::
size_t
>&
v
)
const
...
@@ -56,10 +65,11 @@ struct invoke_rule_builder
...
@@ -56,10 +65,11 @@ struct invoke_rule_builder
m_helper
=
new
helper_impl
(
arg0
,
args
...);
m_helper
=
new
helper_impl
(
arg0
,
args
...);
static_assert
(
util
::
eval_type_lists
<
filtered_types
,
static_assert
(
util
::
eval_first_n
<
arg_types
::
type_list_size
,
util
::
type_list
<
Arg0
,
Args
...
>
,
filtered_types
,
util
::
is_comparable
>::
value
,
arg_types
,
"Wrong argument types"
);
util
::
is_comparable
>::
value
,
"wrong argument types (not comparable)"
);
}
}
typedef
typename
tuple_view_type_from_type_list
<
filtered_types
>::
type
typedef
typename
tuple_view_type_from_type_list
<
filtered_types
>::
type
...
...
cppa/util.hpp
View file @
8021cd02
...
@@ -9,9 +9,11 @@
...
@@ -9,9 +9,11 @@
#include "cppa/util/detach.hpp"
#include "cppa/util/detach.hpp"
#include "cppa/util/disjunction.hpp"
#include "cppa/util/disjunction.hpp"
#include "cppa/util/enable_if.hpp"
#include "cppa/util/enable_if.hpp"
#include "cppa/util/eval_first_n.hpp"
#include "cppa/util/eval_type_list.hpp"
#include "cppa/util/eval_type_list.hpp"
#include "cppa/util/eval_type_lists.hpp"
#include "cppa/util/eval_type_lists.hpp"
#include "cppa/util/filter_type_list.hpp"
#include "cppa/util/filter_type_list.hpp"
#include "cppa/util/first_n.hpp"
#include "cppa/util/has_copy_member_fun.hpp"
#include "cppa/util/has_copy_member_fun.hpp"
#include "cppa/util/is_comparable.hpp"
#include "cppa/util/is_comparable.hpp"
#include "cppa/util/is_copyable.hpp"
#include "cppa/util/is_copyable.hpp"
...
...
cppa/util/compare_tuples.hpp
View file @
8021cd02
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
#include "cppa/get.hpp"
#include "cppa/get.hpp"
#include "cppa/util/type_list.hpp"
#include "cppa/util/type_list.hpp"
#include "cppa/util/eval_first_n.hpp"
#include "cppa/util/is_comparable.hpp"
#include "cppa/util/is_comparable.hpp"
#include "cppa/util/eval_type_lists.hpp"
#include "cppa/util/eval_type_lists.hpp"
...
@@ -34,6 +35,25 @@ struct cmp_helper<0, LhsTuple, RhsTuple>
...
@@ -34,6 +35,25 @@ struct cmp_helper<0, LhsTuple, RhsTuple>
}
}
};
};
template
<
bool
ALessB
,
std
::
size_t
A
,
std
::
size_t
B
>
struct
min_impl
{
static
const
std
::
size_t
value
=
A
;
};
template
<
std
::
size_t
A
,
std
::
size_t
B
>
struct
min_impl
<
false
,
A
,
B
>
{
static
const
std
::
size_t
value
=
B
;
};
template
<
std
::
size_t
A
,
std
::
size_t
B
>
struct
min_
{
static
const
std
::
size_t
value
=
min_impl
<
(
A
<
B
),
A
,
B
>::
value
;
};
}
}
// namespace cppa::detail
}
}
// namespace cppa::detail
namespace
cppa
{
namespace
util
{
namespace
cppa
{
namespace
util
{
...
@@ -55,6 +75,29 @@ bool compare_tuples(const LhsTuple<LhsTypes...>& lhs,
...
@@ -55,6 +75,29 @@ bool compare_tuples(const LhsTuple<LhsTypes...>& lhs,
RhsTuple
<
RhsTypes
...
>>::
cmp
(
lhs
,
rhs
);
RhsTuple
<
RhsTypes
...
>>::
cmp
(
lhs
,
rhs
);
}
}
template
<
template
<
typename
...
>
class
LhsTuple
,
typename
...
LhsTypes
,
template
<
typename
...
>
class
RhsTuple
,
typename
...
RhsTypes
>
bool
compare_first_elements
(
const
LhsTuple
<
LhsTypes
...
>&
lhs
,
const
RhsTuple
<
RhsTypes
...
>&
rhs
)
{
typedef
util
::
type_list
<
LhsTypes
...
>
lhs_types
;
typedef
util
::
type_list
<
RhsTypes
...
>
rhs_types
;
static_assert
(
util
::
eval_first_n
<
detail
::
min_
<
lhs_types
::
type_list_size
,
rhs_types
::
type_list_size
>
::
value
,
lhs_types
,
rhs_types
,
util
::
is_comparable
>::
value
,
"types of lhs are not comparable to the types of rhs"
);
return
detail
::
cmp_helper
<
(
detail
::
min_
<
lhs_types
::
type_list_size
,
rhs_types
::
type_list_size
>
::
value
-
1
),
LhsTuple
<
LhsTypes
...
>
,
RhsTuple
<
RhsTypes
...
>>::
cmp
(
lhs
,
rhs
);
}
}
}
// namespace cppa::util
}
}
// namespace cppa::util
#endif // COMPARE_TUPLES_HPP
#endif // COMPARE_TUPLES_HPP
cppa/util/eval_type_lists.hpp
View file @
8021cd02
...
@@ -4,7 +4,6 @@
...
@@ -4,7 +4,6 @@
#include <type_traits>
#include <type_traits>
#include "cppa/util/type_list.hpp"
#include "cppa/util/type_list.hpp"
#include "cppa/util/concat_type_lists.hpp"
namespace
cppa
{
namespace
util
{
namespace
cppa
{
namespace
util
{
...
@@ -18,6 +17,7 @@ struct eval_type_lists
...
@@ -18,6 +17,7 @@ struct eval_type_lists
typedef
typename
ListA
::
head_type
head_type_a
;
typedef
typename
ListA
::
head_type
head_type_a
;
typedef
typename
ListA
::
tail_type
tail_type_a
;
typedef
typename
ListA
::
tail_type
tail_type_a
;
typedef
typename
ListB
::
head_type
head_type_b
;
typedef
typename
ListB
::
head_type
head_type_b
;
typedef
typename
ListB
::
tail_type
tail_type_b
;
typedef
typename
ListB
::
tail_type
tail_type_b
;
...
...
libcppa.Makefile
View file @
8021cd02
...
@@ -55,6 +55,7 @@ HEADERS = cppa/actor.hpp \
...
@@ -55,6 +55,7 @@ HEADERS = cppa/actor.hpp \
cppa/util/void_type.hpp
cppa/util/void_type.hpp
SOURCES = src/actor.cpp \
SOURCES = src/actor.cpp \
src/actor_private.cpp \
src/decorated_tuple.cpp \
src/decorated_tuple.cpp \
src/deserializer.cpp \
src/deserializer.cpp \
src/message_receiver.cpp \
src/message_receiver.cpp \
...
...
src/actor.cpp
View file @
8021cd02
#include "cppa/actor.hpp"
#include "cppa/actor.hpp"
#include <boost/thread.hpp>
namespace
cppa
{
namespace
cppa
{
actor
&
actor
::
operator
=
(
const
actor
&
other
)
actor
&
actor
::
operator
=
(
const
actor
&
other
)
...
@@ -14,4 +16,23 @@ actor& actor::operator=(actor&& other)
...
@@ -14,4 +16,23 @@ actor& actor::operator=(actor&& other)
return
*
this
;
return
*
this
;
}
}
actor
::~
actor
()
{
/*
if (m_channel && m_channel->unique())
{
detail::actor_private* ap = dynamic_cast<detail::actor_private*>(m_channel.get());
if (ap && ap->m_thread)
{
if (boost::this_thread::get_id() != ap->m_thread->get_id())
{
ap->m_thread->join();
delete ap->m_thread;
ap->m_thread = 0;
}
}
}
*/
}
}
// namespace cppa
}
// namespace cppa
src/message_receiver.cpp
View file @
8021cd02
...
@@ -22,4 +22,8 @@ message_receiver::operator=(intrusive_ptr<detail::channel>&& ch_ptr)
...
@@ -22,4 +22,8 @@ message_receiver::operator=(intrusive_ptr<detail::channel>&& ch_ptr)
return
*
this
;
return
*
this
;
}
}
message_receiver
::~
message_receiver
()
{
}
}
// namespace cppa
}
// namespace cppa
src/mock_scheduler.cpp
View file @
8021cd02
...
@@ -134,7 +134,8 @@ namespace cppa { namespace detail {
...
@@ -134,7 +134,8 @@ namespace cppa { namespace detail {
actor
spawn_impl
(
behavior
*
actor_behavior
)
actor
spawn_impl
(
behavior
*
actor_behavior
)
{
{
actor_ptr
aptr
(
new
actor_impl
(
actor_behavior
));
actor_ptr
aptr
(
new
actor_impl
(
actor_behavior
));
boost
::
thread
(
aptr
).
detach
();
aptr
.
m_impl
->
m_thread
=
new
boost
::
thread
(
aptr
);
// boost::thread(aptr).detach();
return
actor
(
aptr
.
m_impl
);
return
actor
(
aptr
.
m_impl
);
// return actor(std::move(aptr.m_impl));
// return actor(std::move(aptr.m_impl));
}
}
...
...
unit_testing/test__a_matches_b.cpp
View file @
8021cd02
...
@@ -16,6 +16,8 @@ std::size_t test__a_matches_b()
...
@@ -16,6 +16,8 @@ std::size_t test__a_matches_b()
typedef
type_list
<
int
,
int
,
std
::
string
>
int_int_string
;
typedef
type_list
<
int
,
int
,
std
::
string
>
int_int_string
;
typedef
type_list
<
int
,
int
,
const
std
::
string
&>
int_int_const_string_ref
;
typedef
type_list
<
int
,
int
,
const
std
::
string
&>
int_int_const_string_ref
;
typedef
typename
first_n
<
2
,
int_float_int
>::
type
int_float
;
typedef
type_list_apply
<
int_int_const_string_ref
,
typedef
type_list_apply
<
int_int_const_string_ref
,
remove_const_reference
>::
type
remove_const_reference
>::
type
int_int_string2
;
int_int_string2
;
...
@@ -29,8 +31,10 @@ std::size_t test__a_matches_b()
...
@@ -29,8 +31,10 @@ std::size_t test__a_matches_b()
CPPA_CHECK
((
a_matches_b
<
int_int_string
,
int_int_string2
>::
value
));
CPPA_CHECK
((
a_matches_b
<
int_int_string
,
int_int_string2
>::
value
));
CPPA_CHECK
(
!
(
a_matches_b
<
int_int_string
,
int_int_const_string_ref
>::
value
));
CPPA_CHECK
(
!
(
a_matches_b
<
int_int_string
,
int_int_const_string_ref
>::
value
));
CPPA_CHECK_EQUAL
((
a_matches_b
<
type_list
<
float
>
,
CPPA_CHECK
(
!
(
a_matches_b
<
type_list
<
float
>
,
type_list
<
int
,
float
,
int
>>::
value
),
false
);
type_list
<
int
,
float
,
int
>>::
value
));
CPPA_CHECK
((
std
::
is_same
<
util
::
type_list
<
int
,
float
>
,
int_float
>::
value
));
CPPA_CHECK
((
a_matches_b
<
type_list
<
any_type
*
,
float
>
,
CPPA_CHECK
((
a_matches_b
<
type_list
<
any_type
*
,
float
>
,
type_list
<
int
,
float
,
int
>>::
value
)
==
false
);
type_list
<
int
,
float
,
int
>>::
value
)
==
false
);
...
...
unit_testing/test__local_group.cpp
View file @
8021cd02
...
@@ -20,127 +20,104 @@ using std::endl;
...
@@ -20,127 +20,104 @@ using std::endl;
using
namespace
cppa
;
using
namespace
cppa
;
class
group
:
public
detail
::
channel
namespace
{
{
boost
::
mutex
m_mtx
;
std
::
list
<
actor
>
m_subscribers
;
public:
struct
group
:
detail
::
channel
{
struct
subscription
// NOT thread safe
class
subscription
:
public
detail
::
ref_counted_impl
<
std
::
size_t
>
{
{
actor
m_self
;
actor
m_self
;
intrusive_ptr
<
group
>
m_group
;
intrusive_ptr
<
group
>
m_group
;
public:
subscription
()
=
delete
;
subscription
(
const
subscription
&
)
=
delete
;
subscription
&
operator
=
(
const
subscription
&
)
=
delete
;
subscription
(
const
actor
&
s
,
const
intrusive_ptr
<
group
>&
g
)
subscription
(
const
actor
&
s
,
const
intrusive_ptr
<
group
>&
g
)
:
m_self
(
s
),
m_group
(
g
)
:
m_self
(
s
),
m_group
(
g
)
{
{
}
}
~
subscription
()
~
subscription
()
{
{
m_group
->
unsubscribe
(
m_self
);
m_group
->
unsubscribe
(
m_self
);
}
}
};
};
subscription
subscribe
(
const
actor
&
who
)
virtual
intrusive_ptr
<
subscription
>
subscribe
(
const
actor
&
who
)
=
0
;
{
boost
::
mutex
::
scoped_lock
guard
(
m_mtx
);
m_subscribers
.
push_back
(
who
);
return
{
who
,
this
};
}
void
unsubscribe
(
const
actor
&
who
)
virtual
void
unsubscribe
(
const
actor
&
who
)
=
0
;
{
boost
::
mutex
::
scoped_lock
guard
(
m_mtx
);
auto
i
=
std
::
find
(
m_subscribers
.
begin
(),
m_subscribers
.
end
(),
who
);
if
(
i
!=
m_subscribers
.
end
())
{
m_subscribers
.
erase
(
i
);
}
}
void
enqueue_msg
(
const
message
&
msg
)
{
boost
::
mutex
::
scoped_lock
guard
(
m_mtx
);
for
(
auto
i
=
m_subscribers
.
begin
();
i
!=
m_subscribers
.
end
();
++
i
)
{
i
->
enqueue_msg
(
msg
);
}
}
template
<
typename
...
Args
>
template
<
typename
...
Args
>
void
send
(
const
Args
&
...
args
)
void
send
(
const
Args
&
...
args
)
{
{
message
msg
(
this_actor
(),
this
,
args
...);
enqueue_msg
(
message
(
this_actor
(),
this
,
args
...));
enqueue_msg
(
msg
);
}
}
};
};
namespace
{
class
local_group
:
public
group
class
group_bucket
{
{
boost
::
mutex
m_mtx
;
boost
::
mutex
m_mtx
;
std
::
map
<
std
::
string
,
intrusive_ptr
<
group
>>
m_groups
;
std
::
list
<
actor
>
m_subscribers
;
inline
std
::
list
<
actor
>::
iterator
find
(
const
actor
&
what
)
{
return
std
::
find
(
m_subscribers
.
begin
(),
m_subscribers
.
end
(),
what
);
}
public:
public:
intrusive_ptr
<
group
>
get
(
const
std
::
string
&
group_name
)
virtual
void
enqueue_msg
(
const
message
&
msg
)
{
{
boost
::
mutex
::
scoped_lock
guard
(
m_mtx
);
boost
::
mutex
::
scoped_lock
guard
(
m_mtx
);
intrusive_ptr
<
group
>&
result
=
m_groups
[
group_name
];
for
(
auto
i
=
m_subscribers
.
begin
();
i
!=
m_subscribers
.
end
();
++
i
)
if
(
!
result
)
{
{
result
.
reset
(
new
group
);
i
->
enqueue_msg
(
msg
);
}
}
return
result
;
}
}
};
virtual
intrusive_ptr
<
group
::
subscription
>
subscribe
(
const
actor
&
who
)
template
<
std
::
size_t
NumBuckets
>
class
group_table
{
group_bucket
m_buckets
[
NumBuckets
];
group_bucket
&
bucket
(
const
std
::
string
&
group_name
)
{
{
unsigned
int
gn_hash
=
hash_of
(
group_name
);
boost
::
mutex
::
scoped_lock
guard
(
m_mtx
);
return
m_buckets
[
gn_hash
%
NumBuckets
];
auto
i
=
find
(
who
);
if
(
i
==
m_subscribers
.
end
())
{
m_subscribers
.
push_back
(
who
);
return
new
group
::
subscription
(
who
,
this
);
}
return
new
group
::
subscription
(
0
,
0
);
}
}
public:
virtual
void
unsubscribe
(
const
actor
&
who
)
intrusive_ptr
<
group
>
operator
[](
const
std
::
string
&
group_name
)
{
{
return
bucket
(
group_name
).
get
(
group_name
);
boost
::
mutex
::
scoped_lock
guard
(
m_mtx
);
auto
i
=
find
(
who
);
if
(
i
!=
m_subscribers
.
end
())
{
m_subscribers
.
erase
(
i
);
}
}
}
};
};
group_table
<
100
>
m_groups
;
//local_group* m_local_group = new local_group;
}
// namespace <anonymous>
namespace
{
intrusive_ptr
<
group
>
local_group
=
new
group
;
local_group
m_local_
group
;
}
group
&
local
(
const
char
*
)
struct
{
{
intrusive_ptr
<
group
>
operator
/
(
const
std
::
string
&
/*group_name*/
)
return
m_local_group
;
{
return
local_group
;
// return m_groups[group_name];
}
}
}
local
;
}
// namespace <anonymous>
struct
storage
struct
storage
{
{
...
@@ -168,6 +145,7 @@ struct storage
...
@@ -168,6 +145,7 @@ struct storage
};
};
/*
template<typename... Args>
template<typename... Args>
void send(std::list<actor>& actors, const Args&... args)
void send(std::list<actor>& actors, const Args&... args)
{
{
...
@@ -176,21 +154,13 @@ void send(std::list<actor>& actors, const Args&... args)
...
@@ -176,21 +154,13 @@ void send(std::list<actor>& actors, const Args&... args)
i->send(args...);
i->send(args...);
}
}
}
}
*/
void
foo_actor
()
void
foo_actor
()
{
{
// auto x = (local/"foobar")->subscribe(this_actor());
receive
(
on
<
int
>
()
>>
[](
int
i
)
{
auto
rules
=
(
reply
(
i
);
on
<
int
,
int
,
int
>
()
>>
[]()
{
});
reply
(
23.
f
);
},
on
<
int
>
()
>>
[](
int
i
)
{
reply
(
i
);
}
);
receive
(
rules
);
receive
(
rules
);
// reply(1);
}
}
std
::
size_t
test__local_group
()
std
::
size_t
test__local_group
()
...
@@ -198,37 +168,15 @@ std::size_t test__local_group()
...
@@ -198,37 +168,15 @@ std::size_t test__local_group()
CPPA_TEST
(
test__local_group
);
CPPA_TEST
(
test__local_group
);
/*
std
::
list
<
intrusive_ptr
<
group
::
subscription
>>
m_subscriptions
;
storage st;
st.get<int>("foobaz") = 42;
CPPA_CHECK_EQUAL(st.get<int>("foobaz"), 42);
st.get<std::string>("_s") = "Hello World!";
CPPA_CHECK_EQUAL(st.get<std::string>("_s"), "Hello World!");
*/
// auto g = local/"foobar";
std
::
list
<
actor
>
m_slaves
;
for
(
int
i
=
0
;
i
<
5
;
++
i
)
{
m_slaves
.
push_back
(
spawn
(
foo_actor
));
}
send
(
m_slaves
,
1
,
2
,
3
);
send
(
m_slaves
,
1
);
group
&
lg
=
local
(
"foobar"
);
for
(
int
i
=
0
;
i
<
5
;
++
i
)
for
(
int
i
=
0
;
i
<
5
;
++
i
)
{
{
receive
(
on
<
float
>
()
>>
[]()
{
}
);
m_subscriptions
.
push_back
(
lg
.
subscribe
(
spawn
(
foo_actor
))
);
}
}
// g->
send(1);
lg
.
send
(
1
);
int
result
=
0
;
int
result
=
0
;
...
...
unit_testing/test__tuple.cpp
View file @
8021cd02
...
@@ -73,6 +73,18 @@ std::size_t test__tuple()
...
@@ -73,6 +73,18 @@ std::size_t test__tuple()
CPPA_CHECK
(
tv2
.
get
<
1
>
()
==
"Hello World"
);
CPPA_CHECK
(
tv2
.
get
<
1
>
()
==
"Hello World"
);
{
tuple
<
int
>
t1_sub1
(
42
);
tuple
<
int
,
float
>
t1_sub2
(
42
,
.2
f
);
tuple
<
int
,
float
,
int
>
t1_sub3
(
42
,
.2
f
,
2
);
CPPA_CHECK
((
util
::
compare_first_elements
(
t1
,
t1_sub1
)));
CPPA_CHECK
((
match
<
int
,
any_type
*>
(
t1
,
t1_sub1
)));
CPPA_CHECK
((
util
::
compare_first_elements
(
t1
,
t1_sub2
)));
CPPA_CHECK
((
match
<
int
,
any_type
*
,
float
,
any_type
*>
(
t1
,
t1_sub2
)));
CPPA_CHECK
((
util
::
compare_first_elements
(
t1
,
t1_sub3
)));
CPPA_CHECK
((
match
<
int
,
float
,
int
,
any_type
>
(
t1
,
t1_sub3
)));
}
{
{
std
::
vector
<
std
::
size_t
>
tv3_mappings
;
std
::
vector
<
std
::
size_t
>
tv3_mappings
;
match
<
any_type
*
,
int
,
std
::
string
>
(
t1
,
tv3_mappings
);
match
<
any_type
*
,
int
,
std
::
string
>
(
t1
,
tv3_mappings
);
...
...
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