[Util] macro to wait condition accepted/tizen/unified/20230830.170545
authorJaeyun Jung <jy1210.jung@samsung.com>
Mon, 21 Aug 2023 08:54:37 +0000 (17:54 +0900)
committerjaeyun-jung <39614140+jaeyun-jung@users.noreply.github.com>
Mon, 28 Aug 2023 07:27:05 +0000 (16:27 +0900)
Update macro to wait timed-out condition.

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

index 2d1bc5091bc64735bd16a78684c8c697743be921..640c8bc46ce5f33eb5be97f8f0552bea634417b3 100644 (file)
@@ -298,21 +298,8 @@ nns_edge_queue_wait_pop (nns_edge_queue_h handle, unsigned int timeout,
   *size = 0U;
 
   nns_edge_lock (q);
-  if (q->length == 0U) {
-    if (timeout > 0) {
-      struct timespec ts;
-      struct timeval now;
-
-      gettimeofday (&now, NULL);
-
-      ts.tv_sec = now.tv_sec + timeout / 1000;
-      ts.tv_nsec = now.tv_usec * 1000 + (timeout % 1000) * 1000000;
-
-      nns_edge_cond_timedwait (q, &ts);
-    } else {
-      nns_edge_cond_wait (q);
-    }
-  }
+  if (q->length == 0U)
+    nns_edge_cond_wait_until (q, timeout);
 
   popped = _pop_data (q, false, data, size);
   nns_edge_unlock (q);
index ff43b2d05d87311cc6915bf4f9012615ddc27349..c5484836298aa631dbad527a8ea15e0a4369d667 100644 (file)
@@ -15,7 +15,6 @@
 #define __NNSTREAMER_EDGE_QUEUE_H__
 
 #include <stdbool.h>
-#include <sys/time.h>
 #include "nnstreamer-edge.h"
 
 #ifdef __cplusplus
index 45e499ff6e3174ab98e27a1e47a911accc55f817..30a6f6830dba36b308cdc57d94e9218c82ee27f6 100644 (file)
@@ -20,6 +20,7 @@
 #include <stdbool.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/time.h>
 #include <unistd.h>
 #include <limits.h>
 #include "nnstreamer-edge.h"
@@ -67,7 +68,18 @@ extern "C" {
 #define nns_edge_cond_init(h) do { pthread_cond_init (&(h)->cond, NULL); } while (0)
 #define nns_edge_cond_destroy(h) do { pthread_cond_destroy (&(h)->cond); } while (0)
 #define nns_edge_cond_wait(h) do { pthread_cond_wait (&(h)->cond, &(h)->lock); } while (0)
-#define nns_edge_cond_timedwait(h,t) do { pthread_cond_timedwait (&(h)->cond, &(h)->lock, (t)); } while (0)
+#define nns_edge_cond_wait_until(h,ms) do { \
+    if ((ms) > 0) { \
+      struct timespec ts; \
+      struct timeval now; \
+      gettimeofday (&now, NULL); \
+      ts.tv_sec = now.tv_sec + (ms) / 1000; \
+      ts.tv_nsec = now.tv_usec * 1000 + ((ms) % 1000) * 1000000; \
+      pthread_cond_timedwait (&(h)->cond, &(h)->lock, &ts); \
+    } else { \
+      pthread_cond_wait (&(h)->cond, &(h)->lock); \
+    } \
+  } while (0)
 #define nns_edge_cond_signal(h) do { pthread_cond_signal (&(h)->cond); } while (0)
 
 /**