{"id":9088,"url":"https://patchwork.libcamera.org/api/patches/9088/?format=json","web_url":"https://patchwork.libcamera.org/patch/9088/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20200731133947.84258-2-email@uajain.com>","date":"2020-07-31T13:39:53","name":"[libcamera-devel,v3,1/3] libcamera: thread: Support selective message dispatch to thread","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"f11a13c18b63a7831280b6078b375cf3f30ecc2f","submitter":{"id":1,"url":"https://patchwork.libcamera.org/api/people/1/?format=json","name":"Umang Jain","email":"email@uajain.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/9088/mbox/","series":[{"id":1168,"url":"https://patchwork.libcamera.org/api/series/1168/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1168","date":"2020-07-31T13:39:52","name":"Add Object::deleteLater() support","version":3,"mbox":"https://patchwork.libcamera.org/series/1168/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/9088/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/9088/checks/","tags":{},"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 EB7BABD878\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 31 Jul 2020 13:39:57 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id B9ACA61EAB;\n\tFri, 31 Jul 2020 15:39:57 +0200 (CEST)","from o1.f.az.sendgrid.net (o1.f.az.sendgrid.net [208.117.55.132])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id E0220611A2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 31 Jul 2020 15:39:54 +0200 (CEST)","by filterdrecv-p3iad2-d8cc6d457-vqmvz with SMTP id\n\tfilterdrecv-p3iad2-d8cc6d457-vqmvz-18-5F241F29-33\n\t2020-07-31 13:39:53.496836441 +0000 UTC m=+156699.076970626","from mail.uajain.com (unknown)\n\tby ismtpd0001p1hnd1.sendgrid.net (SG) with ESMTP id\n\tp9ZLO7eTSYKmzjEb5kIrCg for <libcamera-devel@lists.libcamera.org>;\n\tFri, 31 Jul 2020 13:39:53.166 +0000 (UTC)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=uajain.com header.i=@uajain.com\n\theader.b=\"Lc1MhkH1\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=uajain.com;\n\th=from:subject:in-reply-to:references:mime-version:to:cc:\n\tcontent-transfer-encoding:content-type;\n\ts=s1; bh=rZO56G1jUXqkj9NaKsVMgBkSiSxVvWJQQydjtgOydGI=;\n\tb=Lc1MhkH1Xa+u7CXv8UYhENYgruO8TwtBvliP3PVjf7CF4aWxy/gDArdF3OEDPyfsCNTO\n\thdhYWAOfRHccfMS6C61yLKw041PKh9uWBLymGsQ2g4q1BDWPVRlMGH1oUyEhdm4GZVbLVN\n\tCo6mZVF2wq46bu1WZ3ESUgrvZiEoTBt7A=","From":"Umang Jain <email@uajain.com>","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\n\tselective message dispatch to thread","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>","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Extend the current dispatchMessages() to support dispatching of\nselective messsages according to the Message::Type passed in\nthe function argument. dispatchMessages() can now be called\nexplicitly to force deliver selected type's message to the\nthread for processing (typically when event loop is not\nrunning).\n\nSigned-off-by: Umang Jain <email@uajain.com>\n---\n include/libcamera/internal/thread.h |  3 ++-\n src/libcamera/thread.cpp            | 30 ++++++++++++++++++++---------\n 2 files changed, 23 insertions(+), 10 deletions(-)","diff":"diff --git a/include/libcamera/internal/thread.h b/include/libcamera/internal/thread.h\nindex 7b59e58..f6367a8 100644\n--- a/include/libcamera/internal/thread.h\n+++ b/include/libcamera/internal/thread.h\n@@ -14,6 +14,7 @@\n \n #include <libcamera/signal.h>\n \n+#include \"libcamera/internal/message.h\"\n #include \"libcamera/internal/utils.h\"\n \n namespace libcamera {\n@@ -47,7 +48,7 @@ public:\n \tEventDispatcher *eventDispatcher();\n \tvoid setEventDispatcher(std::unique_ptr<EventDispatcher> dispatcher);\n \n-\tvoid dispatchMessages();\n+\tvoid dispatchMessages(Message::Type type = Message::Type::None);\n \n protected:\n \tint exec();\ndiff --git a/src/libcamera/thread.cpp b/src/libcamera/thread.cpp\nindex d1750d7..7e318d9 100644\n--- a/src/libcamera/thread.cpp\n+++ b/src/libcamera/thread.cpp\n@@ -552,25 +552,37 @@ void Thread::removeMessages(Object *receiver)\n }\n \n /**\n- * \\brief Dispatch all posted messages for this thread\n+ * \\brief Dispatch posted messages for this thread\n+ * \\param[in] type The message type\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  */\n-void Thread::dispatchMessages()\n+void Thread::dispatchMessages(Message::Type type)\n {\n \tMutexLocker locker(data_->messages_.mutex_);\n \n-\twhile (!data_->messages_.list_.empty()) {\n-\t\tstd::unique_ptr<Message> msg = std::move(data_->messages_.list_.front());\n-\t\tdata_->messages_.list_.pop_front();\n-\t\tif (!msg)\n+\tstd::list<std::unique_ptr<Message>> &messages = data_->messages_.list_;\n+\n+\tfor (auto iter = messages.begin(); iter != messages.end(); ) {\n+\t\tstd::unique_ptr<Message> &msg = *iter;\n+\n+\t\tif (!msg || (type != Message::Type::None && msg->type() != type)) {\n+\t\t\t++iter;\n \t\t\tcontinue;\n+\t\t}\n \n-\t\tObject *receiver = msg->receiver_;\n-\t\tASSERT(data_ == receiver->thread()->data_);\n+\t\tstd::unique_ptr<Message> message = std::move(msg);\n+\t\titer = data_->messages_.list_.erase(iter);\n \n+\t\tObject *receiver = message->receiver_;\n+\t\tASSERT(data_ == receiver->thread()->data_);\n \t\treceiver->pendingMessages_--;\n \n \t\tlocker.unlock();\n-\t\treceiver->message(msg.get());\n+\t\treceiver->message(message.get());\n+\t\tmessage.reset();\n \t\tlocker.lock();\n \t}\n }\n","prefixes":["libcamera-devel","v3","1/3"]}