Fix problem for multiple api call
authorjjack.lee <jjack.lee@samsung.com>
Mon, 26 Jan 2015 04:59:03 +0000 (13:59 +0900)
committerUze Choi <uzchoi@samsung.com>
Wed, 4 Feb 2015 08:26:31 +0000 (08:26 +0000)
It is thread issue. So, add lock mechanism.
Fix [IOT-263]

Change-Id: Ic0fac30b1a4c0c305af607e5caa7c1afd21163b6
Signed-off-by: Jack Lee <jjack.lee@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/243
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
service/things-manager/sdk/src/GroupManager.cpp

index ceb2686..a0fd31d 100644 (file)
@@ -41,6 +41,8 @@ std::map< std::vector< std::string >, CandidateCallback > candidateRequest;
 std::map< std::vector< std::string >, CandidateCallback > candidateRequestForTimer;
 std::map< std::string, std::map< std::string, std::shared_ptr< OCResource > > > rtForResourceList;
 std::vector< std::string > allFoundResourceTypes;
+std::mutex callbackLock;
+
 
 template< typename T >
 bool IsSubset(std::vector< T > full, std::vector< T > sub)
@@ -150,6 +152,7 @@ GroupManager::~GroupManager(void)
 void GroupManager::findPreparedRequest(
         std::map< std::vector< std::string >, CandidateCallback > &request)
 {
+    std::lock_guard<std::mutex> lock(callbackLock);
     std::vector< std::shared_ptr< OCResource > > resources;
 
     for (auto it = request.begin(); it != request.end();)
@@ -157,14 +160,13 @@ void GroupManager::findPreparedRequest(
 
         if (IsSubset(allFoundResourceTypes, it->first))
         {
-            //std::cout << "IS SUBSET !!! \n";
-
             for (unsigned int i = 0; i < it->first.size(); ++i)
             {
 
                 for (auto secondIt = rtForResourceList[it->first.at(i)].begin();
                         secondIt != rtForResourceList[it->first.at(i)].end(); ++secondIt)
                 {
+                    //insert resource related to request
                     resources.push_back(secondIt->second);
                 }
             }