30 singletons_manager::singletons_manager()
31 : lst{}, nb_partitions{lst.num_threads()}
34 singletons_manager& singletons_manager::manager(){
35 static singletons_manager x;
39 void singletons_manager::register_new_singleton(singleton_instance_base *p){
40 register_new_singleton(p, manager().lst.this_thread());
43 void singletons_manager::register_new_singleton(singleton_instance_base *p,
size_t ithread){
44 if (p) manager().lst(ithread).push_back(p);
47 void singletons_manager::on_partitions_change(){
48 auto new_nb_partitions = manager().lst.num_threads();
49 auto &nb_partitions = manager().nb_partitions;
50 if (new_nb_partitions > nb_partitions){
51 manager().lst.on_thread_update();
52 nb_partitions = new_nb_partitions;
56 static int level_compare(singleton_instance_base *a, singleton_instance_base *b) {
57 return a->level() < b->level();
60 singletons_manager::~singletons_manager() {
61 for(
size_type i = 0; i != nb_partitions; ++i){
62 std::sort(lst(i).begin(), lst(i).end(), level_compare);
63 for (
auto &&p : lst(i))
delete p;