Merge branch 'master' of gitee.com:yxlyhzx/applications_settings_s30055321

This commit is contained in:
侯志雄 2024-11-19 16:22:25 +08:00
commit 9532f2b037

View File

@ -35,7 +35,6 @@ namespace OHOS {
namespace Settings {
std::map<std::string, sptr<SettingsObserver>> g_observerMap;
std::mutex g_observerMapMutex;
bool g_observerFlag = false;
SettingsObserver::~SettingsObserver()
{
@ -46,13 +45,23 @@ namespace Settings {
this->cbInfo = nullptr;
}
bool IsExistObserver(SettingsObserver* settingsObserver) {
std::lock_guard<std::mutex> lockGuard(g_observerMapMutex);
for (auto it = g_observerMap.begin(); it != g_observerMap.end(); ++it) {
if (&(*(it->second)) == settingsObserver) {
return true;
}
}
return false;
}
int OnChangeAsync(uv_loop_s* loop, uv_work_t *work)
{
int ret = uv_queue_work(loop, work, [](uv_work_t *work) {},
[](uv_work_t *work, int status) {
SETTING_LOG_INFO("n_s_o_c_a");
SettingsObserver* settingsObserver = reinterpret_cast<SettingsObserver*>(work->data);
if (!g_observerFlag || settingsObserver == nullptr || settingsObserver->cbInfo == nullptr ||
if (!IsExistObserver(settingsObserver) || settingsObserver == nullptr || settingsObserver->cbInfo == nullptr ||
settingsObserver->toBeDelete) {
SETTING_LOG_ERROR("uv_work: cbInfo invalid.");
delete work;
@ -190,7 +199,6 @@ namespace Settings {
std::string strUri = GetStageUriStr(callbackInfo->tableName, GetObserverIdStr(), callbackInfo->key);
OHOS::Uri uri(strUri);
g_observerFlag = true;
sptr<SettingsObserver> settingsObserver = sptr<SettingsObserver>
(new (std::nothrow)SettingsObserver(callbackInfo));
g_observerMap[callbackInfo->key] = settingsObserver;
@ -253,7 +261,6 @@ namespace Settings {
dataShareHelper->UnregisterObserver(uri, g_observerMap[key]);
dataShareHelper->Release();
g_observerMap[key]->toBeDelete = true;
g_observerFlag = false;
g_observerMap[key] = nullptr;
g_observerMap.erase(key);