From patchwork Fri Jul 31 13:39:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 9088 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 EB7BABD878 for ; Fri, 31 Jul 2020 13:39:57 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B9ACA61EAB; Fri, 31 Jul 2020 15:39:57 +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="Lc1MhkH1"; 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 E0220611A2 for ; Fri, 31 Jul 2020 15:39:54 +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=rZO56G1jUXqkj9NaKsVMgBkSiSxVvWJQQydjtgOydGI=; b=Lc1MhkH1Xa+u7CXv8UYhENYgruO8TwtBvliP3PVjf7CF4aWxy/gDArdF3OEDPyfsCNTO hdhYWAOfRHccfMS6C61yLKw041PKh9uWBLymGsQ2g4q1BDWPVRlMGH1oUyEhdm4GZVbLVN Co6mZVF2wq46bu1WZ3ESUgrvZiEoTBt7A= Received: by filterdrecv-p3iad2-d8cc6d457-vqmvz with SMTP id filterdrecv-p3iad2-d8cc6d457-vqmvz-18-5F241F29-33 2020-07-31 13:39:53.496836441 +0000 UTC m=+156699.076970626 Received: from mail.uajain.com (unknown) by ismtpd0001p1hnd1.sendgrid.net (SG) with ESMTP id p9ZLO7eTSYKmzjEb5kIrCg for ; Fri, 31 Jul 2020 13:39:53.166 +0000 (UTC) From: Umang Jain Date: Fri, 31 Jul 2020 13:39:53 +0000 (UTC) Message-Id: <20200731133947.84258-2-email@uajain.com> In-Reply-To: <20200731133947.84258-1-email@uajain.com> References: <20200731133947.84258-1-email@uajain.com> Mime-Version: 1.0 X-SG-EID: 1Q40EQ7YGir8a9gjSIAdTjhngY657NMk9ckeo4dbHZDiOpywc/L3L9rFqlwE4KPc/mSirh79xX0l6HRHZb2eYOh3j8GimY8FU2cDIu5BK9uo/u0UKfCGuWra26U2h3bDlEbUIjGFk2ET8Ge+vVnCPS/P0zdlLL4BRggwPsGX7JzaF9gLM5pHujKJmnaCPEm9lvOwwwjLj+pfMnEEpk9BllyIZyptbccBfCh6TWaAvcZdKKXREpniq0kMeouKIgKbjvAfd8lOmWANZB2biby2TQ== To: libcamera-devel@lists.libcamera.org Subject: [libcamera-devel] [PATCH v3 1/3] 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 | 30 ++++++++++++++++++++--------- 2 files changed, 23 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..7e318d9 100644 --- a/src/libcamera/thread.cpp +++ b/src/libcamera/thread.cpp @@ -552,25 +552,37 @@ 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 || (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(); } }