summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/libcamera/base/thread.h3
-rw-r--r--src/libcamera/base/thread.cpp21
2 files changed, 15 insertions, 9 deletions
diff --git a/include/libcamera/base/thread.h b/include/libcamera/base/thread.h
index 3cbf6398..b9284c2c 100644
--- a/include/libcamera/base/thread.h
+++ b/include/libcamera/base/thread.h
@@ -48,7 +48,8 @@ public:
EventDispatcher *eventDispatcher();
- void dispatchMessages(Message::Type type = Message::Type::None);
+ void dispatchMessages(Message::Type type = Message::Type::None,
+ Object *receiver = nullptr);
protected:
int exec();
diff --git a/src/libcamera/base/thread.cpp b/src/libcamera/base/thread.cpp
index 646ad3cb..d8fe0d69 100644
--- a/src/libcamera/base/thread.cpp
+++ b/src/libcamera/base/thread.cpp
@@ -604,10 +604,12 @@ void Thread::removeMessages(Object *receiver)
/**
* \brief Dispatch posted messages for this thread
* \param[in] type The message type
+ * \param[in] receiver The receiver whose messages to dispatch
*
- * This function immediately dispatches all the messages previously posted for
- * this thread with postMessage() that match the message \a type. If the \a type
- * is Message::Type::None, all messages are dispatched.
+ * This function immediately dispatches all the messages of the given \a type
+ * previously posted to this thread for the \a receiver with postMessage(). If
+ * the \a type is Message::Type::None, all messages types are dispatched. If the
+ * \a receiver is null, messages to all receivers are dispatched.
*
* Messages shall only be dispatched from the current thread, typically within
* the thread from the run() function. Calling this function outside of the
@@ -617,7 +619,7 @@ void Thread::removeMessages(Object *receiver)
* same thread from an object's message handler. It guarantees delivery of
* messages in the order they have been posted in all cases.
*/
-void Thread::dispatchMessages(Message::Type type)
+void Thread::dispatchMessages(Message::Type type, Object *receiver)
{
ASSERT(data_ == ThreadData::current());
@@ -634,6 +636,9 @@ void Thread::dispatchMessages(Message::Type type)
if (type != Message::Type::None && msg->type() != type)
continue;
+ if (receiver && receiver != msg->receiver_)
+ continue;
+
/*
* Move the message, setting the entry in the list to null. It
* will cause recursive calls to ignore the entry, and the erase
@@ -641,12 +646,12 @@ void Thread::dispatchMessages(Message::Type type)
*/
std::unique_ptr<Message> message = std::move(msg);
- Object *receiver = message->receiver_;
- ASSERT(data_ == receiver->thread()->data_);
- receiver->pendingMessages_--;
+ Object *messageReceiver = message->receiver_;
+ ASSERT(data_ == messageReceiver->thread()->data_);
+ messageReceiver->pendingMessages_--;
locker.unlock();
- receiver->message(message.get());
+ messageReceiver->message(message.get());
message.reset();
locker.lock();
}