From: jaesick.shin Date: Tue, 26 Jul 2016 11:45:40 +0000 (+0900) Subject: modify mutex logic in ProviderMemoryCache. X-Git-Tag: 1.2.0+RC1~52^2~111 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0b6f32a6eafbd468af2c2d0afa5150f041f2bf9b;p=platform%2Fupstream%2Fiotivity.git modify mutex logic in ProviderMemoryCache. It was to modify the part that can be preempted contexts in ProviderMemoryCache. Solve that problem using mutexAttribute. Change-Id: Ibaa1bc34348b819f5f2bbd0d1ffd95fa95f905c4 Signed-off-by: jaesick.shin Reviewed-on: https://gerrit.iotivity.org/gerrit/9725 Tested-by: jenkins-iotivity Reviewed-by: Uze Choi Tested-by: Uze Choi --- diff --git a/service/notification/src/provider/NSProviderInterface.c b/service/notification/src/provider/NSProviderInterface.c index a216072..ae29be0 100644 --- a/service/notification/src/provider/NSProviderInterface.c +++ b/service/notification/src/provider/NSProviderInterface.c @@ -82,7 +82,11 @@ NSResult NSStartProvider(NSAccessPolicy policy, NSSubscribeRequestCallback subsc void NSSetList() { NS_LOG(DEBUG, "NSSetList - IN"); - pthread_mutex_init(&NSCacheMutex, NULL); + + pthread_mutexattr_init(&NSCacheMutexAttr); + int pthreadResult = pthread_mutexattr_settype(&NSCacheMutexAttr, PTHREAD_MUTEX_RECURSIVE); + pthread_mutex_init(&NSCacheMutex, &NSCacheMutexAttr); + NSInitSubscriptionList(); NSInitMessageList(); NS_LOG(DEBUG, "NSSetList - OUT"); diff --git a/service/notification/src/provider/cache/linux/NSProviderMemoryCache.c b/service/notification/src/provider/cache/linux/NSProviderMemoryCache.c index 66d88f9..ca80395 100755 --- a/service/notification/src/provider/cache/linux/NSProviderMemoryCache.c +++ b/service/notification/src/provider/cache/linux/NSProviderMemoryCache.c @@ -34,7 +34,6 @@ NSCacheList * NSStorageCreate() newList->head = newList->tail = NULL; pthread_mutex_unlock(&NSCacheMutex); - NS_LOG(DEBUG, "NSCacheCreate"); return newList; @@ -86,9 +85,7 @@ NSResult NSCacheUpdateSubScriptionState(NSCacheList * list, char * id, bool stat return NS_ERROR; } - pthread_mutex_unlock(&NSCacheMutex); NSCacheElement * it = NSStorageRead(list, id); - pthread_mutex_lock(&NSCacheMutex); if (it) { @@ -143,10 +140,7 @@ NSResult NSStorageWrite(NSCacheList * list, NSCacheElement * newObj) NS_LOG(DEBUG, "Type is SUBSCRIBER"); NSCacheSubData * subData = (NSCacheSubData *) newObj->data; - - pthread_mutex_unlock(&NSCacheMutex); NSCacheElement * it = NSStorageRead(list, subData->id); - pthread_mutex_lock(&NSCacheMutex); if (it) { @@ -204,10 +198,8 @@ NSResult NSStorageWrite(NSCacheList * list, NSCacheElement * newObj) NS_LOG(DEBUG, "Type is MESSAGE"); NSCacheMsgData * msgData = (NSCacheMsgData *) newObj->data; - - pthread_mutex_unlock(&NSCacheMutex); NSCacheElement * it = NSStorageRead(list, msgData->id); - pthread_mutex_lock(&NSCacheMutex); + if (it) { NSCacheMsgData * itData = (NSCacheMsgData *) it->data; diff --git a/service/notification/src/provider/cache/linux/NSProviderMemoryCache.h b/service/notification/src/provider/cache/linux/NSProviderMemoryCache.h index 43cca9c..cc02053 100755 --- a/service/notification/src/provider/cache/linux/NSProviderMemoryCache.h +++ b/service/notification/src/provider/cache/linux/NSProviderMemoryCache.h @@ -43,5 +43,6 @@ NSResult NSCacheUpdateSubScriptionState(NSCacheList *, char *, bool); NSResult NSProviderDeleteSubDataFromObId(NSCacheList * list, OCObservationId id); pthread_mutex_t NSCacheMutex; +pthread_mutexattr_t NSCacheMutexAttr; #endif /* _NS_PROVIDER_CACHEADAPTER__H_ */