新增singleton_manager释放顺序整理, 新增audio_device_manager

This commit is contained in:
2024-02-27 16:25:18 +08:00
parent 8b328cc0d6
commit dc28bf6e0f
8 changed files with 81 additions and 19 deletions

View File

@@ -2,26 +2,39 @@
#include "singleton.h"
bool singleton_initliazer::has_init(singleton* s) {
return std::ranges::find(singletons_, s) != singletons_.end();
}
void singleton_initliazer::init_singleton(singleton* s) {
if (!has_init(s)) {
singletons_.push_back(s);
s->init(*this);
}
}
void singleton_manager::add(singleton* s) {
singletons_.push_back(s);
}
void singleton_manager::init() const {
void singleton_manager::init() {
singleton_initliazer initliazer;
for (const auto s : singletons_) {
s->init(initliazer);
initliazer.singletons_.push_back(s);
initliazer.init_singleton(s);
}
for (const auto s : singletons_) {
s->post_init();
}
singletons_ = initliazer.singletons_;
}
void singleton_manager::release() const {
for (const auto s : singletons_) {
for (int32_t j = singletons_.size() - 1; j >= 0; --j) {
auto s = singletons_[j];
s->begin_release();
}
for (const auto s : singletons_) {
for (int32_t j = singletons_.size() - 1; j >= 0; --j) {
auto s = singletons_[j];
s->release();
}
}