From patchwork Fri Jul 31 18:14:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 9119 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id D5FC1BD86F for ; Fri, 31 Jul 2020 18:14:18 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A15D561EEF; Fri, 31 Jul 2020 20:14:17 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=uajain.com header.i=@uajain.com header.b="NTk0kvq3"; dkim-atps=neutral Received: from o1.f.az.sendgrid.net (o1.f.az.sendgrid.net [208.117.55.132]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id EEE28611A2 for ; Fri, 31 Jul 2020 20:14:15 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=uajain.com; h=from:subject:in-reply-to:references:mime-version:to:cc: content-transfer-encoding:content-type; s=s1; bh=YBXjP0n0lj5BCprVeWF7WmtypCWAldJAIa3SQ0eIJ6o=; b=NTk0kvq3Fo4w1tn9VPcMgJRsZ8qpEgZN299loTSbcJHwRpS0Dr8Xmjs7wG0DQ9DZz2of UKDsdJckY4m38s3px8PJIQIeYv5zT0oYmSLenIO1nev25gPt0owrXwQdENs4NBFw/tenBX tn5kdZHISBr6pT/Yz01HzkhULsN5vQsZE= Received: by filterdrecv-p3mdw1-7ff865655c-svvjh with SMTP id filterdrecv-p3mdw1-7ff865655c-svvjh-19-5F245F76-23 2020-07-31 18:14:14.634886421 +0000 UTC m=+172681.736483684 Received: from mail.uajain.com (unknown) by ismtpd0004p1maa1.sendgrid.net (SG) with ESMTP id r6JYpAVDSvCRRpNU_9H40Q Fri, 31 Jul 2020 18:14:14.242 +0000 (UTC) From: Umang Jain Date: Fri, 31 Jul 2020 18:14:14 +0000 (UTC) Message-Id: <20200731181410.99892-2-email@uajain.com> In-Reply-To: <20200731181410.99892-1-email@uajain.com> References: <20200731181410.99892-1-email@uajain.com> Mime-Version: 1.0 X-SG-EID: 1Q40EQ7YGir8a9gjSIAdTjhngY657NMk9ckeo4dbHZDiOpywc/L3L9rFqlwE4KPcIgOyDPOiX995eQdp4XFd3MB3kKT368qXzPWOoATU15gwFH1GX3Qhzp4UW2Y1Up/mNVFGoWyp0D1uU2FcX/ObcDnR2GbHI+CA3pXo6kcRfJksVy4ehV5v0XVOHD/o+BTUusOJ8DVu/K9O8VMDNHsL5NWPO9tEEHWVO+O9n8UMycXlhcTdlZInhjlZIGoqbRWblmwBohQ4p9ltxY7KNk1fiA== To: libcamera-devel@lists.libcamera.org Subject: [libcamera-devel] [PATCH v4 1/4] libcamera: thread: Support selective message dispatch to thread X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Extend the current dispatchMessages() to support dispatching of selective messsages according to the Message::Type passed in the function argument. dispatchMessages() can now be called explicitly to force deliver selected type's message to the thread for processing (typically when event loop is not running). Signed-off-by: Umang Jain Reviewed-by: Laurent Pinchart --- include/libcamera/internal/thread.h | 3 ++- src/libcamera/thread.cpp | 35 +++++++++++++++++++++-------- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/include/libcamera/internal/thread.h b/include/libcamera/internal/thread.h index 7b59e58..f6367a8 100644 --- a/include/libcamera/internal/thread.h +++ b/include/libcamera/internal/thread.h @@ -14,6 +14,7 @@ #include +#include "libcamera/internal/message.h" #include "libcamera/internal/utils.h" namespace libcamera { @@ -47,7 +48,7 @@ public: EventDispatcher *eventDispatcher(); void setEventDispatcher(std::unique_ptr dispatcher); - void dispatchMessages(); + void dispatchMessages(Message::Type type = Message::Type::None); protected: int exec(); diff --git a/src/libcamera/thread.cpp b/src/libcamera/thread.cpp index d1750d7..87006a9 100644 --- a/src/libcamera/thread.cpp +++ b/src/libcamera/thread.cpp @@ -552,25 +552,42 @@ void Thread::removeMessages(Object *receiver) } /** - * \brief Dispatch all posted messages for this thread + * \brief Dispatch posted messages for this thread + * \param[in] type The message type + * + * This function immediately dispatches all the messages previously posted for + * this thread with postMessage() that match the message \a type. If the \a type + * is Message::Type::None, all messages are dispatched. */ -void Thread::dispatchMessages() +void Thread::dispatchMessages(Message::Type type) { MutexLocker locker(data_->messages_.mutex_); - while (!data_->messages_.list_.empty()) { - std::unique_ptr msg = std::move(data_->messages_.list_.front()); - data_->messages_.list_.pop_front(); - if (!msg) + std::list> &messages = data_->messages_.list_; + + for (auto iter = messages.begin(); iter != messages.end(); ) { + std::unique_ptr &msg = *iter; + + if (!msg) { + iter = data_->messages_.list_.erase(iter); + continue; + } + + if (type != Message::Type::None && msg->type() != type) { + ++iter; continue; + } - Object *receiver = msg->receiver_; - ASSERT(data_ == receiver->thread()->data_); + std::unique_ptr message = std::move(msg); + iter = data_->messages_.list_.erase(iter); + Object *receiver = message->receiver_; + ASSERT(data_ == receiver->thread()->data_); receiver->pendingMessages_--; locker.unlock(); - receiver->message(msg.get()); + receiver->message(message.get()); + message.reset(); locker.lock(); } }