From 77409b9260f5a06dd6eec1a46ecb105a758d9e53 Mon Sep 17 00:00:00 2001 From: Harry Date: Thu, 22 Mar 2018 19:13:09 +0530 Subject: [PATCH] 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 --- .../resource-encapsulation/src/resourceCache/include/ObserveCache.h | 1 + service/resource-encapsulation/src/resourceCache/src/ObserveCache.cpp | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) 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) -- 2.7.4