mv3d: get the latest in mDfsAsyncQueue
authorTae-Young Chung <ty83.chung@samsung.com>
Mon, 14 Nov 2022 06:44:16 +0000 (15:44 +0900)
committerKwanghoon Son <k.son@samsung.com>
Wed, 14 Dec 2022 06:32:36 +0000 (15:32 +0900)
[Issue type] update

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

index 9bfc05a..dd5cafc 100644 (file)
@@ -70,6 +70,13 @@ Mv3d::~Mv3d()
        }
 
        if (mDfsAsyncQueue) {
+               gpointer base = nullptr;
+               while ((base = g_async_queue_try_pop(mDfsAsyncQueue))) {
+                       auto pItem = static_cast<std::shared_ptr<DfsInputData> *>(base);
+                       auto item = std::move(*pItem);
+                       delete pItem;
+                       item.reset();
+               }
                g_async_queue_unref(mDfsAsyncQueue);
        }
 
@@ -374,6 +381,18 @@ gpointer Mv3d::DfsThreadLoop(gpointer data)
 {
        Mv3d *handle = static_cast<Mv3d *>(data);
        while (handle->mDfsIsLive) {
+               auto queueLength = static_cast<int>(g_async_queue_length(handle->mDfsAsyncQueue));
+               if (queueLength < 0)
+                       continue;
+
+               for (int itemIndex = 0; itemIndex < queueLength; itemIndex++) {
+                       gpointer base = g_async_queue_try_pop(handle->mDfsAsyncQueue);
+                       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;