Change queue of the sending thread
authorgichan <gichan2.jang@samsung.com>
Wed, 4 Jan 2023 05:45:48 +0000 (14:45 +0900)
committerjaeyun-jung <39614140+jaeyun-jung@users.noreply.github.com>
Fri, 6 Jan 2023 04:31:45 +0000 (13:31 +0900)
 - Release send queue after the send thread is finished.
 - Add new function to clear the data in the queue.

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

index 31fd8fce4997fbdb1291445d01cb72a50a769175..8eef0dc7689c90de768c41cfd3bd725498351e0b 100644 (file)
@@ -1389,14 +1389,14 @@ nns_edge_release_handle (nns_edge_h edge_h)
   eh->user_data = NULL;
   eh->broker_h = NULL;
 
-  nns_edge_queue_destroy (eh->send_queue);
-  eh->send_queue = NULL;
-
+  nns_edge_queue_clear (eh->send_queue);
   if (eh->send_thread) {
     eh->sending = false;
     pthread_join (eh->send_thread, NULL);
     eh->send_thread = 0;
   }
+  nns_edge_queue_destroy (eh->send_queue);
+  eh->send_queue = NULL;
 
   if (eh->listener_thread) {
     eh->listening = false;
index 90dc8d0c755bafa70035ab206c693eced72975b1..8f978e3c7dd6c96c3dc4771f59c2b67edbd673d9 100644 (file)
@@ -324,3 +324,27 @@ nns_edge_queue_wait_pop (nns_edge_queue_h handle, unsigned int timeout,
 
   return (popped && *data != NULL);
 }
+
+/**
+ * @brief Clear all data in the queue.
+ * @note When this function is called, nns_edge_queue_wait_pop will stop the waiting.
+ */
+bool
+nns_edge_queue_clear (nns_edge_queue_h handle)
+{
+  nns_edge_queue_s *q = (nns_edge_queue_s *) handle;
+
+  if (!q) {
+    nns_edge_loge ("[Queue] Invalid param, queue is null.");
+    return false;
+  }
+
+  nns_edge_lock (q);
+  nns_edge_cond_signal (q);
+
+  while (q->length > 0U)
+    _pop_data (q, true, NULL, NULL);
+
+  nns_edge_unlock (q);
+  return true;
+}
index 7bc199436fdcebe13456965ff7972601992a0b0d..ff43b2d05d87311cc6915bf4f9012615ddc27349 100644 (file)
@@ -92,6 +92,14 @@ bool nns_edge_queue_pop (nns_edge_queue_h handle, void **data, nns_size_t *size)
  */
 bool nns_edge_queue_wait_pop (nns_edge_queue_h handle, unsigned int timeout, void **data, nns_size_t *size);
 
+/**
+ * @brief Stop waiting for new data and clear all data in the queue.
+ * @param[in] handle The queue handle.
+ * @return true on success.
+ * @note When this function is called, nns_edge_queue_wait_pop will stop the waiting.
+ */
+bool nns_edge_queue_clear (nns_edge_queue_h handle);
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */