Modify consumer logic for updating provider information
authorYounghyunJoo <yh_.joo@samsung.com>
Mon, 29 Aug 2016 12:56:43 +0000 (21:56 +0900)
committerUze Choi <uzchoi@samsung.com>
Thu, 1 Sep 2016 12:35:38 +0000 (12:35 +0000)
- Add synchronization logic for cache update in NSConsumerInternalTaskController.
- Adapt its synchronization logic, when subscription succeed is checked/updated.

Change-Id: I746a3d3602eab3ac570a6d2ddfcdd4b7dce8e18a
Signed-off-by: YounghyunJoo <yh_.joo@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/11201
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
service/notification/src/consumer/NSConsumerInternalTaskController.c
service/notification/src/consumer/NSConsumerMemoryCache.h

index 505d414798e6d0f796a94aaa86cd975184f59a5c..f05016cec00907e4a56d4ba31a653b535025e6b8 100644 (file)
@@ -317,6 +317,11 @@ void NSConsumerHandleSubscribeSucceed(NSProvider_internal * provider)
     NSCacheList * ProviderCache = *(NSGetProviderCacheList());
 
     NSCacheElement * cacheElement = NSStorageRead(ProviderCache, provider->providerId);
+    NS_VERIFY_NOT_NULL_V(cacheElement);
+
+    pthread_mutex_t * mutex = NSGetCacheMutex();
+    pthread_mutex_lock(mutex);
+
     NS_VERIFY_NOT_NULL_V(cacheElement);
     NSProvider_internal * prov = (NSProvider_internal *)cacheElement->data;
     NSProviderConnectionInfo *infos = prov->connection;
@@ -325,6 +330,8 @@ void NSConsumerHandleSubscribeSucceed(NSProvider_internal * provider)
         infos->isSubscribing = true;
         infos = infos->next;
     }
+
+    pthread_mutex_unlock(mutex);
 }
 
 void NSConsumerHandleRecvProviderChanged(NSMessage * msg)
index 76ab96804d3a89321bb72f2096c457f90b9d0a14..e387570a8e1fa5b0d99ecdd78cf5243bc9cb0847 100644 (file)
@@ -31,6 +31,7 @@ extern "C" {
 #include "NSStorageAdapter.h"
 #include "NSConsumerCommon.h"
 
+pthread_mutex_t * NSGetCacheMutex();
 
 bool NSConsumerCompareIdCacheData(NSCacheType type, void * data, const char * id);
 NSResult NSConsumerCacheWriteMessage(NSCacheList * list, NSCacheElement * newObj);