[libcamera-devel] [PATCH] libcamera: base: thread: Prevent messages to thread without an event loop

Laurent Pinchart laurent.pinchart at ideasonboard.com
Mon Jun 27 18:46:12 CEST 2022


A message posted to an object bound to a thread without an event loop
will never get delivered. This indicates a bug in the caller, and
materializes in ways that can be hard to debug, such as a signal never
being delivered. Add an assertion in Thread::postMessage() to catch this
at the source.

Signed-off-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
---
 src/libcamera/base/thread.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/libcamera/base/thread.cpp b/src/libcamera/base/thread.cpp
index 6bda9d1462f5..6ead1d7c12d0 100644
--- a/src/libcamera/base/thread.cpp
+++ b/src/libcamera/base/thread.cpp
@@ -530,6 +530,7 @@ void Thread::postMessage(std::unique_ptr<Message> msg, Object *receiver)
 	msg->receiver_ = receiver;
 
 	ASSERT(data_ == receiver->thread()->data_);
+	ASSERT(data_ != mainThread.data_);
 
 	MutexLocker locker(data_->messages_.mutex_);
 	data_->messages_.list_.push_back(std::move(msg));

base-commit: 27cc0a6b58bcca32071cb6ab96e5ee79c75031e5
-- 
Regards,

Laurent Pinchart



More information about the libcamera-devel mailing list