From e97c076c283be9a2da8f95bec76aeeb23d729e00 Mon Sep 17 00:00:00 2001 From: YounghyunJoo Date: Mon, 29 Aug 2016 21:56:43 +0900 Subject: [PATCH] Modify consumer logic for updating provider information - 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 Reviewed-on: https://gerrit.iotivity.org/gerrit/11201 Tested-by: jenkins-iotivity Reviewed-by: Uze Choi --- .../notification/src/consumer/NSConsumerInternalTaskController.c | 7 +++++++ service/notification/src/consumer/NSConsumerMemoryCache.h | 1 + 2 files changed, 8 insertions(+) diff --git a/service/notification/src/consumer/NSConsumerInternalTaskController.c b/service/notification/src/consumer/NSConsumerInternalTaskController.c index 505d414..f05016c 100644 --- a/service/notification/src/consumer/NSConsumerInternalTaskController.c +++ b/service/notification/src/consumer/NSConsumerInternalTaskController.c @@ -318,6 +318,11 @@ void NSConsumerHandleSubscribeSucceed(NSProvider_internal * provider) 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; while(infos) @@ -325,6 +330,8 @@ void NSConsumerHandleSubscribeSucceed(NSProvider_internal * provider) infos->isSubscribing = true; infos = infos->next; } + + pthread_mutex_unlock(mutex); } void NSConsumerHandleRecvProviderChanged(NSMessage * msg) diff --git a/service/notification/src/consumer/NSConsumerMemoryCache.h b/service/notification/src/consumer/NSConsumerMemoryCache.h index 76ab968..e387570 100644 --- a/service/notification/src/consumer/NSConsumerMemoryCache.h +++ b/service/notification/src/consumer/NSConsumerMemoryCache.h @@ -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); -- 2.7.4