modify mutex logic in ProviderMemoryCache.
authorjaesick.shin <jaesick.shin@samsung.com>
Tue, 26 Jul 2016 11:45:40 +0000 (20:45 +0900)
committerUze Choi <uzchoi@samsung.com>
Wed, 27 Jul 2016 05:25:08 +0000 (05:25 +0000)
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 <jaesick.shin@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/9725
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
Tested-by: Uze Choi <uzchoi@samsung.com>
service/notification/src/provider/NSProviderInterface.c
service/notification/src/provider/cache/linux/NSProviderMemoryCache.c
service/notification/src/provider/cache/linux/NSProviderMemoryCache.h

index a216072..ae29be0 100644 (file)
@@ -82,7 +82,11 @@ NSResult NSStartProvider(NSAccessPolicy policy, NSSubscribeRequestCallback subsc
 void NSSetList()\r
 {\r
     NS_LOG(DEBUG, "NSSetList - IN");\r
-    pthread_mutex_init(&NSCacheMutex, NULL);\r
+\r
+    pthread_mutexattr_init(&NSCacheMutexAttr);\r
+    int pthreadResult = pthread_mutexattr_settype(&NSCacheMutexAttr, PTHREAD_MUTEX_RECURSIVE);\r
+    pthread_mutex_init(&NSCacheMutex, &NSCacheMutexAttr);\r
+\r
     NSInitSubscriptionList();\r
     NSInitMessageList();\r
     NS_LOG(DEBUG, "NSSetList - OUT");\r
index 66d88f9..ca80395 100755 (executable)
@@ -34,7 +34,6 @@ NSCacheList * NSStorageCreate()
     newList->head = newList->tail = NULL;\r
 \r
     pthread_mutex_unlock(&NSCacheMutex);\r
-\r
     NS_LOG(DEBUG, "NSCacheCreate");\r
 \r
     return newList;\r
@@ -86,9 +85,7 @@ NSResult NSCacheUpdateSubScriptionState(NSCacheList * list, char * id, bool stat
         return NS_ERROR;\r
     }\r
 \r
-    pthread_mutex_unlock(&NSCacheMutex);\r
     NSCacheElement * it = NSStorageRead(list, id);\r
-    pthread_mutex_lock(&NSCacheMutex);\r
 \r
     if (it)\r
     {\r
@@ -143,10 +140,7 @@ NSResult NSStorageWrite(NSCacheList * list, NSCacheElement * newObj)
         NS_LOG(DEBUG, "Type is SUBSCRIBER");\r
 \r
         NSCacheSubData * subData = (NSCacheSubData *) newObj->data;\r
-\r
-        pthread_mutex_unlock(&NSCacheMutex);\r
         NSCacheElement * it = NSStorageRead(list, subData->id);\r
-        pthread_mutex_lock(&NSCacheMutex);\r
 \r
         if (it)\r
         {\r
@@ -204,10 +198,8 @@ NSResult NSStorageWrite(NSCacheList * list, NSCacheElement * newObj)
         NS_LOG(DEBUG, "Type is MESSAGE");\r
 \r
         NSCacheMsgData * msgData = (NSCacheMsgData *) newObj->data;\r
-\r
-        pthread_mutex_unlock(&NSCacheMutex);\r
         NSCacheElement * it = NSStorageRead(list, msgData->id);\r
-        pthread_mutex_lock(&NSCacheMutex);\r
+\r
         if (it)\r
         {\r
             NSCacheMsgData * itData = (NSCacheMsgData *) it->data;\r
index 43cca9c..cc02053 100755 (executable)
@@ -43,5 +43,6 @@ NSResult NSCacheUpdateSubScriptionState(NSCacheList *, char *, bool);
 NSResult NSProviderDeleteSubDataFromObId(NSCacheList * list, OCObservationId id);\r
 \r
 pthread_mutex_t NSCacheMutex;\r
+pthread_mutexattr_t NSCacheMutexAttr;\r
 \r
 #endif /* _NS_PROVIDER_CACHEADAPTER__H_ */\r