diff options
author | samanway <samanway@linux-samanway.sa.corp.samsungelectronics.net> | 2020-01-28 22:08:04 +0530 |
---|---|---|
committer | DoHyun Pyun <dh79.pyun@samsung.com> | 2020-02-19 09:10:08 +0900 |
commit | daef13e9901a25656dbea914d2a5bf92a755fc1d (patch) | |
tree | c65b618ba8a441097fcfa04020234f3d26cc3c83 | |
parent | e921b65b421b01c562dacee74614ada071ab02ea (diff) | |
download | iotivity-daef13e9901a25656dbea914d2a5bf92a755fc1d.tar.gz iotivity-daef13e9901a25656dbea914d2a5bf92a755fc1d.tar.bz2 iotivity-daef13e9901a25656dbea914d2a5bf92a755fc1d.zip |
[CONPRO-1555] oneconnect:Core / Application crashed
- In function NSConsumerMsgPushThreadFunc for locking 'msgHandleThread', there could be a
possibility of destruction of the thread running NSConsumerMsgHandleThreadFunc function
and destruction of the mutex as well at the time of locking it
- Hence handled this critical mutex with a global lock
https://github.sec.samsung.net/RS7-IOTIVITY/IoTivity/pull/657
(cherry-picked from 5289e48a0aa9ce007d44cd443dd73cc8f509fcee)
Change-Id: I1892df4276b6ffcb969a91fd23c9f3d9f3c5a959
Signed-off-by: samanway-dey <samanway.dey@samsung.com>
Signed-off-by: DoHyun Pyun <dh79.pyun@samsung.com>
-rw-r--r-- | service/notification/src/consumer/NSConsumerScheduler.c | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/service/notification/src/consumer/NSConsumerScheduler.c b/service/notification/src/consumer/NSConsumerScheduler.c index 9dd920f1c..14adef534 100644 --- a/service/notification/src/consumer/NSConsumerScheduler.c +++ b/service/notification/src/consumer/NSConsumerScheduler.c @@ -45,6 +45,8 @@ #include "NSConsumerMQPlugin.h" #endif +pthread_mutex_t NSConsumerQueueMutex; + void * NSConsumerMsgHandleThreadFunc(void * handle); void * NSConsumerMsgPushThreadFunc(void * data); @@ -92,6 +94,9 @@ NSResult NSConsumerMessageHandlerInit() ret = NSConsumerSystemInit(); NS_VERIFY_NOT_NULL(ret == NS_OK ? (void *) 1 : NULL, NS_ERROR); + NS_LOG(DEBUG, "mutex init"); + pthread_mutex_init(&NSConsumerQueueMutex, NULL); + NS_LOG(DEBUG, "create queue"); queue = NSCreateQueue(); NS_VERIFY_NOT_NULL(queue, NS_ERROR); @@ -118,10 +123,10 @@ NSResult NSConsumerPushEvent(NSTask * task) void NSConsumerMessageHandlerExit() { - NSConsumerListenerTermiate(); NSCancelAllSubscription(); + pthread_mutex_lock(&NSConsumerQueueMutex); NSConsumerThread * thread = *(NSGetMsgHandleThreadHandle()); NSThreadStop(thread); NSSetMsgHandleThreadHandle(NULL); @@ -129,6 +134,8 @@ void NSConsumerMessageHandlerExit() NSConsumerQueue * queue = *(NSGetMsgHandleQueue()); NSDestroyQueue(queue); NSSetMsgHandleQueue(NULL); + pthread_mutex_unlock(&NSConsumerQueueMutex); + pthread_mutex_destroy(&NSConsumerQueueMutex); NSDestroyInternalCachedList(); } @@ -139,7 +146,9 @@ void * NSConsumerMsgHandleThreadFunc(void * threadHandle) NSConsumerQueueObject * obj = NULL; NS_LOG(DEBUG, "create thread for consumer message handle"); + pthread_mutex_lock(&NSConsumerQueueMutex); NSConsumerThread * queueHandleThread = (NSConsumerThread *) threadHandle; + pthread_mutex_unlock(&NSConsumerQueueMutex); NS_VERIFY_NOT_NULL(queueHandleThread, NULL); while (true) @@ -151,18 +160,20 @@ void * NSConsumerMsgHandleThreadFunc(void * threadHandle) continue; } + pthread_mutex_lock(&NSConsumerQueueMutex); if (!queueHandleThread->isStarted && NSIsQueueEmpty(queue)) { + pthread_mutex_unlock(&NSConsumerQueueMutex); NS_LOG(ERROR, "msg handler thread will be terminated"); break; } if (NSIsQueueEmpty(queue)) { + pthread_mutex_unlock(&NSConsumerQueueMutex); usleep(2000); continue; } - NSThreadLock(queueHandleThread); NS_LOG(DEBUG, "msg handler working"); obj = NSPopQueue(queue); @@ -174,7 +185,7 @@ void * NSConsumerMsgHandleThreadFunc(void * threadHandle) } NSThreadUnlock(queueHandleThread); - + pthread_mutex_unlock(&NSConsumerQueueMutex); } return NULL; @@ -186,6 +197,7 @@ void * NSConsumerMsgPushThreadFunc(void * data) NSConsumerQueue * queue = NULL; NS_LOG(DEBUG, "get queueThread handle"); + pthread_mutex_lock(&NSConsumerQueueMutex); NSConsumerThread * msgHandleThread = *(NSGetMsgHandleThreadHandle()); NS_VERIFY_NOT_NULL_WITH_POST_CLEANING(msgHandleThread, NULL, NSOICFree(data)); @@ -219,6 +231,7 @@ void * NSConsumerMsgPushThreadFunc(void * data) } NSThreadUnlock(msgHandleThread); + pthread_mutex_unlock(&NSConsumerQueueMutex); return NULL; } |