Modify discoveryMap's cancel logic in order to keep data intergrity.
authordoil.kwon <doil.kwon@samsung.com>
Thu, 24 Sep 2015 08:20:12 +0000 (17:20 +0900)
committerMadan Lanka <lanka.madan@samsung.com>
Fri, 25 Sep 2015 05:12:32 +0000 (05:12 +0000)
- lock guard mutex before erasing data in discoveryMap.

Change-Id: I71f2a63797e417148a670a1d9e880d0c2a6515d4
Signed-off-by: doil.kwon <doil.kwon@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/3029
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
service/resource-encapsulation/include/RCSDiscoveryManagerImpl.h
service/resource-encapsulation/src/resourceClient/RCSDiscoveryManager.cpp
service/resource-encapsulation/src/resourceClient/RCSDiscoveryManagerImpl.cpp

index 391544a8537bb3de3da5f2901fb29f7a82119004..e582ea4f760866cd53025c6fedc7060d74ff2c7d 100644 (file)
@@ -141,7 +141,7 @@ namespace OIC
                 std::unique_ptr<RCSDiscoveryManager::DiscoveryTask> startDiscovery(const RCSAddress& address,
                         const std::string& relativeURI,const std::string& resourceType,
                         RCSDiscoveryManager::ResourceDiscoveredCallback cb);
-
+                void cancel(ID);
             private:
 
                 /**
index 540302368d34960284e0a86a220d074857165957..29c794a301cc8731fe49de58b703012148d98af6 100755 (executable)
@@ -68,7 +68,7 @@ namespace OIC {
         }
 
         void RCSDiscoveryManager::DiscoveryTask::cancel(){
-            RCSDiscoveryManagerImpl::getInstance()->m_discoveryMap.erase(m_id);
+            RCSDiscoveryManagerImpl::getInstance()->cancel(m_id);
         }
     }
 }
index 0305d3e26ad29c41608a20a49a51f26ea33dd01c..bbb29e25ddd281095eefaeff1dd1cfb8994d6758 100755 (executable)
@@ -60,7 +60,7 @@ namespace OIC
         void RCSDiscoveryManagerImpl::findCallback(std::shared_ptr< PrimitiveResource > resource,
             RCSDiscoveryManagerImpl::ID discoverID)
         {
-            std::unique_lock<std::mutex> lock(m_mutex);
+            std::lock_guard<std::mutex> lock(m_mutex);
 
            if(!isDuplicatedCallback(resource,discoverID))
             {
@@ -142,7 +142,7 @@ namespace OIC
 
         void RCSDiscoveryManagerImpl::pollingCallback(unsigned int /*msg*/)
         {
-            std::unique_lock<std::mutex> lock(m_mutex);
+            std::lock_guard<std::mutex> lock(m_mutex);
             for(auto it = m_discoveryMap.begin(); it != m_discoveryMap.end(); ++it)
             {
                 OIC::Service::discoverResource(it->second.m_address,it->second.m_relativeUri+ "?rt="
@@ -156,7 +156,7 @@ namespace OIC
         {
             if(ret == OC_STACK_OK || ret == OC_STACK_RESOURCE_CREATED || ret == OC_STACK_RESOURCE_DELETED)
             {
-                std::unique_lock<std::mutex> lock(m_mutex);
+                std::lock_guard<std::mutex> lock(m_mutex);
                 for(auto it = m_discoveryMap.begin(); it != m_discoveryMap.end(); ++it)
                 {
                     if(!it->second.m_isReceivedFindCallback)
@@ -170,7 +170,7 @@ namespace OIC
 
         RCSDiscoveryManagerImpl::ID RCSDiscoveryManagerImpl::createId()
         {
-            std::unique_lock<std::mutex> lock(m_mutex);
+            std::lock_guard<std::mutex> lock(m_mutex);
             if(s_uniqueId<LIMITNUMBER)
             {
                  s_uniqueId++;
@@ -190,5 +190,11 @@ namespace OIC
 
             return RESETNUMBER;
         }
+
+        void RCSDiscoveryManagerImpl::cancel(ID id)
+        {
+            std::lock_guard<std::mutex> lock(m_mutex);
+            m_discoveryMap.erase(id);
+        }
     }
 }