[PATCH] libcamera: Add static Object::Deleter function
Barnabás Pőcze
pobrn at protonmail.com
Wed Oct 23 19:33:32 CEST 2024
Hi
2024. október 23., szerda 18:58 keltezéssel, Harvey Yang <chenghaoyang at chromium.org> írta:
> This patch allows a smart pointer of Object to be destructed in other
> threads.
>
> There will be multiple usages of smart pointers of Object. This patch
> adds the deleter function to avoid duplicated code.
>
> Signed-off-by: Harvey Yang <chenghaoyang at chromium.org>
> ---
> include/libcamera/base/object.h | 2 ++
> src/libcamera/base/object.cpp | 11 +++++++++++
> 2 files changed, 13 insertions(+)
>
> diff --git a/include/libcamera/base/object.h b/include/libcamera/base/object.h
> index 508773cd0..c4522d480 100644
> --- a/include/libcamera/base/object.h
> +++ b/include/libcamera/base/object.h
> @@ -24,6 +24,8 @@ class Thread;
> class Object
> {
> public:
> + static void Deleter(Object *obj);
I think a functor would be preferable, see camera.cpp:Camera::create():
struct Deleter {
void operator()(Object *obj) const
{
if (Thread::current() == obj->thread())
delete obj;
else
obj->deleteLater();
}
};
Or is there a reason why this wouldn't work?
Regards,
Barnabás Pőcze
> +
> Object(Object *parent = nullptr);
> virtual ~Object();
>
> diff --git a/src/libcamera/base/object.cpp b/src/libcamera/base/object.cpp
> index 745d2565a..2c04b99a5 100644
> --- a/src/libcamera/base/object.cpp
> +++ b/src/libcamera/base/object.cpp
> @@ -59,6 +59,17 @@ LOG_DEFINE_CATEGORY(Object)
> * \sa Message, Signal, Thread
> */
>
> +/**
> + * \brief A deleter function that calls Object::deleteLater
> + * \param[in] obj The object itself
> + *
> + * The static deleter function that's used in smart pointers.
> + */
> +void Object::Deleter(Object *obj)
> +{
> + obj->deleteLater();
> +}
> +
> /**
> * \brief Construct an Object instance
> * \param[in] parent The object parent
> --
> 2.47.0.105.g07ac214952-goog
>
More information about the libcamera-devel
mailing list