From 84d41ca88a209276896787e8d4f35325cb9fcf27 Mon Sep 17 00:00:00 2001 From: Dale Phurrough Date: Tue, 14 Mar 2023 14:35:27 +0100 Subject: [PATCH] deprecate thread unsafe isClosed() in DataInputQueue, DataOutputQueue - partial fix luxonis/depthai-core#520 --- include/depthai/device/DataQueue.hpp | 8 ++++++-- src/device/DataQueue.cpp | 8 ++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/include/depthai/device/DataQueue.hpp b/include/depthai/device/DataQueue.hpp index 607282333..f0c020e42 100644 --- a/include/depthai/device/DataQueue.hpp +++ b/include/depthai/device/DataQueue.hpp @@ -43,8 +43,10 @@ class DataOutputQueue { /** * Check whether queue is closed + * + * @warning This function is thread-unsafe and may return incorrect values. */ - bool isClosed() const; + [[deprecated("thread-unsafe and may return incorrect values")]] bool isClosed() const; /** * Closes the queue and the underlying thread @@ -355,8 +357,10 @@ class DataInputQueue { /** * Check whether queue is closed + * + * @warning This function is thread-unsafe and may return incorrect values. */ - bool isClosed() const; + [[deprecated("thread-unsafe and may return incorrect values")]] bool isClosed() const; /** * Closes the queue and the underlying thread diff --git a/src/device/DataQueue.cpp b/src/device/DataQueue.cpp index 31d4e3807..5bf4ffcf5 100644 --- a/src/device/DataQueue.cpp +++ b/src/device/DataQueue.cpp @@ -83,6 +83,10 @@ DataOutputQueue::DataOutputQueue(const std::shared_ptr conn, co }); } +// BUGBUG this function is thread-unsafe. The idea of "isClosed" is ephemerial and +// since there is no mutex lock, its state is outdated and invalid even before +// the logical NOT in this function. This calculated boolean then continues to degrade +// in validity as it is returned by value to the caller bool DataOutputQueue::isClosed() const { return !running; } @@ -220,6 +224,10 @@ DataInputQueue::DataInputQueue( }); } +// BUGBUG this function is thread-unsafe. The idea of "isClosed" is ephemerial and +// since there is no mutex lock, its state is outdated and invalid even before +// the logical NOT in this function. This calculated boolean then continues to degrade +// in validity as it is returned by value to the caller bool DataInputQueue::isClosed() const { return !running; }