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
a6c9ad67
Commit
a6c9ad67
authored
May 30, 2012
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cleanup; removed link, unlink, monitor and demonitor from cppa namespace
parent
3a523fc7
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
71 additions
and
181 deletions
+71
-181
cppa/cppa.hpp
cppa/cppa.hpp
+1
-91
cppa/local_actor.hpp
cppa/local_actor.hpp
+15
-0
src/cppa.cpp
src/cppa.cpp
+0
-78
src/local_actor.cpp
src/local_actor.cpp
+41
-0
src/unicast_network.cpp
src/unicast_network.cpp
+1
-5
unit_testing/test__spawn.cpp
unit_testing/test__spawn.cpp
+13
-7
No files found.
cppa/cppa.hpp
View file @
a6c9ad67
...
@@ -423,52 +423,6 @@
...
@@ -423,52 +423,6 @@
namespace
cppa
{
namespace
cppa
{
/**
* @ingroup ActorManagement
* @brief Links @p lhs and @p rhs;
* @pre <tt>lhs != rhs</tt>
*/
void
link
(
actor_ptr
&
lhs
,
actor_ptr
&
rhs
);
/**
* @copydoc link(actor_ptr&,actor_ptr&)
*/
void
link
(
actor_ptr
&&
lhs
,
actor_ptr
&
rhs
);
/**
* @copydoc link(actor_ptr&,actor_ptr&)
*/
void
link
(
actor_ptr
&&
lhs
,
actor_ptr
&&
rhs
);
/**
* @copydoc link(actor_ptr&,actor_ptr&)
*/
void
link
(
actor_ptr
&
lhs
,
actor_ptr
&&
rhs
);
/**
* @ingroup ActorManagement
* @brief Unlinks @p lhs from @p rhs;
* @pre <tt>lhs != rhs</tt>
*/
void
unlink
(
actor_ptr
&
lhs
,
actor_ptr
&
rhs
);
/**
* @ingroup ActorManagement
* @brief Adds a unidirectional @p monitor to @p whom.
* @note Each calls to @p monitor creates a new, independent monitor.
* @pre The calling actor receives a "DOWN" message from @p whom when
* it terminates.
*/
void
monitor
(
actor_ptr
&
whom
);
void
monitor
(
actor_ptr
&&
whom
);
/**
* @ingroup ActorManagement
* @brief Removes a monitor from @p whom.
*/
void
demonitor
(
actor_ptr
&
whom
);
/**
/**
* @ingroup ActorManagement
* @ingroup ActorManagement
* @brief Spans a new context-switching actor.
* @brief Spans a new context-switching actor.
...
@@ -524,45 +478,6 @@ inline actor_ptr spawn(F&& what, Arg0&& arg0, Args&&... args) {
...
@@ -524,45 +478,6 @@ inline actor_ptr spawn(F&& what, Arg0&& arg0, Args&&... args) {
spawn_fwd_
<
typename
util
::
rm_ref
<
Args
>::
type
>::
_
(
args
)...));
spawn_fwd_
<
typename
util
::
rm_ref
<
Args
>::
type
>::
_
(
args
)...));
}
}
/*
/ **
* @ingroup ActorManagement
* @brief Spawns a new actor that executes @p what with given arguments.
* @tparam Hint Hint to the scheduler for the best scheduling strategy.
* @param what Function or functor that the spawned Actor should execute.
* @param args Arguments needed to invoke @p what.
* @returns A pointer to the spawned {@link actor actor}.
* /
template<scheduling_hint Hint, typename F, typename... Args>
auto //actor_ptr
spawn(F&& what, const Args&... args)
-> typename std::enable_if<
!std::is_convertible<typename util::rm_ref<F>::type, scheduled_actor*>::value
&& !std::is_convertible<typename util::rm_ref<F>::type, event_based_actor*>::value,
actor_ptr
>::type {
typedef typename util::rm_ref<F>::type ftype;
std::integral_constant<bool, std::is_function<ftype>::value> is_fun;
auto ptr = detail::get_behavior(is_fun, std::forward<F>(what), args...);
return get_scheduler()->spawn(ptr, Hint);
}
/ **
* @ingroup ActorManagement
* @brief Alias for <tt>spawn<scheduled>(what, args...)</tt>.
* /
template<typename F, typename... Args>
auto // actor_ptr
spawn(F&& what, const Args&... args)
-> typename std::enable_if<
!std::is_convertible<typename util::rm_ref<F>::type, scheduled_actor*>::value
&& !std::is_convertible<typename util::rm_ref<F>::type, event_based_actor*>::value,
actor_ptr
>::type {
return spawn<scheduled>(std::forward<F>(what), args...);
}
*/
#ifdef CPPA_DOCUMENTATION
#ifdef CPPA_DOCUMENTATION
/**
/**
...
@@ -713,12 +628,7 @@ inline void await_all_others_done() {
...
@@ -713,12 +628,7 @@ inline void await_all_others_done() {
* @param port Unused TCP port.
* @param port Unused TCP port.
* @throws bind_failure
* @throws bind_failure
*/
*/
void
publish
(
actor_ptr
&
whom
,
std
::
uint16_t
port
);
void
publish
(
actor_ptr
whom
,
std
::
uint16_t
port
);
/**
* @copydoc publish(actor_ptr&,std::uint16_t)
*/
void
publish
(
actor_ptr
&&
whom
,
std
::
uint16_t
port
);
/**
/**
* @brief Establish a new connection to the actor at @p host on given @p port.
* @brief Establish a new connection to the actor at @p host on given @p port.
...
...
cppa/local_actor.hpp
View file @
a6c9ad67
...
@@ -137,6 +137,21 @@ class local_actor : public actor {
...
@@ -137,6 +137,21 @@ class local_actor : public actor {
}
}
}
}
/**
* @ingroup ActorManagement
* @brief Adds a unidirectional @p monitor to @p whom.
* @note Each calls to @p monitor creates a new, independent monitor.
* @pre The calling actor receives a "DOWN" message from @p whom when
* it terminates.
*/
void
monitor
(
actor_ptr
whom
);
/**
* @ingroup ActorManagement
* @brief Removes a monitor from @p whom.
*/
void
demonitor
(
actor_ptr
whom
);
};
};
typedef
intrusive_ptr
<
local_actor
>
local_actor_ptr
;
typedef
intrusive_ptr
<
local_actor
>
local_actor_ptr
;
...
...
src/cppa.cpp
View file @
a6c9ad67
...
@@ -33,37 +33,6 @@
...
@@ -33,37 +33,6 @@
namespace
cppa
{
namespace
cppa
{
namespace
{
class
down_observer
:
public
attachable
{
actor_ptr
m_observer
;
actor_ptr
m_observed
;
public:
down_observer
(
actor_ptr
observer
,
actor_ptr
observed
)
:
m_observer
(
std
::
move
(
observer
))
,
m_observed
(
std
::
move
(
observed
))
{
}
void
actor_exited
(
std
::
uint32_t
reason
)
{
using
namespace
cppa
;
send
(
m_observer
,
atom
(
"DOWN"
),
m_observed
,
reason
);
}
bool
matches
(
const
attachable
::
token
&
match_token
)
{
if
(
match_token
.
subtype
==
typeid
(
down_observer
))
{
auto
ptr
=
reinterpret_cast
<
const
local_actor
*>
(
match_token
.
ptr
);
return
m_observer
==
ptr
;
}
return
false
;
}
};
}
// namespace <anonymous>
const
self_type
&
operator
<<
(
const
self_type
&
s
,
const
any_tuple
&
what
)
{
const
self_type
&
operator
<<
(
const
self_type
&
s
,
const
any_tuple
&
what
)
{
local_actor
*
sptr
=
s
;
local_actor
*
sptr
=
s
;
sptr
->
enqueue
(
sptr
,
what
);
sptr
->
enqueue
(
sptr
,
what
);
...
@@ -76,51 +45,4 @@ const self_type& operator<<(const self_type& s, any_tuple&& what) {
...
@@ -76,51 +45,4 @@ const self_type& operator<<(const self_type& s, any_tuple&& what) {
return
s
;
return
s
;
}
}
void
link
(
actor_ptr
&
other
)
{
if
(
other
)
self
->
link_to
(
other
);
}
void
link
(
actor_ptr
&&
other
)
{
actor_ptr
tmp
(
std
::
move
(
other
));
link
(
tmp
);
}
void
link
(
actor_ptr
&
lhs
,
actor_ptr
&
rhs
)
{
if
(
lhs
&&
rhs
)
lhs
->
link_to
(
rhs
);
}
void
link
(
actor_ptr
&&
lhs
,
actor_ptr
&
rhs
)
{
actor_ptr
tmp
(
std
::
move
(
lhs
));
link
(
tmp
,
rhs
);
}
void
link
(
actor_ptr
&&
lhs
,
actor_ptr
&&
rhs
)
{
actor_ptr
tmp1
(
std
::
move
(
lhs
));
actor_ptr
tmp2
(
std
::
move
(
rhs
));
link
(
tmp1
,
tmp2
);
}
void
link
(
actor_ptr
&
lhs
,
actor_ptr
&&
rhs
)
{
actor_ptr
tmp
(
std
::
move
(
rhs
));
link
(
lhs
,
tmp
);
}
void
unlink
(
actor_ptr
&
lhs
,
actor_ptr
&
rhs
)
{
if
(
lhs
&&
rhs
)
lhs
->
unlink_from
(
rhs
);
}
void
monitor
(
actor_ptr
&
whom
)
{
if
(
whom
)
whom
->
attach
(
new
down_observer
(
self
,
whom
));
}
void
monitor
(
actor_ptr
&&
whom
)
{
actor_ptr
tmp
(
std
::
move
(
whom
));
monitor
(
tmp
);
}
void
demonitor
(
actor_ptr
&
whom
)
{
attachable
::
token
mtoken
(
typeid
(
down_observer
),
self
);
if
(
whom
)
whom
->
detach
(
mtoken
);
}
}
// namespace cppa
}
// namespace cppa
src/local_actor.cpp
View file @
a6c9ad67
...
@@ -28,12 +28,53 @@
...
@@ -28,12 +28,53 @@
\******************************************************************************/
\******************************************************************************/
#include "cppa/cppa.hpp"
#include "cppa/atom.hpp"
#include "cppa/local_actor.hpp"
#include "cppa/local_actor.hpp"
namespace
cppa
{
namespace
cppa
{
namespace
{
class
down_observer
:
public
attachable
{
actor_ptr
m_observer
;
actor_ptr
m_observed
;
public:
down_observer
(
actor_ptr
observer
,
actor_ptr
observed
)
:
m_observer
(
std
::
move
(
observer
))
,
m_observed
(
std
::
move
(
observed
))
{
}
void
actor_exited
(
std
::
uint32_t
reason
)
{
send
(
m_observer
,
atom
(
"DOWN"
),
m_observed
,
reason
);
}
bool
matches
(
const
attachable
::
token
&
match_token
)
{
if
(
match_token
.
subtype
==
typeid
(
down_observer
))
{
auto
ptr
=
reinterpret_cast
<
const
local_actor
*>
(
match_token
.
ptr
);
return
m_observer
==
ptr
;
}
return
false
;
}
};
}
// namespace <anonymous>
local_actor
::
local_actor
(
bool
sflag
)
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
));
}
void
local_actor
::
demonitor
(
actor_ptr
whom
)
{
attachable
::
token
mtoken
{
typeid
(
down_observer
),
this
};
if
(
whom
)
whom
->
detach
(
mtoken
);
}
}
// namespace cppa
}
// namespace cppa
src/unicast_network.cpp
View file @
a6c9ad67
...
@@ -105,7 +105,7 @@ struct socket_guard {
...
@@ -105,7 +105,7 @@ struct socket_guard {
};
};
void
publish
(
actor_ptr
&
whom
,
std
::
uint16_t
port
)
{
void
publish
(
actor_ptr
whom
,
std
::
uint16_t
port
)
{
if
(
!
whom
)
return
;
if
(
!
whom
)
return
;
detail
::
singleton_manager
::
get_actor_registry
()
->
put
(
whom
->
id
(),
whom
);
detail
::
singleton_manager
::
get_actor_registry
()
->
put
(
whom
->
id
(),
whom
);
detail
::
native_socket_type
sockfd
;
detail
::
native_socket_type
sockfd
;
...
@@ -140,10 +140,6 @@ void publish(actor_ptr& whom, std::uint16_t port) {
...
@@ -140,10 +140,6 @@ void publish(actor_ptr& whom, std::uint16_t port) {
detail
::
post_office_publish
(
sockfd
,
whom
);
detail
::
post_office_publish
(
sockfd
,
whom
);
}
}
void
publish
(
actor_ptr
&&
whom
,
std
::
uint16_t
port
)
{
publish
(
static_cast
<
actor_ptr
&>
(
whom
),
port
);
}
actor_ptr
remote_actor
(
const
char
*
host
,
std
::
uint16_t
port
)
{
actor_ptr
remote_actor
(
const
char
*
host
,
std
::
uint16_t
port
)
{
detail
::
native_socket_type
sockfd
;
detail
::
native_socket_type
sockfd
;
struct
sockaddr_in
serv_addr
;
struct
sockaddr_in
serv_addr
;
...
...
unit_testing/test__spawn.cpp
View file @
a6c9ad67
...
@@ -514,17 +514,23 @@ size_t test__spawn() {
...
@@ -514,17 +514,23 @@ size_t test__spawn() {
// create 20,000 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
twenty_thousand
=
spawn
([]()
{
for
(
int
i
=
0
;
i
<
20000
;
++
i
)
{
for
(
int
i
=
0
;
i
<
20000
;
++
i
)
{
link
(
my_link
,
spawn
(
new
event_testee
));
self
->
link_to
(
spawn
(
new
event_testee
));
}
}
send
(
my_link
,
atom
(
"EXIT"
),
exit_reason
::
user_defined
);
receive_loop
(
others
()
>>
[]()
{
cout
<<
"wtf? => "
<<
to_string
(
self
->
last_dequeued
())
<<
endl
;
}
);
});
send
(
twenty_thousand
,
atom
(
"EXIT"
),
exit_reason
::
user_defined
);
await_all_others_done
();
await_all_others_done
();
self
->
trap_exit
(
true
);
self
->
trap_exit
(
true
);
auto
ping_actor
=
spawn
(
ping
,
10
);
auto
ping_actor
=
spawn
(
ping
,
10
);
auto
pong_actor
=
spawn
(
pong
,
ping_actor
);
auto
pong_actor
=
spawn
(
pong
,
ping_actor
);
monitor
(
pong_actor
);
self
->
monitor
(
pong_actor
);
monitor
(
ping_actor
);
self
->
monitor
(
ping_actor
);
self
->
link_to
(
pong_actor
);
self
->
link_to
(
pong_actor
);
int
i
=
0
;
int
i
=
0
;
int
flags
=
0
;
int
flags
=
0
;
...
...
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