summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorUmang Jain <email@uajain.com>2020-07-31 18:14:14 +0000
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2020-07-31 23:33:23 +0300
commit3fe7c1cdb4e14aa4da0681103a33912f962c5cc8 (patch)
tree7e745dd645fe797851773b69a0059cb5b444008f /src
parent6042ded8e7ffb7c2d3bf02cfb5fd25f255abdfa3 (diff)
libcamera: thread: Support selective message dispatch to thread
Extend the current dispatchMessages() to support dispatching of selective messsages according to the Message::Type passed in the function argument. dispatchMessages() can now be called explicitly to force deliver selected type's message to the thread for processing (typically when event loop is not running). Signed-off-by: Umang Jain <email@uajain.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'src')
-rw-r--r--src/libcamera/thread.cpp35
1 files changed, 26 insertions, 9 deletions
diff --git a/src/libcamera/thread.cpp b/src/libcamera/thread.cpp
index d1750d72..87006a9c 100644
--- a/src/libcamera/thread.cpp
+++ b/src/libcamera/thread.cpp
@@ -552,25 +552,42 @@ void Thread::removeMessages(Object *receiver)
}
/**
- * \brief Dispatch all posted messages for this thread
+ * \brief Dispatch posted messages for this thread
+ * \param[in] type The message type
+ *
+ * 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.
*/
-void Thread::dispatchMessages()
+void Thread::dispatchMessages(Message::Type type)
{
MutexLocker locker(data_->messages_.mutex_);
- while (!data_->messages_.list_.empty()) {
- std::unique_ptr<Message> msg = std::move(data_->messages_.list_.front());
- data_->messages_.list_.pop_front();
- if (!msg)
+ std::list<std::unique_ptr<Message>> &messages = data_->messages_.list_;
+
+ for (auto iter = messages.begin(); iter != messages.end(); ) {
+ std::unique_ptr<Message> &msg = *iter;
+
+ if (!msg) {
+ iter = data_->messages_.list_.erase(iter);
+ continue;
+ }
+
+ if (type != Message::Type::None && msg->type() != type) {
+ ++iter;
continue;
+ }
- Object *receiver = msg->receiver_;
- ASSERT(data_ == receiver->thread()->data_);
+ std::unique_ptr<Message> message = std::move(msg);
+ iter = data_->messages_.list_.erase(iter);
+ Object *receiver = message->receiver_;
+ ASSERT(data_ == receiver->thread()->data_);
receiver->pendingMessages_--;
locker.unlock();
- receiver->message(msg.get());
+ receiver->message(message.get());
+ message.reset();
locker.lock();
}
}