The foundResource function is called asynchronously, and was written
in a way that was not thread safe. This fix adds a lock and exit logic
so that it works prooperly and only uses the first found curResource
that matches its requirements.
NOTE: This change (author: Erich Keane) is from 01.org.
Change-Id: I984ce1623ff491713ecf5d621f1283ebad33bfef
Signed-Off-by:Sudarshan Prasad<sudarshan.prasad@intel.com>
std::shared_ptr<OCResource> curResource;
static ObserveType OBSERVE_TYPE_TO_USE = ObserveType::Observe;
+std::mutex curResourceLock;
class Light
{
// Callback to found resources
void foundResource(std::shared_ptr<OCResource> resource)
{
+ std::lock_guard<std::mutex> lock(curResourceLock);
if(curResource)
{
std::cout << "Found another resource, ignoring"<<std::endl;
+ return;
}
std::string resourceURI;