26 singletons_manager::singletons_manager()
27 : lst{}, nb_partitions{lst.num_threads()}
30 singletons_manager& singletons_manager::manager(){
31 static singletons_manager x;
35 void singletons_manager::register_new_singleton(singleton_instance_base *p){
36 register_new_singleton(p, manager().lst.this_thread());
39 void singletons_manager::register_new_singleton(singleton_instance_base *p,
size_t ithread){
40 if (p) manager().lst(ithread).push_back(p);
43 void singletons_manager::on_partitions_change(){
44 auto new_nb_partitions = manager().lst.num_threads();
45 auto &nb_partitions = manager().nb_partitions;
46 if (new_nb_partitions > nb_partitions){
47 manager().lst.on_thread_update();
48 nb_partitions = new_nb_partitions;
52 static int level_compare(singleton_instance_base *a, singleton_instance_base *b) {
53 return a->level() < b->level();
56 singletons_manager::~singletons_manager() {
57 for(
size_type i = 0; i != nb_partitions; ++i){
58 std::sort(lst(i).begin(), lst(i).end(), level_compare);
59 for (
auto &&p : lst(i))
delete p;
A simple singleton implementation.
size_t size_type
used as the common size type in the library