[libcamera-devel] [PATCH 1/3] base: thread: Document the postMessage() function as thread-safe

Kieran Bingham kieran.bingham at ideasonboard.com
Fri Jul 9 11:44:11 CEST 2021


Hi Laurent,

On 02/07/2021 00:07, Laurent Pinchart wrote:
> The Thread::postMessage() function is thread-safe, document it as such.


Well this is short and sweet, so I presume you're sure.


> Signed-off-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
> ---
>  src/libcamera/base/thread.cpp | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/src/libcamera/base/thread.cpp b/src/libcamera/base/thread.cpp
> index c7c2d6b29d6a..7f79115222e8 100644
> --- a/src/libcamera/base/thread.cpp
> +++ b/src/libcamera/base/thread.cpp
> @@ -526,6 +526,8 @@ EventDispatcher *Thread::eventDispatcher()
>   *
>   * If the \a receiver is not bound to this thread the behaviour is undefined.
>   *
> + * \context This function is \threadsafe.
> + *

It's curious how the preceding statement declares how this might cause
undefined behaviour, but then we say 'but we're safe'.

However, while a little close, I think the intentions are still fairly
clear and that these refer to two different contexts...

I.e.
 - This function can be called from any thread, but it acts upon the
Thread object and the Thread object must be the one which contains the
target object which will receive the message.

So .. in other long words, I think it's fine.

Reviewed-by: Kieran Bingham <kieran.bingham at ideasonboard.com>


>   * \sa exec()
>   */
>  void Thread::postMessage(std::unique_ptr<Message> msg, Object *receiver)
> 


More information about the libcamera-devel mailing list