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
7e0dbf24
Commit
7e0dbf24
authored
Aug 17, 2012
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added shutdown() function
parent
ad406f57
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
17 deletions
+44
-17
cppa/cppa.hpp
cppa/cppa.hpp
+8
-0
src/singleton_manager.cpp
src/singleton_manager.cpp
+36
-17
No files found.
cppa/cppa.hpp
View file @
7e0dbf24
...
...
@@ -797,6 +797,14 @@ inline actor_ptr remote_actor(const std::string& host, std::uint16_t port) {
*/
actor_ptr
remote_actor
(
util
::
io_stream_ptr_pair
connection
);
/**
* @brief Destroys all singletons, disconnects all peers and stops the
* scheduler. It is recommended to use this function as very last
* function call before leaving main(). Especially in programs
* using libcppa's networking infrastructure.
*/
void
shutdown
();
// note: implemented in singleton_manager.cpp
}
// namespace cppa
namespace
std
{
...
...
src/singleton_manager.cpp
View file @
7e0dbf24
...
...
@@ -46,6 +46,9 @@
#include "cppa/detail/thread_pool_scheduler.hpp"
#include "cppa/detail/uniform_type_info_map.hpp"
using
std
::
cout
;
using
std
::
endl
;
namespace
{
using
namespace
cppa
;
...
...
@@ -67,6 +70,7 @@ void stop_and_kill(std::atomic<T*>& ptr) {
if
(
ptr
.
compare_exchange_weak
(
p
,
nullptr
))
{
p
->
stop
();
delete
p
;
ptr
=
nullptr
;
}
else
{
stop_and_kill
(
ptr
);
...
...
@@ -75,25 +79,12 @@ void stop_and_kill(std::atomic<T*>& ptr) {
}
/*
void delete_singletons() {
if (self.unchecked() != nullptr) {
try { self.unchecked()->quit(exit_reason::normal); }
catch (actor_exited&) { }
}
auto rptr = s_actor_registry.load();
if (rptr) {
rptr->await_running_count_equal(0);
struct static_cleanup_helper {
~static_cleanup_helper() {
delete_singletons();
}
stop_and_kill(s_scheduler);
stop_and_kill(s_network_manager);
std::atomic_thread_fence(std::memory_order_seq_cst);
// it's safe now to delete all other singletons now
delete s_actor_registry.load();
delete s_group_manager.load();
auto et = s_empty_tuple.load();
if (et && !et->deref()) delete et;
delete s_uniform_type_info_map.load();
}
s_static_cleanup_helper;
*/
template
<
typename
T
>
...
...
@@ -126,6 +117,34 @@ T* lazy_get(std::atomic<T*>& ptr, bool register_atexit_fun = false) {
}
// namespace <anonymous>
namespace
cppa
{
void
shutdown
()
{
if
(
self
.
unchecked
()
!=
nullptr
)
{
try
{
self
.
unchecked
()
->
quit
(
exit_reason
::
normal
);
}
catch
(
actor_exited
&
)
{
}
}
auto
rptr
=
s_actor_registry
.
load
();
if
(
rptr
)
{
rptr
->
await_running_count_equal
(
0
);
}
stop_and_kill
(
s_scheduler
);
stop_and_kill
(
s_network_manager
);
std
::
atomic_thread_fence
(
std
::
memory_order_seq_cst
);
// it's safe now to delete all other singletons now
delete
s_actor_registry
.
load
();
s_actor_registry
=
nullptr
;
delete
s_group_manager
.
load
();
s_group_manager
=
nullptr
;
auto
et
=
s_empty_tuple
.
load
();
if
(
et
&&
!
et
->
deref
())
delete
et
;
s_empty_tuple
=
nullptr
;
delete
s_uniform_type_info_map
.
load
();
s_uniform_type_info_map
=
nullptr
;
}
}
// namespace cppa
namespace
cppa
{
namespace
detail
{
actor_registry
*
singleton_manager
::
get_actor_registry
()
{
...
...
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