From c04ac05a42d644464490feecf905cfd4aaf64b76 Mon Sep 17 00:00:00 2001 From: Senthil Kumar G S Date: Fri, 12 Apr 2019 12:04:12 +0530 Subject: [PATCH] Avoid adding elements to QueueingThread if it's already stopped. Backgraund:- -> If a thread has called CAQueueingThreadStop(), it signals the condition variable to wake up the CAQueueingThreadBaseRoutine. -> After signaling, it waits on the same condition variable to wait for the completion of CAQueueingThreadBaseRoutine. -> CAQueueingThreadBaseRoutine will finish its current task and signals the condition variable. -> CAQueueingThreadStop should wake up upon signal and return back to caller. Issue:- -> CAQueueingThreadAddData also signals the condition variable which can wake up the thread that called CAQueueingThreadStop. -> CAQueueingThreadStop returns back to caller assuming that the CAQueueingThreadBaseRoutine has stopped. But it could still be running. https://github.sec.samsung.net/RS7-IOTIVITY/IoTivity/pull/475 (cherry picked from 069d45ab60a7cd90d451aea4fdcf9d03dda421de) Change-Id: Ib64d83a2560f31d44cb33148eba4f8b4e9a1289e Signed-off-by: Senthil Kumar G S Signed-off-by: DoHyun Pyun --- resource/csdk/connectivity/src/caqueueingthread.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/resource/csdk/connectivity/src/caqueueingthread.c b/resource/csdk/connectivity/src/caqueueingthread.c index 0afeed9..ba7b478 100644 --- a/resource/csdk/connectivity/src/caqueueingthread.c +++ b/resource/csdk/connectivity/src/caqueueingthread.c @@ -237,6 +237,16 @@ CAResult_t CAQueueingThreadAddData(CAQueueingThread_t *thread, void *data, uint3 // mutex lock oc_mutex_lock(thread->threadMutex); + // thread stop + if (thread->isStop) + { + // mutex unlock + oc_mutex_unlock(thread->threadMutex); + + OICFree(message); + return CA_STATUS_FAILED; + } + // add thread data into list u_queue_add_element(thread->dataQueue, message); -- 2.7.4