[libcamera-devel,02/11] Adds missing thread-safety annotations, lack of which break the build.
diff mbox series

Message ID 20221024055543.116040-3-nicholas@rothemail.net
State Superseded
Headers show
Series
  • [libcamera-devel,01/11] Fixes Bug 156, which breaks libcamera on Android < 12.
Related show

Commit Message

Nicolas Dufresne via libcamera-devel Oct. 24, 2022, 5:55 a.m. UTC
From: Nicholas Roth <nicholas@rothemail.net>

../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(); }
                               ^
---
 src/ipa/raspberrypi/controller/metadata.h | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

Comments

Laurent Pinchart Oct. 24, 2022, 1:52 p.m. UTC | #1
Hi Nicholas,

Thank you for the patch.

On Mon, Oct 24, 2022 at 12:55:34AM -0500, Nicholas Roth via libcamera-devel wrote:
> From: Nicholas Roth <nicholas@rothemail.net>
> 
> ../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(); }
>                                ^

Apart from the commit message issue raised by Kieran, the code change
looks good to me.

> ---
>  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_;

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_;