diff options
author | Hwankyu Jhun <h.jhun@samsung.com> | 2019-01-16 10:25:31 +0900 |
---|---|---|
committer | Hwankyu Jhun <h.jhun@samsung.com> | 2019-01-16 10:25:31 +0900 |
commit | 55915352e12b41ce7489378b4c7fee13841d4f7a (patch) | |
tree | 93f003c556306e0d72551c310401648609749047 | |
parent | 804cfb753a5dd4780951d02a956625de97e339b7 (diff) | |
download | preference-sandbox/hjhun/devel.tar.gz preference-sandbox/hjhun/devel.tar.bz2 preference-sandbox/hjhun/devel.zip |
Fix mutex locksandbox/hjhun/devel
Change-Id: I18d4ba8563b61495bf7da0827928c57d25a26646
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
-rw-r--r-- | src/preference.cc | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/preference.cc b/src/preference.cc index ecc063d..29276fe 100644 --- a/src/preference.cc +++ b/src/preference.cc @@ -61,6 +61,7 @@ class PrefExt : public Preference, public Preference::IEventListener { } int AddWatch(const char* key, preference_changed_cb cb, void* user_data) { + std::lock_guard<std::recursive_mutex> lock(GetMutex()); if (Preference::AddWatch(key) < 0) return -1; @@ -71,6 +72,7 @@ class PrefExt : public Preference, public Preference::IEventListener { } int RemoveWatch(const char* key) { + std::lock_guard<std::recursive_mutex> lock(GetMutex()); auto i = map_.find(key); if (i == map_.end()) return -1; @@ -80,10 +82,6 @@ class PrefExt : public Preference, public Preference::IEventListener { return 0; } - std::recursive_mutex& GetMutex() const { - return mutex_; - } - private: void Init() { Listen(this); @@ -95,12 +93,17 @@ class PrefExt : public Preference, public Preference::IEventListener { disposed_ = true; } + std::recursive_mutex& GetMutex() const { + return mutex_; + } + void OnCreated(const std::string& key) override { SECURE_LOGD("key(%s)", key.c_str()); } void OnUpdated(const std::string& key) override { SECURE_LOGD("key(%s)", key.c_str()); + std::lock_guard<std::recursive_mutex> lock(GetMutex()); auto i = map_.find(key); if (i != map_.end()) { auto& ev = i->second; @@ -330,7 +333,6 @@ API int preference_set_changed_cb(const char* key, return PREFERENCE_ERROR_NO_KEY; } - std::lock_guard<std::recursive_mutex> lock(pref.GetMutex()); int r = pref.AddWatch(key, callback, user_data); if (r < 0) { _E("Failed to add watch"); @@ -353,7 +355,6 @@ API int preference_unset_changed_cb(const char* key) { return PREFERENCE_ERROR_NO_KEY; } - std::lock_guard<std::recursive_mutex> lock(pref.GetMutex()); int r = pref.RemoveWatch(key); if (r < 0) { _E("Failed to remove watch"); |