From a66e5ca8c61093c5b927bb072c595560fd5d5d38 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Mon, 12 Aug 2019 03:35:35 +0300 Subject: libcamera: thread: Support dispatching messages to main thread MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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(-) (limited to 'src') diff --git a/src/libcamera/event_dispatcher_poll.cpp b/src/libcamera/event_dispatcher_poll.cpp index 4f15f3e3..281f37bd 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 acae91cb..630abb49 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 6f86e4a9..24422f7b 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(); -- cgit v1.2.1