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
daf900c1
Commit
daf900c1
authored
Apr 22, 2016
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make sure on_exit is called when destroying actors
Also move virtual function calls out of destructors. Relates #454.
parent
406f2f1e
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
39 additions
and
3 deletions
+39
-3
libcaf_core/caf/abstract_actor.hpp
libcaf_core/caf/abstract_actor.hpp
+7
-0
libcaf_core/caf/actor_storage.hpp
libcaf_core/caf/actor_storage.hpp
+2
-0
libcaf_core/caf/local_actor.hpp
libcaf_core/caf/local_actor.hpp
+2
-0
libcaf_core/caf/stateful_actor.hpp
libcaf_core/caf/stateful_actor.hpp
+2
-2
libcaf_core/src/abstract_actor.cpp
libcaf_core/src/abstract_actor.cpp
+4
-0
libcaf_core/src/local_actor.cpp
libcaf_core/src/local_actor.cpp
+8
-1
libcaf_core/test/actor_lifetime.cpp
libcaf_core/test/actor_lifetime.cpp
+14
-0
No files found.
libcaf_core/caf/abstract_actor.hpp
View file @
daf900c1
...
@@ -64,6 +64,13 @@ public:
...
@@ -64,6 +64,13 @@ public:
virtual
~
abstract_actor
();
virtual
~
abstract_actor
();
/// Cleans up any remaining state before the destructor is called.
/// This function makes sure it is safe to call virtual functions
/// in sub classes before destroying the object, because calling
/// virtual function in the destructor itself is not safe. Any override
/// implementation is required to call `super::destroy()` at the end.
virtual
void
destroy
();
void
enqueue
(
strong_actor_ptr
sender
,
message_id
mid
,
void
enqueue
(
strong_actor_ptr
sender
,
message_id
mid
,
message
content
,
execution_unit
*
host
)
override
;
message
content
,
execution_unit
*
host
)
override
;
...
...
libcaf_core/caf/actor_storage.hpp
View file @
daf900c1
...
@@ -26,6 +26,7 @@
...
@@ -26,6 +26,7 @@
#include <type_traits>
#include <type_traits>
#include "caf/config.hpp"
#include "caf/config.hpp"
#include "caf/abstract_actor.hpp"
#include "caf/actor_control_block.hpp"
#include "caf/actor_control_block.hpp"
#ifdef CAF_GCC
#ifdef CAF_GCC
...
@@ -75,6 +76,7 @@ public:
...
@@ -75,6 +76,7 @@ public:
private:
private:
static
void
data_dtor
(
abstract_actor
*
ptr
)
{
static
void
data_dtor
(
abstract_actor
*
ptr
)
{
// safe due to static assert #3
// safe due to static assert #3
ptr
->
destroy
();
static_cast
<
T
*>
(
ptr
)
->~
T
();
static_cast
<
T
*>
(
ptr
)
->~
T
();
}
}
...
...
libcaf_core/caf/local_actor.hpp
View file @
daf900c1
...
@@ -129,6 +129,8 @@ public:
...
@@ -129,6 +129,8 @@ public:
~
local_actor
();
~
local_actor
();
void
destroy
()
override
;
// -- spawn functions --------------------------------------------------------
// -- spawn functions --------------------------------------------------------
template
<
class
T
,
spawn_options
Os
=
no_spawn_options
,
class
...
Ts
>
template
<
class
T
,
spawn_options
Os
=
no_spawn_options
,
class
...
Ts
>
...
...
libcaf_core/caf/stateful_actor.hpp
View file @
daf900c1
...
@@ -52,12 +52,12 @@ public:
...
@@ -52,12 +52,12 @@ public:
}
}
/// Destroys the state of this actor (no further overriding allowed).
/// Destroys the state of this actor (no further overriding allowed).
void
on_exit
()
override
final
{
void
on_exit
()
final
{
CAF_LOG_TRACE
(
""
);
CAF_LOG_TRACE
(
""
);
state_
.
~
State
();
state_
.
~
State
();
}
}
const
char
*
name
()
const
override
final
{
const
char
*
name
()
const
final
{
return
get_name
(
state_
);
return
get_name
(
state_
);
}
}
...
...
libcaf_core/src/abstract_actor.cpp
View file @
daf900c1
...
@@ -54,6 +54,10 @@ abstract_actor::~abstract_actor() {
...
@@ -54,6 +54,10 @@ abstract_actor::~abstract_actor() {
// nop
// nop
}
}
void
abstract_actor
::
destroy
()
{
// nop
}
void
abstract_actor
::
enqueue
(
strong_actor_ptr
sender
,
message_id
mid
,
void
abstract_actor
::
enqueue
(
strong_actor_ptr
sender
,
message_id
mid
,
message
msg
,
execution_unit
*
host
)
{
message
msg
,
execution_unit
*
host
)
{
enqueue
(
mailbox_element
::
make
(
sender
,
mid
,
{},
std
::
move
(
msg
)),
host
);
enqueue
(
mailbox_element
::
make
(
sender
,
mid
,
{},
std
::
move
(
msg
)),
host
);
...
...
libcaf_core/src/local_actor.cpp
View file @
daf900c1
...
@@ -99,9 +99,16 @@ local_actor::local_actor(int init_flags)
...
@@ -99,9 +99,16 @@ local_actor::local_actor(int init_flags)
}
}
local_actor
::~
local_actor
()
{
local_actor
::~
local_actor
()
{
// nop
}
void
local_actor
::
destroy
()
{
CAF_LOG_TRACE
(
CAF_ARG
(
planned_exit_reason
()));
CAF_LOG_TRACE
(
CAF_ARG
(
planned_exit_reason
()));
if
(
planned_exit_reason
()
==
exit_reason
::
not_exited
)
if
(
planned_exit_reason
()
==
exit_reason
::
not_exited
)
{
on_exit
();
cleanup
(
exit_reason
::
unreachable
,
nullptr
);
cleanup
(
exit_reason
::
unreachable
,
nullptr
);
}
monitorable_actor
::
destroy
();
}
}
void
local_actor
::
intrusive_ptr_add_ref_impl
()
{
void
local_actor
::
intrusive_ptr_add_ref_impl
()
{
...
...
libcaf_core/test/actor_lifetime.cpp
View file @
daf900c1
...
@@ -43,9 +43,14 @@ public:
...
@@ -43,9 +43,14 @@ public:
}
}
~
testee
()
{
~
testee
()
{
printf
(
"%s %d
\n
"
,
__FILE__
,
__LINE__
);
--
s_testees
;
--
s_testees
;
}
}
const
char
*
name
()
const
override
{
return
"testee"
;
}
void
on_exit
()
override
{
void
on_exit
()
override
{
--
s_pending_on_exits
;
--
s_pending_on_exits
;
}
}
...
@@ -105,6 +110,15 @@ struct fixture {
...
@@ -105,6 +110,15 @@ struct fixture {
}
// namespace <anonymous>
}
// namespace <anonymous>
CAF_TEST
(
destructor_call
)
{
{
// lifetime scope of actor systme
actor_system
system
;
system
.
spawn
<
testee
>
();
}
CAF_CHECK_EQUAL
(
s_testees
.
load
(),
0
);
CAF_CHECK_EQUAL
(
s_pending_on_exits
.
load
(),
0
);
}
CAF_TEST_FIXTURE_SCOPE
(
actor_lifetime_tests
,
fixture
)
CAF_TEST_FIXTURE_SCOPE
(
actor_lifetime_tests
,
fixture
)
CAF_TEST
(
no_spawn_options_and_exit_msg
)
{
CAF_TEST
(
no_spawn_options_and_exit_msg
)
{
...
...
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