[Connect] flag to check sending thread
authorJaeyun <jy1210.jung@samsung.com>
Tue, 3 Jan 2023 10:33:00 +0000 (19:33 +0900)
committerjaeyun-jung <39614140+jaeyun-jung@users.noreply.github.com>
Fri, 6 Jan 2023 03:00:21 +0000 (12:00 +0900)
1. Add flag to check sending thread.
2. Init data ptr and size in the queue.

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

index 29e490dfad778e30d7a922336fdb8552a0b0e5d5..f19a74aaf1427f955297f5ffc5e88d2dc098de70 100644 (file)
@@ -66,6 +66,7 @@ typedef struct
   pthread_t listener_thread;
 
   /* thread and queue to send data */
+  bool sending;
   nns_edge_queue_h send_queue;
   pthread_t send_thread;
 
@@ -813,7 +814,14 @@ _nns_edge_send_thread (void *thread_data)
   char *val;
   int ret;
 
-  while (nns_edge_queue_wait_pop (eh->send_queue, 0U, &data_h, &data_size)) {
+  eh->sending = true;
+  while (eh->sending &&
+      nns_edge_queue_wait_pop (eh->send_queue, 0U, &data_h, &data_size)) {
+    if (!eh->sending) {
+      nns_edge_data_destroy (data_h);
+      break;
+    }
+
     /* Send data to destination */
     switch (eh->connect_type) {
       case NNS_EDGE_CONNECT_TYPE_TCP:
@@ -859,6 +867,8 @@ _nns_edge_send_thread (void *thread_data)
     }
     nns_edge_data_destroy (data_h);
   }
+  eh->sending = false;
+
   return NULL;
 }
 
@@ -1231,6 +1241,7 @@ nns_edge_create_handle (const char *id, nns_edge_connect_type_e connect_type,
   eh->broker_h = NULL;
   eh->connections = NULL;
   eh->listening = false;
+  eh->sending = false;
   eh->listener_fd = -1;
   nns_edge_metadata_create (&eh->metadata);
   nns_edge_queue_create (&eh->send_queue);
@@ -1382,6 +1393,7 @@ nns_edge_release_handle (nns_edge_h edge_h)
   eh->send_queue = NULL;
 
   if (eh->send_thread) {
+    eh->sending = false;
     pthread_join (eh->send_thread, NULL);
     eh->send_thread = 0;
   }
index ea806c123f849b1803e3dd4bd363c9a37b43c427..4a3fcb88ac71911209991e4fd6cc51fdffb164db 100644 (file)
@@ -262,6 +262,10 @@ nns_edge_queue_pop (nns_edge_queue_h handle, void **data, nns_size_t * size)
     return false;
   }
 
+  /* init data */
+  *data = NULL;
+  *size = 0U;
+
   nns_edge_lock (q);
   popped = _pop_data (q, false, data, size);
   nns_edge_unlock (q);
@@ -294,6 +298,10 @@ nns_edge_queue_wait_pop (nns_edge_queue_h handle, unsigned int timeout,
     return false;
   }
 
+  /* init data */
+  *data = NULL;
+  *size = 0U;
+
   nns_edge_lock (q);
   if (q->length == 0U) {
     if (timeout > 0) {