libcamera
v0.3.1+12-19bbca3c
Supporting cameras in Linux since 2019
|
Helper class to allocate an object in shareable memory. More...
Public Member Functions | |
template<class... Args> | |
SharedMemObject (const std::string &name, Args &&...args) | |
Construct a SharedMemObject. More... | |
SharedMemObject (SharedMemObject< T > &&rhs) | |
Move constructor for SharedMemObject. More... | |
~SharedMemObject () | |
Destroy the SharedMemObject instance. More... | |
SharedMemObject< T > & | operator= (SharedMemObject< T > &&rhs) |
Move assignment operator for SharedMemObject. More... | |
T * | operator-> () |
Dereference the stored object. More... | |
const T * | operator-> () const |
Dereference the stored object. More... | |
T & | operator* () |
Dereference the stored object. More... | |
const T & | operator* () const |
Dereference the stored object. More... | |
Public Member Functions inherited from libcamera::SharedMem | |
SharedMem (const std::string &name, std::size_t size) | |
Construct a SharedMem with memory of the given size. More... | |
SharedMem (SharedMem &&rhs) | |
Move constructor for SharedMem. More... | |
virtual | ~SharedMem () |
Destroy the SharedMem instance. More... | |
SharedMem & | operator= (SharedMem &&rhs) |
Move assignment operator for SharedMem. More... | |
const SharedFD & | fd () const |
Retrieve the file descriptor for the underlying shared memory. More... | |
Span< uint8_t > | mem () const |
Retrieve the underlying shared memory. More... | |
operator bool () const | |
Check if the shared memory allocation succeeded. More... | |
Static Public Attributes | |
static constexpr std::size_t | kSize = sizeof(T) |
The size of the object stored in shared memory. | |
Helper class to allocate an object in shareable memory.
The | object type |
The SharedMemObject class is a specialization of the SharedMem class that wraps an object of type T and constructs it in shareable memory. It uses the same underlying memory allocation and sharing mechanism as the SharedMem class.
The wrapped object is constructed at the same time as the SharedMemObject instance, by forwarding the arguments passed to the SharedMemObject constructor. The underlying memory allocation is sized to the object T size. The bool() operator should be used to check the allocation was successful. The object can be accessed using the dereference operators operator*() and operator->().
While no restriction on the type T is enforced, not all types are suitable for sharing between multiple processes. Most notably, any object type that contains pointer or reference members will likely cause issues. Even if those members refer to other members of the same object, the shared memory will be mapped at different addresses in different processes, and the pointers will not be valid.
A new anonymous file is created for every SharedMemObject instance. If there is a need to share a large number of small objects, these objects should be grouped into a single larger object to limit the number of file descriptors.
To share the object with other processes, see the SharedMem documentation.
|
inline |
Construct a SharedMemObject.
[in] | name | Name of the SharedMemObject |
[in] | args | Arguments to pass to the constructor of the object T |
The name is used for debugging purpose only. Multiple SharedMem instances can have the same name.
|
inline |
Move constructor for SharedMemObject.
[in] | rhs | The object to move |
|
inline |
Destroy the SharedMemObject instance.
Destroying a SharedMemObject calls the wrapped T object's destructor. While the underlying memory may not be freed immediately if other mappings have been created manually (see SharedMem::~SharedMem() for more information), the stored object may be modified. Depending on the ~T() destructor, accessing the object after destruction of the SharedMemObject causes undefined behaviour. It is the responsibility of the user of this class to synchronize with other users who have access to the shared object.
|
inline |
Dereference the stored object.
|
inline |
Dereference the stored object.
|
inline |
Dereference the stored object.
|
inline |
Dereference the stored object.
|
inline |
Move assignment operator for SharedMemObject.
[in] | rhs | The SharedMemObject object to take the data from |
Moving a SharedMemObject does not affect the stored object.