mirror of
https://github.com/openharmony/windowmanager.git
synced 2026-07-19 17:08:11 -04:00
fix singleton container bug
Signed-off-by: xingyanan <xingyanan2@huawei.com> Change-Id: I071de7383059a842e257d3f364052866a5d1d023 Signed-off-by: xingyanan <xingyanan2@huawei.com>
This commit is contained in:
@@ -43,6 +43,9 @@ public:
|
||||
std::string nameT = __PRETTY_FUNCTION__;
|
||||
nameT = nameT.substr(nameT.find("T = "));
|
||||
nameT = nameT.substr(sizeof("T ="), nameT.length() - sizeof("T = "));
|
||||
if (SingletonContainer::GetInstance().GetSingleton(nameT) == nullptr) {
|
||||
return T::GetInstance();
|
||||
}
|
||||
return *(reinterpret_cast<T*>(SingletonContainer::GetInstance().GetSingleton(nameT)));
|
||||
}
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ void SingletonContainer::AddSingleton(const std::string& name, void* instance)
|
||||
static int32_t nextId = 0;
|
||||
singletonMap[nextId].value = instance;
|
||||
singletonMap[nextId].refCount = 0;
|
||||
WLOGFD("add %{public}s", name.c_str());
|
||||
WLOGFI("add %{public}s", name.c_str());
|
||||
stringMap[name] = nextId++;
|
||||
} else {
|
||||
WLOGFE("add failed: %{public}s", name.c_str());
|
||||
@@ -70,7 +70,7 @@ void SingletonContainer::SetSingleton(const std::string& name, void* instance)
|
||||
if (stringMap.find(name) == stringMap.end()) {
|
||||
AddSingleton(name, instance);
|
||||
} else {
|
||||
WLOGFD("set %{public}s", name.c_str());
|
||||
WLOGFI("set %{public}s", name.c_str());
|
||||
singletonMap[stringMap[name]].value = instance;
|
||||
}
|
||||
}
|
||||
@@ -78,7 +78,7 @@ void SingletonContainer::SetSingleton(const std::string& name, void* instance)
|
||||
void* SingletonContainer::GetSingleton(const std::string& name)
|
||||
{
|
||||
if (stringMap.find(name) == stringMap.end()) {
|
||||
WLOGFD("cannot get %{public}s", name.c_str());
|
||||
WLOGFE("can not get %{public}s", name.c_str());
|
||||
return nullptr;
|
||||
}
|
||||
return singletonMap[stringMap[name]].value;
|
||||
|
||||
Reference in New Issue
Block a user