[libcamera-devel,1/3] base: thread: Document the postMessage() function as thread-safe
diff mbox series

Message ID 20210701230741.14320-2-laurent.pinchart@ideasonboard.com
State Accepted
Delegated to: Laurent Pinchart
Headers show
Series
  • base: Fix crash with recursive messages dispatch
Related show

Commit Message

Laurent Pinchart July 1, 2021, 11:07 p.m. UTC
The Thread::postMessage() function is thread-safe, document it as such.

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

Comments

Kieran Bingham July 9, 2021, 9:44 a.m. UTC | #1
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@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@ideasonboard.com>


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

Patch
diff mbox series

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.
+ *
  * \sa exec()
  */
 void Thread::postMessage(std::unique_ptr<Message> msg, Object *receiver)