libcamera v0.2.0
Supporting cameras in Linux since 2019
|
Helper class for allocating objects in shared memory. More...
Public Member Functions | |
template<class... Args> | |
SharedMemObject (const std::string &name, Args &&...args) | |
Contstructor for the SharedMemObject. | |
SharedMemObject (SharedMemObject< T > &&rhs) | |
Move constructor for SharedMemObject. | |
~SharedMemObject () | |
SharedMemObject destructor. | |
SharedMemObject< T > & | operator= (SharedMemObject< T > &&rhs) |
Operator= for SharedMemObject. | |
T * | operator-> () |
Operator-> for SharedMemObject. | |
const T * | operator-> () const |
Operator-> for SharedMemObject. | |
T & | operator* () |
Operator* for SharedMemObject. | |
const T & | operator* () const |
Operator* for SharedMemObject. | |
const SharedFD & | fd () const |
Gets the file descriptor for the underlaying storage file. | |
operator bool () const | |
Operator bool() for SharedMemObject. | |
Static Public Attributes | |
static constexpr std::size_t | SIZE = sizeof(T) |
The size of the object that is going to be stored here. | |
Helper class for allocating objects in shared memory.
Memory is allocated and exposed as a SharedFD for use across IPC boundaries.
Given the type of the object to be created in shared memory and the arguments to pass to this object's constructor, SharedMemObject allocates the shared memory of the size of the object and constructs the object in this memory. To check that the SharedMemObject was created successfully, one needs to verify that the underlying SharedFD (the reference to it is returned by SharedMemObject::fd() member function) is valid. The object created in the shared memory can be accessed using the SharedMemObject::operator*() indirection operator. Its members can be accessed with the SharedMemObject::operator->() member of pointer operator.
To access the object from another process the SharedFD should be passed to that process, and the shared memory should be mapped by calling mmap().
A single memfd is created for every SharedMemObject. If there is a need to allocate a large number of objects in shared memory, these objects should be grouped into a single large object to keep the number of created memfd's reasonably small.
|
inline |
Contstructor for the SharedMemObject.
[in] | name | Name of the SharedMemObject |
[in] | args | Args to pass to the constructor of the object in shared memory |
|
inline |
Move constructor for SharedMemObject.
[in] | rhs | The object to move |
|
inline |
SharedMemObject destructor.
Destroys the object created in the shared memory and then unmaps the shared memory. Decrements the shared memory descriptor use count.
|
inline |
Gets the file descriptor for the underlaying storage file.
|
inlineexplicit |
Operator bool() for SharedMemObject.
|
inline |
Operator* for SharedMemObject.
|
inline |
Operator* for SharedMemObject.
|
inline |
Operator-> for SharedMemObject.
|
inline |
Operator-> for SharedMemObject.
|
inline |
Operator= for SharedMemObject.
[in] | rhs | The SharedMemObject object to take the data from |