Update parts of getting the latest in mDfsAsyncQueue 13/284813/2
authorTae-Young Chung <ty83.chung@samsung.com>
Mon, 28 Nov 2022 07:08:58 +0000 (16:08 +0900)
committerTae-Young Chung <ty83.chung@samsung.com>
Wed, 30 Nov 2022 03:38:42 +0000 (12:38 +0900)
[Issue type] update

This commit is manually patched from https://review.tizen.org/gerrit/#/c/platform/core/api/mediavision/+/284812/
to avoid conflict.

Change-Id: I11dfca071a0f126f6e2e2fd2f2df54a68d98761f
Signed-off-by: Tae-Young Chung <ty83.chung@samsung.com>
mv_3d/3d/src/Mv3d.cpp

index 813044c..e98eee0 100644 (file)
@@ -29,6 +29,7 @@ using namespace open3d;
 
 #include "Mv3d.h"
 
+#define MV_3D_TIMEOUT_SEC 3
 namespace mediavision
 {
 namespace mv3d
@@ -410,21 +411,24 @@ namespace mv3d
        {
                Mv3d *handle = static_cast<Mv3d*>(data);
                while(handle->mDfsIsLive) {
-                       auto queueLength = static_cast<int>(g_async_queue_length(handle->mDfsAsyncQueue));
-                       if (queueLength < 0)
-                               continue;
+                       auto base = g_async_queue_timeout_pop(handle->mDfsAsyncQueue, MV_3D_TIMEOUT_SEC * G_TIME_SPAN_SECOND);
+                       if (!base) {
+                               LOGW("Timeout! no more items. Exit thread");
+                               break;
+                       }
+
+                       auto queueRemaining = static_cast<int>(g_async_queue_length(handle->mDfsAsyncQueue));
+                       LOGI("%d remaining", queueRemaining);
 
-                       for (int itemIndex = 0; itemIndex < queueLength; itemIndex++) {
-                               gpointer base = g_async_queue_try_pop(handle->mDfsAsyncQueue);
+                       while (queueRemaining > 0) {
                                auto pItem = static_cast<std::shared_ptr<DfsInputData> *>(base);
                                auto item = std::move(*pItem);
                                delete pItem;
                                item.reset();
-                       }
 
-                       gpointer base = g_async_queue_try_pop(handle->mDfsAsyncQueue);
-                       if (!base) {
-                               continue;
+                               base = g_async_queue_pop(handle->mDfsAsyncQueue);
+                               queueRemaining--;
+                               LOGI("%d remaining", queueRemaining);
                        }
 
                        auto pInput = static_cast<std::shared_ptr<DfsInputData>*>(base);