[libcamera-devel,v5,02/10] ipa: add missing thread-safety annotations
diff mbox series

Message ID 20221028031726.4849-3-nicholas@rothemail.net
State Accepted
Headers show
Series
  • [libcamera-devel,v5,01/10] ipa: workaround libcxx duration limitation
Related show

Commit Message

Nicolas Dufresne via libcamera-devel Oct. 28, 2022, 3:17 a.m. UTC
From: Nicholas Roth <nicholas@rothemail.net>

The raspberrypi IPA is missing thread-safety annotations, which breaks
the build.

Add required thread-safety annotations.

../src/ipa/raspberrypi/controller/metadata.h:108:31: error: mutex
  'mutex_' is still held at the end of function [-Werror,-Wthread-safety-analysis]
        void lock() { mutex_.lock(); }
                                     ^
../src/ipa/raspberrypi/controller/metadata.h:108:23: note: mutex
  acquired here
        void lock() { mutex_.lock(); }
                             ^
../src/ipa/raspberrypi/controller/metadata.h:109:25: error: releasing
  mutex 'mutex_' that was not held [-Werror,-Wthread-safety-analysis]
        void unlock() { mutex_.unlock(); }
                               ^

Signed-off-by: Nicholas Roth <nicholas@rothemail.net>
---
 src/ipa/raspberrypi/controller/metadata.h | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

Comments

Kieran Bingham Oct. 28, 2022, 9:43 a.m. UTC | #1
Quoting Nicholas Roth via libcamera-devel (2022-10-28 04:17:18)
> From: Nicholas Roth <nicholas@rothemail.net>
> 
> The raspberrypi IPA is missing thread-safety annotations, which breaks
> the build.
> 
> Add required thread-safety annotations.
> 
> ../src/ipa/raspberrypi/controller/metadata.h:108:31: error: mutex
>   'mutex_' is still held at the end of function [-Werror,-Wthread-safety-analysis]
>         void lock() { mutex_.lock(); }
>                                      ^
> ../src/ipa/raspberrypi/controller/metadata.h:108:23: note: mutex
>   acquired here
>         void lock() { mutex_.lock(); }
>                              ^
> ../src/ipa/raspberrypi/controller/metadata.h:109:25: error: releasing
>   mutex 'mutex_' that was not held [-Werror,-Wthread-safety-analysis]
>         void unlock() { mutex_.unlock(); }
>                                ^
> 
> Signed-off-by: Nicholas Roth <nicholas@rothemail.net>

From Jacopo on v1

Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>

From Me

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

Naush - any objections or concerns on this patch?



> ---
>  src/ipa/raspberrypi/controller/metadata.h | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/src/ipa/raspberrypi/controller/metadata.h b/src/ipa/raspberrypi/controller/metadata.h
> index 0f7ebfaf..870b6e26 100644
> --- a/src/ipa/raspberrypi/controller/metadata.h
> +++ b/src/ipa/raspberrypi/controller/metadata.h
> @@ -13,9 +13,11 @@
>  #include <mutex>
>  #include <string>
>  
> +#include <libcamera/base/thread_annotations.h>
> +
>  namespace RPiController {
>  
> -class Metadata
> +class LIBCAMERA_TSA_CAPABILITY("mutex") Metadata
>  {
>  public:
>         Metadata() = default;
> @@ -103,8 +105,8 @@ public:
>          * locks with the standard lock classes.
>          * e.g. std::lock_guard<RPiController::Metadata> lock(metadata)
>          */
> -       void lock() { mutex_.lock(); }
> -       void unlock() { mutex_.unlock(); }
> +       void lock() LIBCAMERA_TSA_ACQUIRE() { mutex_.lock(); }
> +       void unlock() LIBCAMERA_TSA_RELEASE() { mutex_.unlock(); }
>  
>  private:
>         mutable std::mutex mutex_;
> -- 
> 2.34.1
>
Naushir Patuck Oct. 28, 2022, 9:44 a.m. UTC | #2
On Fri, 28 Oct 2022 at 10:43, Kieran Bingham <
kieran.bingham@ideasonboard.com> wrote:

> Quoting Nicholas Roth via libcamera-devel (2022-10-28 04:17:18)
> > From: Nicholas Roth <nicholas@rothemail.net>
> >
> > The raspberrypi IPA is missing thread-safety annotations, which breaks
> > the build.
> >
> > Add required thread-safety annotations.
> >
> > ../src/ipa/raspberrypi/controller/metadata.h:108:31: error: mutex
> >   'mutex_' is still held at the end of function
> [-Werror,-Wthread-safety-analysis]
> >         void lock() { mutex_.lock(); }
> >                                      ^
> > ../src/ipa/raspberrypi/controller/metadata.h:108:23: note: mutex
> >   acquired here
> >         void lock() { mutex_.lock(); }
> >                              ^
> > ../src/ipa/raspberrypi/controller/metadata.h:109:25: error: releasing
> >   mutex 'mutex_' that was not held [-Werror,-Wthread-safety-analysis]
> >         void unlock() { mutex_.unlock(); }
> >                                ^
> >
> > Signed-off-by: Nicholas Roth <nicholas@rothemail.net>
>
> From Jacopo on v1
>
> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
>
> From Me
>
> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
>
> Naush - any objections or concerns on this patch?
>

Nope, all looks fine:

Reviewed-by: Naushir Patuck <naush@raspberrypi.com>


>
>
>
> > ---
> >  src/ipa/raspberrypi/controller/metadata.h | 8 +++++---
> >  1 file changed, 5 insertions(+), 3 deletions(-)
> >
> > diff --git a/src/ipa/raspberrypi/controller/metadata.h
> b/src/ipa/raspberrypi/controller/metadata.h
> > index 0f7ebfaf..870b6e26 100644
> > --- a/src/ipa/raspberrypi/controller/metadata.h
> > +++ b/src/ipa/raspberrypi/controller/metadata.h
> > @@ -13,9 +13,11 @@
> >  #include <mutex>
> >  #include <string>
> >
> > +#include <libcamera/base/thread_annotations.h>
> > +
> >  namespace RPiController {
> >
> > -class Metadata
> > +class LIBCAMERA_TSA_CAPABILITY("mutex") Metadata
> >  {
> >  public:
> >         Metadata() = default;
> > @@ -103,8 +105,8 @@ public:
> >          * locks with the standard lock classes.
> >          * e.g. std::lock_guard<RPiController::Metadata> lock(metadata)
> >          */
> > -       void lock() { mutex_.lock(); }
> > -       void unlock() { mutex_.unlock(); }
> > +       void lock() LIBCAMERA_TSA_ACQUIRE() { mutex_.lock(); }
> > +       void unlock() LIBCAMERA_TSA_RELEASE() { mutex_.unlock(); }
> >
> >  private:
> >         mutable std::mutex mutex_;
> > --
> > 2.34.1
> >
>

Patch
diff mbox series

diff --git a/src/ipa/raspberrypi/controller/metadata.h b/src/ipa/raspberrypi/controller/metadata.h
index 0f7ebfaf..870b6e26 100644
--- a/src/ipa/raspberrypi/controller/metadata.h
+++ b/src/ipa/raspberrypi/controller/metadata.h
@@ -13,9 +13,11 @@ 
 #include <mutex>
 #include <string>
 
+#include <libcamera/base/thread_annotations.h>
+
 namespace RPiController {
 
-class Metadata
+class LIBCAMERA_TSA_CAPABILITY("mutex") Metadata
 {
 public:
 	Metadata() = default;
@@ -103,8 +105,8 @@  public:
 	 * locks with the standard lock classes.
 	 * e.g. std::lock_guard<RPiController::Metadata> lock(metadata)
 	 */
-	void lock() { mutex_.lock(); }
-	void unlock() { mutex_.unlock(); }
+	void lock() LIBCAMERA_TSA_ACQUIRE() { mutex_.lock(); }
+	void unlock() LIBCAMERA_TSA_RELEASE() { mutex_.unlock(); }
 
 private:
 	mutable std::mutex mutex_;