From patchwork Mon Aug 12 12:46:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 1781 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id EAE2C60E38 for ; Mon, 12 Aug 2019 14:46:49 +0200 (CEST) Received: from pendragon.bb.dnainternet.fi (dfj612yhrgyx302h3jwwy-3.rev.dnainternet.fi [IPv6:2001:14ba:21f5:5b00:ce28:277f:58d7:3ca4]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 86B3C594 for ; Mon, 12 Aug 2019 14:46:49 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1565614009; bh=JL6icfRv59UQAMHOVt8DJGpk6nFLqIeWcf4xWR2Z+kA=; h=From:To:Subject:Date:In-Reply-To:References:From; b=tb/wR2Ip6NXZIX4e4K7xlus0eJ/6QGyDK6FemeUXdDcj0FpuyP5sOQO6ue0dS0S4T 5UzYpR2sGDxDGTah4LOUMZEJx+6U4oC5w6DxlW719+4uAgg0NzmCa++Luwf7r1RVj2 s5tcM3tILws9HqRSZLJ4aDMU+kCMAud/aCJji5fM= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Mon, 12 Aug 2019 15:46:27 +0300 Message-Id: <20190812124642.24287-4-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190812124642.24287-1-laurent.pinchart@ideasonboard.com> References: <20190812124642.24287-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 03/18] libcamera: thread: Support dispatching messages to main thread X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 12 Aug 2019 12:46:50 -0000 Threads contain message queues and dispatch queue messages in their event loop, in Thread::exec(). This mechanism prevents the main thread from dispatching messages as it doesn't run Thread::exec(). Fix this by moving message dispatching from Thread::exec() to EventDispatcher::processEvents(). Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- src/libcamera/event_dispatcher_poll.cpp | 3 +++ src/libcamera/include/thread.h | 3 ++- src/libcamera/thread.cpp | 4 +--- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/libcamera/event_dispatcher_poll.cpp b/src/libcamera/event_dispatcher_poll.cpp index 4f15f3e3269b..281f37bdbb16 100644 --- a/src/libcamera/event_dispatcher_poll.cpp +++ b/src/libcamera/event_dispatcher_poll.cpp @@ -19,6 +19,7 @@ #include #include "log.h" +#include "thread.h" /** * \file event_dispatcher_poll.h @@ -143,6 +144,8 @@ void EventDispatcherPoll::processEvents() { int ret; + Thread::current()->dispatchMessages(); + /* Create the pollfd array. */ std::vector pollfds; pollfds.reserve(notifiers_.size() + 1); diff --git a/src/libcamera/include/thread.h b/src/libcamera/include/thread.h index acae91cb6457..630abb49534f 100644 --- a/src/libcamera/include/thread.h +++ b/src/libcamera/include/thread.h @@ -43,6 +43,8 @@ public: EventDispatcher *eventDispatcher(); void setEventDispatcher(std::unique_ptr dispatcher); + void dispatchMessages(); + protected: int exec(); virtual void run(); @@ -53,7 +55,6 @@ private: void postMessage(std::unique_ptr msg, Object *receiver); void removeMessages(Object *receiver); - void dispatchMessages(); friend class Object; friend class ThreadData; diff --git a/src/libcamera/thread.cpp b/src/libcamera/thread.cpp index 6f86e4a90a05..24422f7b7bd0 100644 --- a/src/libcamera/thread.cpp +++ b/src/libcamera/thread.cpp @@ -212,10 +212,8 @@ int Thread::exec() locker.unlock(); - while (!data_->exit_.load(std::memory_order_acquire)) { - dispatchMessages(); + while (!data_->exit_.load(std::memory_order_acquire)) dispatcher->processEvents(); - } locker.lock();