[libcamera-devel] [PATCH] libcamera: base: thread: Prevent messages to thread without an event loop
Tomi Valkeinen
tomi.valkeinen at ideasonboard.com
Tue Jun 28 10:09:21 CEST 2022
On 27/06/2022 19:46, Laurent Pinchart wrote:
> 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
So what was the issue with the code I had? The problem is that
CameraManager is a libcamera Object, and was associated with the main
thread...? And a PyCameraManager which doesn't inherit CameraManager is
not an Object and not associated with any thread, so it works?
Tomi
More information about the libcamera-devel
mailing list