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
196b8080
Commit
196b8080
authored
Dec 21, 2011
by
neverlord
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
behavior typedef
parent
f4912f83
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
69 additions
and
34 deletions
+69
-34
Makefile.am
Makefile.am
+1
-0
cppa.files
cppa.files
+1
-0
cppa/actor.hpp
cppa/actor.hpp
+4
-4
cppa/behavior.hpp
cppa/behavior.hpp
+13
-0
cppa/event_based_actor.hpp
cppa/event_based_actor.hpp
+5
-2
cppa/event_based_actor_mixin.hpp
cppa/event_based_actor_mixin.hpp
+10
-8
src/event_based_actor.cpp
src/event_based_actor.cpp
+17
-7
unit_testing/test__spawn.cpp
unit_testing/test__spawn.cpp
+18
-13
No files found.
Makefile.am
View file @
196b8080
...
@@ -78,6 +78,7 @@ nobase_library_include_HEADERS = \
...
@@ -78,6 +78,7 @@ nobase_library_include_HEADERS = \
cppa/anything.hpp
\
cppa/anything.hpp
\
cppa/atom.hpp
\
cppa/atom.hpp
\
cppa/attachable.hpp
\
cppa/attachable.hpp
\
cppa/behavior.hpp
\
cppa/binary_deserializer.hpp
\
cppa/binary_deserializer.hpp
\
cppa/binary_serializer.hpp
\
cppa/binary_serializer.hpp
\
cppa/channel.hpp
\
cppa/channel.hpp
\
...
...
cppa.files
View file @
196b8080
...
@@ -242,3 +242,4 @@ cppa/event_based_actor_mixin.hpp
...
@@ -242,3 +242,4 @@ cppa/event_based_actor_mixin.hpp
cppa/fsm_actor.hpp
cppa/fsm_actor.hpp
cppa/self.hpp
cppa/self.hpp
src/self.cpp
src/self.cpp
cppa/behavior.hpp
cppa/actor.hpp
View file @
196b8080
...
@@ -27,7 +27,7 @@ class actor : public channel
...
@@ -27,7 +27,7 @@ class actor : public channel
{
{
bool
m_is_proxy
;
bool
m_is_proxy
;
std
::
uint32_t
m_id
;
actor_id
m_id
;
process_information_ptr
m_parent_process
;
process_information_ptr
m_parent_process
;
protected:
protected:
...
@@ -163,14 +163,14 @@ class actor : public channel
...
@@ -163,14 +163,14 @@ class actor : public channel
* the process it's executed in.
* the process it's executed in.
* @returns The unique identifier of this actor.
* @returns The unique identifier of this actor.
*/
*/
inline
std
::
uint32_t
id
()
const
;
inline
actor_id
id
()
const
;
/**
/**
* @brief Get the actor that has the unique identifier @p
actor_id
.
* @brief Get the actor that has the unique identifier @p
needle
.
* @returns A pointer to the requestet actor or @c nullptr if no
* @returns A pointer to the requestet actor or @c nullptr if no
* running actor with the ID @p actor_id was found in this process.
* running actor with the ID @p actor_id was found in this process.
*/
*/
static
intrusive_ptr
<
actor
>
by_id
(
std
::
uint32_t
actor_id
);
static
intrusive_ptr
<
actor
>
by_id
(
actor_id
needle
);
inline
bool
is_proxy
()
const
;
inline
bool
is_proxy
()
const
;
...
...
cppa/behavior.hpp
0 → 100644
View file @
196b8080
#ifndef BEHAVIOR_HPP
#define BEHAVIOR_HPP
#include "cppa/util/either.hpp"
#include "cppa/invoke_rules.hpp"
namespace
cppa
{
typedef
util
::
either
<
invoke_rules
,
timed_invoke_rules
>
behavior
;
}
// namespace cppa
#endif // BEHAVIOR_HPP
cppa/event_based_actor.hpp
View file @
196b8080
#ifndef EVENT_BASED_ACTOR_HPP
#ifndef EVENT_BASED_ACTOR_HPP
#define EVENT_BASED_ACTOR_HPP
#define EVENT_BASED_ACTOR_HPP
#include "cppa/behavior.hpp"
#include "cppa/event_based_actor_mixin.hpp"
#include "cppa/event_based_actor_mixin.hpp"
namespace
cppa
{
namespace
cppa
{
...
@@ -13,8 +14,10 @@ class event_based_actor : public event_based_actor_mixin<event_based_actor>
...
@@ -13,8 +14,10 @@ class event_based_actor : public event_based_actor_mixin<event_based_actor>
typedef
abstract_event_based_actor
::
stack_element
stack_element
;
typedef
abstract_event_based_actor
::
stack_element
stack_element
;
void
clear
();
void
clear
();
void
do_become
(
invoke_rules
*
behavior
,
bool
has_ownership
);
// has_ownership == false
void
do_become
(
timed_invoke_rules
*
behavior
,
bool
has_ownership
);
void
do_become
(
behavior
*
bhvr
);
void
do_become
(
invoke_rules
*
bhvr
,
bool
has_ownership
);
void
do_become
(
timed_invoke_rules
*
bhvr
,
bool
has_ownership
);
};
};
...
...
cppa/event_based_actor_mixin.hpp
View file @
196b8080
#ifndef EVENT_BASED_ACTOR_MIXIN_HPP
#ifndef EVENT_BASED_ACTOR_MIXIN_HPP
#define EVENT_BASED_ACTOR_MIXIN_HPP
#define EVENT_BASED_ACTOR_MIXIN_HPP
#include "cppa/behavior.hpp"
#include "cppa/abstract_event_based_actor.hpp"
#include "cppa/abstract_event_based_actor.hpp"
#include <iostream>
using
std
::
cout
;
using
std
::
endl
;
namespace
cppa
{
namespace
cppa
{
template
<
typename
Derived
>
template
<
typename
Derived
>
...
@@ -36,22 +33,27 @@ class event_based_actor_mixin : public abstract_event_based_actor
...
@@ -36,22 +33,27 @@ class event_based_actor_mixin : public abstract_event_based_actor
protected:
protected:
void
become
(
invoke_rules
*
behavior
)
inline
void
become
(
behavior
*
bhvr
)
{
d_this
()
->
do_become
(
bhvr
);
}
inline
void
become
(
invoke_rules
*
behavior
)
{
{
d_this
()
->
do_become
(
behavior
,
false
);
d_this
()
->
do_become
(
behavior
,
false
);
}
}
void
become
(
timed_invoke_rules
*
behavior
)
inline
void
become
(
timed_invoke_rules
*
behavior
)
{
{
d_this
()
->
do_become
(
behavior
,
false
);
d_this
()
->
do_become
(
behavior
,
false
);
}
}
void
become
(
invoke_rules
&&
behavior
)
inline
void
become
(
invoke_rules
&&
behavior
)
{
{
d_this
()
->
do_become
(
new
invoke_rules
(
std
::
move
(
behavior
)),
true
);
d_this
()
->
do_become
(
new
invoke_rules
(
std
::
move
(
behavior
)),
true
);
}
}
void
become
(
timed_invoke_rules
&&
behavior
)
inline
void
become
(
timed_invoke_rules
&&
behavior
)
{
{
d_this
()
->
do_become
(
new
timed_invoke_rules
(
std
::
move
(
behavior
)),
true
);
d_this
()
->
do_become
(
new
timed_invoke_rules
(
std
::
move
(
behavior
)),
true
);
}
}
...
...
src/event_based_actor.cpp
View file @
196b8080
...
@@ -7,20 +7,30 @@ void event_based_actor::clear()
...
@@ -7,20 +7,30 @@ void event_based_actor::clear()
if
(
!
m_loop_stack
.
empty
())
m_loop_stack
.
pop
();
if
(
!
m_loop_stack
.
empty
())
m_loop_stack
.
pop
();
}
}
void
event_based_actor
::
do_become
(
invoke_rules
*
behavior
,
void
event_based_actor
::
do_become
(
behavior
*
bhvr
)
bool
has_ownership
)
{
if
(
bhvr
->
is_left
())
{
do_become
(
&
(
bhvr
->
left
()),
false
);
}
else
{
do_become
(
&
(
bhvr
->
right
()),
false
);
}
}
void
event_based_actor
::
do_become
(
invoke_rules
*
bhvr
,
bool
has_ownership
)
{
{
clear
();
clear
();
reset_timeout
();
reset_timeout
();
m_loop_stack
.
push
(
stack_element
(
b
ehavio
r
,
has_ownership
));
m_loop_stack
.
push
(
stack_element
(
b
hv
r
,
has_ownership
));
}
}
void
event_based_actor
::
do_become
(
timed_invoke_rules
*
behavior
,
void
event_based_actor
::
do_become
(
timed_invoke_rules
*
bhvr
,
bool
has_ownership
)
bool
has_ownership
)
{
{
clear
();
clear
();
request_timeout
(
b
ehavio
r
->
timeout
());
request_timeout
(
b
hv
r
->
timeout
());
m_loop_stack
.
push
(
stack_element
(
b
ehavio
r
,
has_ownership
));
m_loop_stack
.
push
(
stack_element
(
b
hv
r
,
has_ownership
));
}
}
}
// namespace cppa
}
// namespace cppa
unit_testing/test__spawn.cpp
View file @
196b8080
...
@@ -28,7 +28,7 @@ using namespace cppa;
...
@@ -28,7 +28,7 @@ using namespace cppa;
struct
event_testee
:
public
fsm_actor
<
event_testee
>
struct
event_testee
:
public
fsm_actor
<
event_testee
>
{
{
invoke_rules
wait4string
=
behavior
wait4string
=
(
(
on
<
std
::
string
>
()
>>
[
this
]()
on
<
std
::
string
>
()
>>
[
this
]()
{
{
...
@@ -40,7 +40,7 @@ struct event_testee : public fsm_actor<event_testee>
...
@@ -40,7 +40,7 @@ struct event_testee : public fsm_actor<event_testee>
}
}
);
);
invoke_rules
wait4float
=
behavior
wait4float
=
(
(
on
<
float
>
()
>>
[
=
]()
on
<
float
>
()
>>
[
=
]()
{
{
...
@@ -52,7 +52,7 @@ struct event_testee : public fsm_actor<event_testee>
...
@@ -52,7 +52,7 @@ struct event_testee : public fsm_actor<event_testee>
}
}
);
);
invoke_rules
init_state
=
behavior
init_state
=
(
(
on
<
int
>
()
>>
[
=
]()
on
<
int
>
()
>>
[
=
]()
{
{
...
@@ -73,9 +73,9 @@ class event_testee : public fsm_actor<event_testee>
...
@@ -73,9 +73,9 @@ class event_testee : public fsm_actor<event_testee>
friend
class
fsm_actor
<
event_testee
>
;
friend
class
fsm_actor
<
event_testee
>
;
invoke_rules
wait4string
;
behavior
wait4string
;
invoke_rules
wait4float
;
behavior
wait4float
;
invoke_rules
init_state
;
behavior
init_state
;
public:
public:
...
@@ -125,7 +125,12 @@ class event_testee : public fsm_actor<event_testee>
...
@@ -125,7 +125,12 @@ class event_testee : public fsm_actor<event_testee>
on
<
atom
(
"GetState"
)
>
()
>>
[
=
]()
on
<
atom
(
"GetState"
)
>
()
>>
[
=
]()
{
{
reply
(
"init_state"
);
reply
(
"init_state"
);
},
after
(
std
::
chrono
::
seconds
(
5
))
>>
[
=
]()
{
quit
(
exit_reason
::
user_defined
);
}
}
);
);
}
}
...
@@ -307,14 +312,14 @@ size_t test__spawn()
...
@@ -307,14 +312,14 @@ size_t test__spawn()
CPPA_CHECK_EQUAL
(
behavior_test
<
testee_actor
>
(),
"init_state"
);
CPPA_CHECK_EQUAL
(
behavior_test
<
testee_actor
>
(),
"init_state"
);
CPPA_CHECK_EQUAL
(
behavior_test
<
event_testee
>
(),
"init_state"
);
CPPA_CHECK_EQUAL
(
behavior_test
<
event_testee
>
(),
"init_state"
);
// create
one million
actors linked to one single actor
// create
20,000
actors linked to one single actor
// and kill them all through killing the link
// and kill them all through killing the link
auto
my_link
=
spawn
(
new
event_testee
);
//
auto my_link = spawn(new event_testee);
for
(
int
i
=
0
;
i
<
20000
;
++
i
)
//
for (int i = 0; i < 20000; ++i)
{
//
{
link
(
my_link
,
spawn
(
new
event_testee
));
//
link(my_link, spawn(new event_testee));
}
//
}
send
(
my_link
,
atom
(
":Exit"
),
exit_reason
::
user_defined
);
//
send(my_link, atom(":Exit"), exit_reason::user_defined);
return
CPPA_TEST_RESULT
;
return
CPPA_TEST_RESULT
;
...
...
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