From issues-return-96707-archive-asf-public=cust-asf.ponee.io@nifi.apache.org Mon May 4 09:16:20 2020 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by mx-eu-01.ponee.io (Postfix) with SMTP id E1497180608 for ; Mon, 4 May 2020 11:16:19 +0200 (CEST) Received: (qmail 9140 invoked by uid 500); 4 May 2020 09:16:19 -0000 Mailing-List: contact issues-help@nifi.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@nifi.apache.org Delivered-To: mailing list issues@nifi.apache.org Received: (qmail 9130 invoked by uid 99); 4 May 2020 09:16:19 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 04 May 2020 09:16:19 +0000 From: =?utf-8?q?GitBox?= To: issues@nifi.apache.org Subject: =?utf-8?q?=5BGitHub=5D_=5Bnifi-minifi-cpp=5D_arpadboda_commented_on_a_change?= =?utf-8?q?_in_pull_request_=23773=3A_MINIFICPP-1202_-_Extend_interface_and_?= =?utf-8?q?add_new_tests_for_MinifiConcurrentQueue?= Message-ID: <158858377919.26397.6166810121795022878.asfpy@gitbox.apache.org> Date: Mon, 04 May 2020 09:16:19 -0000 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit References: In-Reply-To: arpadboda commented on a change in pull request #773: URL: https://github.com/apache/nifi-minifi-cpp/pull/773#discussion_r419306193 ########## File path: libminifi/include/utils/MinifiConcurrentQueue.h ########## @@ -127,33 +184,58 @@ class ConditionConcurrentQueue : private ConcurrentQueue { using ConcurrentQueue::empty; using ConcurrentQueue::clear; - template void enqueue(Args&&... args) { ConcurrentQueue::enqueue(std::forward(args)...); if (running_) { cv_.notify_one(); } } - + bool dequeueWait(T& out) { std::unique_lock lck(this->mtx_); - cv_.wait(lck, [this, &lck]{ return !running_ || !this->emptyImpl(lck); }); // Only wake up if there is something to return or stopped - return running_ && ConcurrentQueue::tryDequeueImpl(lck, out); + if (!running_) { + return false; + } + cv_.wait(lck, [this, &lck]{ return !running_ || !this->emptyImpl(lck); }); // Only wake up if there is something to return or stopped + return ConcurrentQueue::tryDequeueImpl(lck, out); + } + + template + bool consumeWait(Functor&& fun) { + std::unique_lock lck(this->mtx_); + if (!running_) { Review comment: I wonder why this is any better than the original solutions. It's 3 lines longer, but for what? The original code didn't start waiting for the CV as the predicate was true at the beginning, so immediately returned false, as we this does. Could you explain the rational behind this change? ########## File path: libminifi/include/utils/MinifiConcurrentQueue.h ########## @@ -21,14 +21,49 @@ #include #include #include +#include #include +#include namespace org { namespace apache { namespace nifi { namespace minifi { namespace utils { +namespace detail { Review comment: This is good stuff, but I think it should be in GeneralUtils.h as this is not a concurrentQueue-specific functionality. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: users@infra.apache.org