[PATCH v3 05/16] libcamera: shared_mem_object: reorganize the code and document the SharedMemObject class

Andrei Konovalov andrey.konovalov.ynk at gmail.com
Mon Feb 19 13:18:57 CET 2024


Hi Naushir,

On 15.02.2024 16:39, Naushir Patuck wrote:
> Hi Hans,
> 
> On Wed, 14 Feb 2024 at 17:01, Hans de Goede <hdegoede at redhat.com> wrote:
>>
>> From: Andrei Konovalov <andrey.konovalov.ynk at gmail.com>
>>
>> Split the parts which doesn't otherwise depend on the type T or
>> arguments Args out of the SharedMemObject class into a new
>> SharedMem class.
>>
>> Doxygen documentation by Dennis Bonke and Andrei Konovalov.
>>
>> Reviewed-by: Pavel Machek <pavel at ucw.cz>
>> Co-developed-by: Dennis Bonke <admin at dennisbonke.com>
>> Signed-off-by: Dennis Bonke <admin at dennisbonke.com>
>> Signed-off-by: Andrei Konovalov <andrey.konovalov.ynk at gmail.com>
>> ---
>>   .../libcamera/internal/shared_mem_object.h    |  92 ++++++---
>>   src/libcamera/meson.build                     |   1 +
>>   src/libcamera/shared_mem_object.cpp           | 191 ++++++++++++++++++
>>   3 files changed, 253 insertions(+), 31 deletions(-)
>>   create mode 100644 src/libcamera/shared_mem_object.cpp
>>
>> diff --git a/include/libcamera/internal/shared_mem_object.h b/include/libcamera/internal/shared_mem_object.h
>> index bfb639ee..a4de6500 100644
>> --- a/include/libcamera/internal/shared_mem_object.h
>> +++ b/include/libcamera/internal/shared_mem_object.h
>> @@ -7,11 +7,8 @@
>>   #pragma once
>>
>>   #include <cstddef>
>> -#include <fcntl.h>
>>   #include <string>
>>   #include <sys/mman.h>
>> -#include <sys/stat.h>
>> -#include <unistd.h>
>>   #include <utility>
>>
>>   #include <libcamera/base/class.h>
>> @@ -19,6 +16,59 @@
>>
>>   namespace libcamera {
>>
>> +class SharedMem
>> +{
>> +public:
>> +       SharedMem()
>> +               : mem_(nullptr)
>> +       {
>> +       }
>> +
>> +       SharedMem(const std::string &name, std::size_t size);
>> +
>> +       SharedMem(SharedMem &&rhs)
>> +       {
>> +               this->name_ = std::move(rhs.name_);
>> +               this->fd_ = std::move(rhs.fd_);
>> +               this->mem_ = rhs.mem_;
>> +               rhs.mem_ = nullptr;
>> +       }
>> +
>> +       ~SharedMem()
>> +       {
>> +               if (mem_)
>> +                       munmap(mem_, size_);
>> +       }
>> +
>> +       /* Make SharedMem non-copyable for now. */
>> +       LIBCAMERA_DISABLE_COPY(SharedMem)
>> +
>> +       SharedMem &operator=(SharedMem &&rhs)
>> +       {
>> +               this->name_ = std::move(rhs.name_);
>> +               this->fd_ = std::move(rhs.fd_);
>> +               this->mem_ = rhs.mem_;
>> +               rhs.mem_ = nullptr;
>> +               return *this;
>> +       }
>> +
>> +       const SharedFD &fd() const
>> +       {
>> +               return fd_;
>> +       }
>> +
>> +       void *mem() const
>> +       {
>> +               return mem_;
>> +       }
>> +
>> +private:
>> +       std::string name_;
>> +       SharedFD fd_;
>> +       size_t size_;
>> +       void *mem_;
>> +};
>> +
>>   template<class T>
>>   class SharedMemObject
> 
> Would it make sense to have SharedMemObject derived from SharedMem?
> Then you would only need a constructor and destructor implemented for
> SharedMemObject, and all other accessors can be through the base
> class... i think?

Does this updated patch (attached) looks OK for you?

Thanks,
Andrei
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0005-libcamera-shared_mem_object-reorganize-the-code-and-.patch
Type: text/x-patch
Size: 10573 bytes
Desc: not available
URL: <https://lists.libcamera.org/pipermail/libcamera-devel/attachments/20240219/98ec3abe/attachment.bin>


More information about the libcamera-devel mailing list