Commit 152aa067 authored by neverlord's avatar neverlord

use atexit() rather than a 'static destructor'

parent 9018413e
...@@ -76,10 +76,8 @@ void stop_and_kill(std::atomic<T*>& ptr) ...@@ -76,10 +76,8 @@ void stop_and_kill(std::atomic<T*>& ptr)
} }
} }
struct singleton_cleanup_helper void delete_singletons()
{ {
~singleton_cleanup_helper()
{
if (self.unchecked() != nullptr) if (self.unchecked() != nullptr)
{ {
try { self.unchecked()->quit(exit_reason::normal); } try { self.unchecked()->quit(exit_reason::normal); }
...@@ -90,24 +88,19 @@ struct singleton_cleanup_helper ...@@ -90,24 +88,19 @@ struct singleton_cleanup_helper
{ {
rptr->await_running_count_equal(0); rptr->await_running_count_equal(0);
} }
delete s_actor_registry.load();
// TODO: figure out why the ... Mac OS dies with a segfault here
//# ifndef __APPLE__
stop_and_kill(s_scheduler); stop_and_kill(s_scheduler);
//# endif
stop_and_kill(s_network_manager); stop_and_kill(s_network_manager);
CPPA_MEMORY_BARRIER();
// it's safe now to delete all other singletons now // it's safe now to delete all other singletons now
delete s_actor_registry.load();
delete s_group_manager.load(); delete s_group_manager.load();
auto et = s_empty_tuple.load(); auto et = s_empty_tuple.load();
if (et && !et->deref()) delete et; if (et && !et->deref()) delete et;
delete s_actor_registry.load();
delete s_uniform_type_info_map.load(); delete s_uniform_type_info_map.load();
}
} }
;//s_cleanup_helper;
template<typename T> template<typename T>
T* lazy_get(std::atomic<T*>& ptr) T* lazy_get(std::atomic<T*>& ptr, bool register_atexit_fun = false)
{ {
T* result = ptr.load(); T* result = ptr.load();
if (result == nullptr) if (result == nullptr)
...@@ -119,6 +112,13 @@ T* lazy_get(std::atomic<T*>& ptr) ...@@ -119,6 +112,13 @@ T* lazy_get(std::atomic<T*>& ptr)
} }
else else
{ {
// ok, successfully created singleton, register exit fun?
if (register_atexit_fun)
{
//# ifndef __APPLE__
atexit(delete_singletons);
//# endif
}
return tmp; return tmp;
} }
} }
...@@ -136,7 +136,7 @@ actor_registry* singleton_manager::get_actor_registry() ...@@ -136,7 +136,7 @@ actor_registry* singleton_manager::get_actor_registry()
uniform_type_info_map* singleton_manager::get_uniform_type_info_map() uniform_type_info_map* singleton_manager::get_uniform_type_info_map()
{ {
return lazy_get(s_uniform_type_info_map); return lazy_get(s_uniform_type_info_map, true);
} }
group_manager* singleton_manager::get_group_manager() group_manager* singleton_manager::get_group_manager()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment