From: Harry Date: Thu, 22 Mar 2018 13:43:09 +0000 (+0530) Subject: Synchronized observe notification using mutex. X-Git-Tag: submit/tizen/20180404.002721~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F23%2F174223%2F1;p=platform%2Fupstream%2Fiotivity.git Synchronized observe notification using mutex. As InProcClientWrapper class creates separate thread for every obseve callback, There is a chance that more than one thread enter ObserveCache object and trying to modify m_attributes. More over same m_attributes is being passed out or RE layer by const reference, so application is using same member object m_attributes. Mutex allows only one thread to modify m_attributes. https://github.sec.samsung.net/RS7-IOTIVITY/IoTivity/pull/276 (cherry picked from commit c87d0d4b14d22349c3563e7cd316d323d068e2ab) Change-Id: Ibee9b9326e6d7a3be093bc387db70a7c8f9a626d Signed-off-by: Harry Signed-off-by: Amit KS --- diff --git a/service/resource-encapsulation/src/resourceCache/include/ObserveCache.h b/service/resource-encapsulation/src/resourceCache/include/ObserveCache.h index 11b72a6..73ce388 100644 --- a/service/resource-encapsulation/src/resourceCache/include/ObserveCache.h +++ b/service/resource-encapsulation/src/resourceCache/include/ObserveCache.h @@ -73,6 +73,7 @@ namespace OIC RCSResourceAttributes m_attributes; CACHE_STATE m_state; + std::mutex m_cbMutex; DataCacheCB m_reportCB; std::atomic m_isStart; diff --git a/service/resource-encapsulation/src/resourceCache/src/ObserveCache.cpp b/service/resource-encapsulation/src/resourceCache/src/ObserveCache.cpp index 608aa75..2703af7 100644 --- a/service/resource-encapsulation/src/resourceCache/src/ObserveCache.cpp +++ b/service/resource-encapsulation/src/resourceCache/src/ObserveCache.cpp @@ -102,12 +102,13 @@ namespace OIC void ObserveCache::onObserve(const HeaderOptions &, const ResponseStatement & rep, int _result, unsigned int) { + std::lock_guard lock(m_cbMutex); m_state = CACHE_STATE::READY; if (m_attributes == rep.getAttributes() && convertOCResultToSuccess((OCStackResult)_result)) { - return ; + return; } if (m_reportCB)