[{"id":33485,"web_url":"https://patchwork.libcamera.org/comment/33485/","msgid":"<20250226000546.GC21362@pendragon.ideasonboard.com>","date":"2025-02-26T00:05:46","subject":"Re: [PATCH v3 4/6] libcamera: base: thread: Support dispatching for\n\ta specific receiver","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Milan,\n\nThank you for the patch.\n\nOn Tue, Feb 25, 2025 at 04:06:10PM +0100, Milan Zamazal wrote:\n> The Thread::dispatchMessage() function supports filtering messages based\n> on their type. It can be useful to also dispatch only messages posted\n> for a specific receiver. Add an optional receiver argument to the\n> dispatchMessage() function to do so. When set to null (the default\n> value), the behaviour of the function is not changed.\n> \n> This facility is actually used in followup patches.\n> \n> Signed-off-by: Milan Zamazal <mzamazal@redhat.com>\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> ---\n>  include/libcamera/base/thread.h |  3 ++-\n>  src/libcamera/base/thread.cpp   | 21 +++++++++++++--------\n>  2 files changed, 15 insertions(+), 9 deletions(-)\n> \n> diff --git a/include/libcamera/base/thread.h b/include/libcamera/base/thread.h\n> index 3cbf6398..b9284c2c 100644\n> --- a/include/libcamera/base/thread.h\n> +++ b/include/libcamera/base/thread.h\n> @@ -48,7 +48,8 @@ public:\n>  \n>  \tEventDispatcher *eventDispatcher();\n>  \n> -\tvoid dispatchMessages(Message::Type type = Message::Type::None);\n> +\tvoid dispatchMessages(Message::Type type = Message::Type::None,\n> +\t\t\t      Object *receiver = nullptr);\n>  \n>  protected:\n>  \tint exec();\n> diff --git a/src/libcamera/base/thread.cpp b/src/libcamera/base/thread.cpp\n> index 319bfda9..4de356c7 100644\n> --- a/src/libcamera/base/thread.cpp\n> +++ b/src/libcamera/base/thread.cpp\n> @@ -604,10 +604,12 @@ void Thread::removeMessages(Object *receiver)\n>  /**\n>   * \\brief Dispatch posted messages for this thread\n>   * \\param[in] type The message type\n> + * \\param[in] receiver The receiver whose messages to dispatch\n>   *\n> - * This function immediately dispatches all the messages previously posted for\n> - * this thread with postMessage() that match the message \\a type. If the \\a type\n> - * is Message::Type::None, all messages are dispatched.\n> + * This function immediately dispatches all the messages of the given \\a type\n> + * previously posted to this thread for the \\a receiver with postMessage(). If\n> + * the \\a type is Message::Type::None, all messages types are dispatched. If the\n> + * \\a receiver is null, messages to all receivers are dispatched.\n>   *\n>   * Messages shall only be dispatched from the current thread, typically within\n>   * the thread from the run() function. Calling this function outside of the\n> @@ -617,7 +619,7 @@ void Thread::removeMessages(Object *receiver)\n>   * same thread from an object's message handler. It guarantees delivery of\n>   * messages in the order they have been posted in all cases.\n>   */\n> -void Thread::dispatchMessages(Message::Type type)\n> +void Thread::dispatchMessages(Message::Type type, Object *receiver)\n>  {\n>  \tASSERT(data_ == ThreadData::current());\n>  \n> @@ -634,6 +636,9 @@ void Thread::dispatchMessages(Message::Type type)\n>  \t\tif (type != Message::Type::None && msg->type() != type)\n>  \t\t\tcontinue;\n>  \n> +\t\tif (receiver && receiver != msg->receiver_)\n> +\t\t\tcontinue;\n> +\n>  \t\t/*\n>  \t\t * Move the message, setting the entry in the list to null. It\n>  \t\t * will cause recursive calls to ignore the entry, and the erase\n> @@ -641,12 +646,12 @@ void Thread::dispatchMessages(Message::Type type)\n>  \t\t */\n>  \t\tstd::unique_ptr<Message> message = std::move(msg);\n>  \n> -\t\tObject *receiver = message->receiver_;\n> -\t\tASSERT(data_ == receiver->thread()->data_);\n> -\t\treceiver->pendingMessages_--;\n> +\t\tObject *messageReceiver = message->receiver_;\n> +\t\tASSERT(data_ == messageReceiver->thread()->data_);\n> +\t\tmessageReceiver->pendingMessages_--;\n>  \n>  \t\tlocker.unlock();\n> -\t\treceiver->message(message.get());\n> +\t\tmessageReceiver->message(message.get());\n>  \t\tmessage.reset();\n>  \t\tlocker.lock();\n>  \t}","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 83060BF415\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 26 Feb 2025 00:06:09 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id A27FD6873D;\n\tWed, 26 Feb 2025 01:06:08 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 114B16872B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 26 Feb 2025 01:06:06 +0100 (CET)","from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi\n\t[81.175.209.231])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 222036A6;\n\tWed, 26 Feb 2025 01:04:38 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"jBTdbdEm\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1740528278;\n\tbh=V/lWt4JcIJf076mGaRRPreugjGS2p2zX0wFDQty36Ps=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=jBTdbdEmeFwB52VCFMxkxJ61kC8A8kan7sc5gcGXBz/qKv9Dh8Xxv8Gh0QcPzV8Kn\n\t/0d96mTR++Q9HEJbtvqm3kNPF/pE55uxS/kQ8wRwT54LJdYiabWCYVqfla4xopvQ2U\n\ti5QNdE2UWPnWn/hNamE6n9aJQm1/lr1xZ20RjQ9s=","Date":"Wed, 26 Feb 2025 02:05:46 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Milan Zamazal <mzamazal@redhat.com>","Cc":"libcamera-devel@lists.libcamera.org,\n\tStanislaw Gruszka <stanislaw.gruszka@linux.intel.com>,\n\tKieran Bingham <kieran.bingham@ideasonboard.com>","Subject":"Re: [PATCH v3 4/6] libcamera: base: thread: Support dispatching for\n\ta specific receiver","Message-ID":"<20250226000546.GC21362@pendragon.ideasonboard.com>","References":"<20250225150614.20195-1-mzamazal@redhat.com>\n\t<20250225150614.20195-5-mzamazal@redhat.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20250225150614.20195-5-mzamazal@redhat.com>","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":33516,"web_url":"https://patchwork.libcamera.org/comment/33516/","msgid":"<174086980862.3864332.6420712182286922547@ping.linuxembedded.co.uk>","date":"2025-03-01T22:56:48","subject":"Re: [PATCH v3 4/6] libcamera: base: thread: Support dispatching for\n\ta specific receiver","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Milan Zamazal (2025-02-25 15:06:10)\n> The Thread::dispatchMessage() function supports filtering messages based\n> on their type. It can be useful to also dispatch only messages posted\n> for a specific receiver. Add an optional receiver argument to the\n> dispatchMessage() function to do so. When set to null (the default\n> value), the behaviour of the function is not changed.\n> \n> This facility is actually used in followup patches.\n> \n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> Signed-off-by: Milan Zamazal <mzamazal@redhat.com>\n> ---\n>  include/libcamera/base/thread.h |  3 ++-\n>  src/libcamera/base/thread.cpp   | 21 +++++++++++++--------\n>  2 files changed, 15 insertions(+), 9 deletions(-)\n> \n> diff --git a/include/libcamera/base/thread.h b/include/libcamera/base/thread.h\n> index 3cbf6398..b9284c2c 100644\n> --- a/include/libcamera/base/thread.h\n> +++ b/include/libcamera/base/thread.h\n> @@ -48,7 +48,8 @@ public:\n>  \n>         EventDispatcher *eventDispatcher();\n>  \n> -       void dispatchMessages(Message::Type type = Message::Type::None);\n> +       void dispatchMessages(Message::Type type = Message::Type::None,\n> +                             Object *receiver = nullptr);\n>  \n>  protected:\n>         int exec();\n> diff --git a/src/libcamera/base/thread.cpp b/src/libcamera/base/thread.cpp\n> index 319bfda9..4de356c7 100644\n> --- a/src/libcamera/base/thread.cpp\n> +++ b/src/libcamera/base/thread.cpp\n> @@ -604,10 +604,12 @@ void Thread::removeMessages(Object *receiver)\n>  /**\n>   * \\brief Dispatch posted messages for this thread\n>   * \\param[in] type The message type\n> + * \\param[in] receiver The receiver whose messages to dispatch\n>   *\n> - * This function immediately dispatches all the messages previously posted for\n> - * this thread with postMessage() that match the message \\a type. If the \\a type\n> - * is Message::Type::None, all messages are dispatched.\n> + * This function immediately dispatches all the messages of the given \\a type\n> + * previously posted to this thread for the \\a receiver with postMessage(). If\n> + * the \\a type is Message::Type::None, all messages types are dispatched. If the\n> + * \\a receiver is null, messages to all receivers are dispatched.\n>   *\n>   * Messages shall only be dispatched from the current thread, typically within\n>   * the thread from the run() function. Calling this function outside of the\n> @@ -617,7 +619,7 @@ void Thread::removeMessages(Object *receiver)\n>   * same thread from an object's message handler. It guarantees delivery of\n>   * messages in the order they have been posted in all cases.\n>   */\n> -void Thread::dispatchMessages(Message::Type type)\n> +void Thread::dispatchMessages(Message::Type type, Object *receiver)\n>  {\n>         ASSERT(data_ == ThreadData::current());\n>  \n> @@ -634,6 +636,9 @@ void Thread::dispatchMessages(Message::Type type)\n>                 if (type != Message::Type::None && msg->type() != type)\n>                         continue;\n>  \n> +               if (receiver && receiver != msg->receiver_)\n> +                       continue;\n> +\n>                 /*\n>                  * Move the message, setting the entry in the list to null. It\n>                  * will cause recursive calls to ignore the entry, and the erase\n> @@ -641,12 +646,12 @@ void Thread::dispatchMessages(Message::Type type)\n>                  */\n>                 std::unique_ptr<Message> message = std::move(msg);\n>  \n> -               Object *receiver = message->receiver_;\n> -               ASSERT(data_ == receiver->thread()->data_);\n> -               receiver->pendingMessages_--;\n> +               Object *messageReceiver = message->receiver_;\n> +               ASSERT(data_ == messageReceiver->thread()->data_);\n> +               messageReceiver->pendingMessages_--;\n>  \n>                 locker.unlock();\n> -               receiver->message(message.get());\n> +               messageReceiver->message(message.get());\n>                 message.reset();\n>                 locker.lock();\n>         }\n> -- \n> 2.48.1\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 72C52C3263\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSat,  1 Mar 2025 22:56:54 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 90C9568779;\n\tSat,  1 Mar 2025 23:56:53 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id AC711614EB\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat,  1 Mar 2025 23:56:51 +0100 (CET)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 39F91520;\n\tSat,  1 Mar 2025 23:55:21 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"SElYrcDh\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1740869721;\n\tbh=/VOZ1ERzzAzDhONO3flYUqKMdv7pfbvtgScg1Bnp4go=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=SElYrcDh3EeyNI8SIvESlGXKcCBF1b3roIHCOgREIQ0hmzJJinyA7J9c06xTwCsg5\n\tCzz6MnyYyfJuQWOHW8Ryq2AVkS7hMs+kFfw+0eBNM4moWUS+ydiIapj5v0WBbfREh9\n\tT9G9TP4A0tqZy2F+kgy8Ty6Jm9rU3XPHGFAcZ4ZI=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20250225150614.20195-5-mzamazal@redhat.com>","References":"<20250225150614.20195-1-mzamazal@redhat.com>\n\t<20250225150614.20195-5-mzamazal@redhat.com>","Subject":"Re: [PATCH v3 4/6] libcamera: base: thread: Support dispatching for\n\ta specific receiver","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"Milan Zamazal <mzamazal@redhat.com>,\n\tStanislaw Gruszka <stanislaw.gruszka@linux.intel.com>,\n\tLaurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Milan Zamazal <mzamazal@redhat.com>, libcamera-devel@lists.libcamera.org","Date":"Sat, 01 Mar 2025 22:56:48 +0000","Message-ID":"<174086980862.3864332.6420712182286922547@ping.linuxembedded.co.uk>","User-Agent":"alot/0.10","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]