Synchronized observe notification using mutex. 50/174250/1
authorHarry <h.marappa@samsung.com>
Thu, 22 Mar 2018 13:43:09 +0000 (19:13 +0530)
committerAmit KS <amit.s12@samsung.com>
Thu, 29 Mar 2018 08:56:14 +0000 (14:26 +0530)
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: I54c80a6ea9751b8d9f78720121bee949d336ce4f
Signed-off-by: Harry <h.marappa@samsung.com>
Signed-off-by: Amit KS <amit.s12@samsung.com>
service/resource-encapsulation/src/resourceCache/include/ObserveCache.h
service/resource-encapsulation/src/resourceCache/src/ObserveCache.cpp

index 11b72a6..73ce388 100644 (file)
@@ -73,6 +73,7 @@ namespace OIC
                 RCSResourceAttributes m_attributes;
                 CACHE_STATE m_state;
 
+                std::mutex m_cbMutex;
                 DataCacheCB m_reportCB;
 
                 std::atomic<bool> m_isStart;
index 608aa75..2703af7 100644 (file)
@@ -102,12 +102,13 @@ namespace OIC
         void ObserveCache::onObserve(const HeaderOptions &,
                        const ResponseStatement & rep, int _result, unsigned int)
         {
+            std::lock_guard<std::mutex> lock(m_cbMutex);
             m_state = CACHE_STATE::READY;
 
             if (m_attributes == rep.getAttributes() &&
                     convertOCResultToSuccess((OCStackResult)_result))
             {
-                return ;
+                return;
             }
 
             if (m_reportCB)