From patchwork Sat Aug 17 15:20:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 1821 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 0AB15600F9 for ; Sat, 17 Aug 2019 17:21:14 +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 A4F9E98C for ; Sat, 17 Aug 2019 17:21:13 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1566055273; bh=jWaQHPYiVdXbmTXAPOfMiZFcMdagOGG4maW9rwlfRGg=; h=From:To:Subject:Date:In-Reply-To:References:From; b=RUsJ0yJ3WrPL1MQGNkIFD+zUreQQuCEtwmspGmL3J3cS3/N4Zd9UUtPBogHLUbIa6 xm+0Oi9aLhyD1baJbTM2J5HLJSYY9t/c9wbjURSM3dpetzifAO1K6W2w1Uv8IZPj/z h+WkxrXWCgGM9lNLGdnZxoqdMjpBdLe+aPxyj2y0= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Sat, 17 Aug 2019 18:20:49 +0300 Message-Id: <20190817152104.10834-4-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190817152104.10834-1-laurent.pinchart@ideasonboard.com> References: <20190817152104.10834-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 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: Sat, 17 Aug 2019 15:21:14 -0000 Threads contain message queues and dispatch queued 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: Jacopo Mondi 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();