mirror of
https://git.libcamera.org/libcamera/libcamera.git
synced 2025-07-22 16:15:09 +03:00
libcamera: thread: Support dispatching messages to main thread
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 <laurent.pinchart@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
This commit is contained in:
parent
391b184fc5
commit
a66e5ca8c6
3 changed files with 6 additions and 4 deletions
|
@ -19,6 +19,7 @@
|
|||
#include <libcamera/timer.h>
|
||||
|
||||
#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<struct pollfd> pollfds;
|
||||
pollfds.reserve(notifiers_.size() + 1);
|
||||
|
|
|
@ -43,6 +43,8 @@ public:
|
|||
EventDispatcher *eventDispatcher();
|
||||
void setEventDispatcher(std::unique_ptr<EventDispatcher> dispatcher);
|
||||
|
||||
void dispatchMessages();
|
||||
|
||||
protected:
|
||||
int exec();
|
||||
virtual void run();
|
||||
|
@ -53,7 +55,6 @@ private:
|
|||
|
||||
void postMessage(std::unique_ptr<Message> msg, Object *receiver);
|
||||
void removeMessages(Object *receiver);
|
||||
void dispatchMessages();
|
||||
|
||||
friend class Object;
|
||||
friend class ThreadData;
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue