Avoid adding elements to QueueingThread if it's already stopped. 28/204728/1 accepted/tizen/5.0/unified/20190429.011934 submit/tizen_5.0/20190426.041741
authorSenthil Kumar G S <senthil.gs@samsung.com>
Fri, 12 Apr 2019 06:34:12 +0000 (12:04 +0530)
committerDoHyun Pyun <dh79.pyun@samsung.com>
Fri, 26 Apr 2019 04:14:30 +0000 (13:14 +0900)
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 <senthil.gs@samsung.com>
Signed-off-by: DoHyun Pyun <dh79.pyun@samsung.com>
resource/csdk/connectivity/src/caqueueingthread.c

index 0afeed9..ba7b478 100644 (file)
@@ -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);