[RFC,v1] libcamera: base: object,thread: Disable copy/move
diff mbox series

Message ID 20250130195429.1229777-1-pobrn@protonmail.com
State Accepted
Headers show
Series
  • [RFC,v1] libcamera: base: object,thread: Disable copy/move
Related show

Commit Message

Barnabás Pőcze Jan. 30, 2025, 7:54 p.m. UTC
Objects of type `Object` and `Thread` have address identities, so they
should not be just moved/copied. And the special member functions
generated by the compiler do not do the right thing. So delete them.

Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>
---
 include/libcamera/base/object.h | 3 +++
 include/libcamera/base/thread.h | 3 +++
 2 files changed, 6 insertions(+)

Comments

Jacopo Mondi Feb. 3, 2025, 4:18 p.m. UTC | #1
Hi Barnabás

On Thu, Jan 30, 2025 at 07:54:33PM +0000, Barnabás Pőcze wrote:
> Objects of type `Object` and `Thread` have address identities, so they
> should not be just moved/copied. And the special member functions
> generated by the compiler do not do the right thing. So delete them.
>
> Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>

The CI loop is happy with this, so am I

Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>

Thanks
  j

> ---
>  include/libcamera/base/object.h | 3 +++
>  include/libcamera/base/thread.h | 3 +++
>  2 files changed, 6 insertions(+)
>
> diff --git a/include/libcamera/base/object.h b/include/libcamera/base/object.h
> index 508773cd0..6cb935a04 100644
> --- a/include/libcamera/base/object.h
> +++ b/include/libcamera/base/object.h
> @@ -12,6 +12,7 @@
>  #include <vector>
>
>  #include <libcamera/base/bound_method.h>
> +#include <libcamera/base/class.h>
>
>  namespace libcamera {
>
> @@ -52,6 +53,8 @@ protected:
>  	bool assertThreadBound(const char *message);
>
>  private:
> +	LIBCAMERA_DISABLE_COPY_AND_MOVE(Object)
> +
>  	friend class SignalBase;
>  	friend class Thread;
>
> diff --git a/include/libcamera/base/thread.h b/include/libcamera/base/thread.h
> index 3209d4f7c..3cbf6398e 100644
> --- a/include/libcamera/base/thread.h
> +++ b/include/libcamera/base/thread.h
> @@ -13,6 +13,7 @@
>
>  #include <libcamera/base/private.h>
>
> +#include <libcamera/base/class.h>
>  #include <libcamera/base/message.h>
>  #include <libcamera/base/signal.h>
>  #include <libcamera/base/span.h>
> @@ -54,6 +55,8 @@ protected:
>  	virtual void run();
>
>  private:
> +	LIBCAMERA_DISABLE_COPY_AND_MOVE(Thread)
> +
>  	void startThread();
>  	void finishThread();
>
> --
> 2.48.1
>
>
Laurent Pinchart Feb. 3, 2025, 4:21 p.m. UTC | #2
Hi Barnabás,

Thank you for the patch.

On Thu, Jan 30, 2025 at 07:54:33PM +0000, Barnabás Pőcze wrote:
> Objects of type `Object` and `Thread` have address identities, so they
> should not be just moved/copied. And the special member functions
> generated by the compiler do not do the right thing. So delete them.
> 
> Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
>  include/libcamera/base/object.h | 3 +++
>  include/libcamera/base/thread.h | 3 +++
>  2 files changed, 6 insertions(+)
> 
> diff --git a/include/libcamera/base/object.h b/include/libcamera/base/object.h
> index 508773cd0..6cb935a04 100644
> --- a/include/libcamera/base/object.h
> +++ b/include/libcamera/base/object.h
> @@ -12,6 +12,7 @@
>  #include <vector>
>  
>  #include <libcamera/base/bound_method.h>
> +#include <libcamera/base/class.h>
>  
>  namespace libcamera {
>  
> @@ -52,6 +53,8 @@ protected:
>  	bool assertThreadBound(const char *message);
>  
>  private:
> +	LIBCAMERA_DISABLE_COPY_AND_MOVE(Object)
> +
>  	friend class SignalBase;
>  	friend class Thread;
>  
> diff --git a/include/libcamera/base/thread.h b/include/libcamera/base/thread.h
> index 3209d4f7c..3cbf6398e 100644
> --- a/include/libcamera/base/thread.h
> +++ b/include/libcamera/base/thread.h
> @@ -13,6 +13,7 @@
>  
>  #include <libcamera/base/private.h>
>  
> +#include <libcamera/base/class.h>
>  #include <libcamera/base/message.h>
>  #include <libcamera/base/signal.h>
>  #include <libcamera/base/span.h>
> @@ -54,6 +55,8 @@ protected:
>  	virtual void run();
>  
>  private:
> +	LIBCAMERA_DISABLE_COPY_AND_MOVE(Thread)
> +
>  	void startThread();
>  	void finishThread();
>

Patch
diff mbox series

diff --git a/include/libcamera/base/object.h b/include/libcamera/base/object.h
index 508773cd0..6cb935a04 100644
--- a/include/libcamera/base/object.h
+++ b/include/libcamera/base/object.h
@@ -12,6 +12,7 @@ 
 #include <vector>
 
 #include <libcamera/base/bound_method.h>
+#include <libcamera/base/class.h>
 
 namespace libcamera {
 
@@ -52,6 +53,8 @@  protected:
 	bool assertThreadBound(const char *message);
 
 private:
+	LIBCAMERA_DISABLE_COPY_AND_MOVE(Object)
+
 	friend class SignalBase;
 	friend class Thread;
 
diff --git a/include/libcamera/base/thread.h b/include/libcamera/base/thread.h
index 3209d4f7c..3cbf6398e 100644
--- a/include/libcamera/base/thread.h
+++ b/include/libcamera/base/thread.h
@@ -13,6 +13,7 @@ 
 
 #include <libcamera/base/private.h>
 
+#include <libcamera/base/class.h>
 #include <libcamera/base/message.h>
 #include <libcamera/base/signal.h>
 #include <libcamera/base/span.h>
@@ -54,6 +55,8 @@  protected:
 	virtual void run();
 
 private:
+	LIBCAMERA_DISABLE_COPY_AND_MOVE(Thread)
+
 	void startThread();
 	void finishThread();