[Common] wait for thread with lock accepted/tizen/unified/20231213.162138 accepted/tizen/unified/riscv/20231215.050244
authorJaeyun Jung <jy1210.jung@samsung.com>
Fri, 1 Dec 2023 09:04:40 +0000 (18:04 +0900)
committerMyungJoo Ham <myungjoo.ham@samsung.com>
Wed, 6 Dec 2023 10:56:34 +0000 (19:56 +0900)
Add lock to wait for creating new thread for data transfer.

Signed-off-by: Jaeyun Jung <jy1210.jung@samsung.com>
src/libnnstreamer-edge/nnstreamer-edge-internal.c

index c08ceb3b449f7fe060bdc17d97d819949dff18cb..d8da1a424e8e92884cf21a39d645e521079bfa19 100644 (file)
@@ -847,8 +847,11 @@ _nns_edge_send_thread (void *thread_data)
   char *val;
   int ret;
 
+  nns_edge_lock (eh);
   eh->sending = true;
   nns_edge_cond_signal (eh);
+  nns_edge_unlock (eh);
+
   while (eh->sending &&
       NNS_EDGE_ERROR_NONE == nns_edge_queue_wait_pop (eh->send_queue, 0U,
           &data_h, &data_size)) {
@@ -914,6 +917,7 @@ _nns_edge_send_thread (void *thread_data)
 
 /**
  * @brief Create thread to send data.
+ * @note This should be called with lock.
  */
 static int
 _nns_edge_create_send_thread (nns_edge_handle_s * eh)
@@ -921,16 +925,17 @@ _nns_edge_create_send_thread (nns_edge_handle_s * eh)
   int status;
 
   status = pthread_create (&eh->send_thread, NULL, _nns_edge_send_thread, eh);
-  while (!eh->sending) {
-    nns_edge_cond_wait (eh);
-  }
 
   if (status != 0) {
     nns_edge_loge ("Failed to create sender thread.");
     eh->send_thread = 0;
+    eh->sending = false;
     return NNS_EDGE_ERROR_IO;
   }
 
+  /* Wait for starting thread. */
+  nns_edge_cond_wait (eh);
+
   return NNS_EDGE_ERROR_NONE;
 }