From c1005eb119e5b7db07c1bd0c8152cf8cc43664f8 Mon Sep 17 00:00:00 2001 From: "jjack.lee" Date: Mon, 26 Jan 2015 13:59:03 +0900 Subject: [PATCH] Fix problem for multiple api call It is thread issue. So, add lock mechanism. Fix [IOT-263] Change-Id: Ic0fac30b1a4c0c305af607e5caa7c1afd21163b6 Signed-off-by: Jack Lee Reviewed-on: https://gerrit.iotivity.org/gerrit/243 Tested-by: jenkins-iotivity Reviewed-by: Uze Choi (cherry picked from commit 522c05e82f1ccd3ae2cf4b4a63ec414f7ebcb8ce) Reviewed-on: https://gerrit.iotivity.org/gerrit/381 Reviewed-by: Sudarshan Prasad --- service/things-manager/sdk/src/GroupManager.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/service/things-manager/sdk/src/GroupManager.cpp b/service/things-manager/sdk/src/GroupManager.cpp index 777ac08..dcac0dc 100644 --- a/service/things-manager/sdk/src/GroupManager.cpp +++ b/service/things-manager/sdk/src/GroupManager.cpp @@ -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 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); } } -- 2.7.4