Fawkes API
Fawkes Development Version
|
Shared memory segment. More...
#include <>>
Classes | |
struct | SharedMemory_header_t |
General header. More... | |
class | SharedMemoryIterator |
Shared Memory iterator. More... | |
Public Member Functions | |
SharedMemory (const char *magic_token, SharedMemoryHeader *header, bool is_read_only, bool create, bool destroy_on_delete, const char *registry_name=0) | |
Create a new shared memory segment. More... | |
SharedMemory (const SharedMemory &s) | |
Copy constructor. More... | |
virtual | ~SharedMemory () |
Destructor. More... | |
bool | is_read_only () const |
Check for read-only mode. More... | |
bool | is_destroyed () const |
Check if segment has been destroyed This can be used if the segment has been destroyed. More... | |
bool | is_swapable () const |
Check if memory can be swapped out. More... | |
bool | is_valid () const |
Check validity of shared memory segment. More... | |
bool | is_creator () const |
Determine if the shared memory segment has been created by this instance. More... | |
bool | is_protected () const |
Check if memory segment is protected. More... | |
void * | memptr () const |
Get a pointer to the shared memory This method returns a pointer to the data-segment of the shared memory segment. More... | |
size_t | data_size () const |
Get the size of the data-segment. More... | |
int | shmem_id () const |
Get shared memory ID. More... | |
unsigned int | num_attached () const |
Get number of attached processes. More... | |
void | set (void *memptr) |
Copies data from the memptr to shared memory. More... | |
void | set_destroy_on_delete (bool destroy) |
Set deletion behaviour. More... | |
void | add_semaphore () |
Add semaphore to shared memory segment. More... | |
void | set_swapable (bool swapable) |
Set shared memory swapable. More... | |
void | lock_for_read () |
Lock shared memory segment for reading. More... | |
bool | try_lock_for_read () |
Try to aquire lock on shared memory segment for reading. More... | |
void | lock_for_write () |
Lock shared memory segment for writing. More... | |
bool | try_lock_for_write () |
Try to aquire lock on shared memory segment for writing. More... | |
void | unlock () |
Unlock memory. More... | |
void * | ptr (void *addr) const |
Get the real pointer to the data based on an address. More... | |
void * | addr (void *ptr) const |
Get an address from a real pointer. More... | |
Static Public Member Functions | |
static void | list (const char *magic_token, SharedMemoryHeader *header, SharedMemoryLister *lister, const char *registry_name=0) |
List shared memory segments of a given type. More... | |
static void | erase (const char *magic_token, SharedMemoryHeader *header, SharedMemoryLister *lister=0, const char *registry_name=0) |
Erase shared memory segments of a given type. More... | |
static void | erase_orphaned (const char *magic_token, SharedMemoryHeader *header, SharedMemoryLister *lister=0, const char *registry_name=0) |
Erase orphaned (attach count = 0) shared memory segments of a given type. More... | |
static bool | exists (const char *magic_token, SharedMemoryHeader *header, const char *registry_name=0) |
Check if a specific shared memory segment exists. More... | |
static bool | is_destroyed (int shm_id) |
Check if a segment has been destroyed. More... | |
static bool | is_swapable (int shm_id) |
Check if memory can be swapped out. More... | |
static unsigned int | num_attached (int shm_id) |
Get number of attached processes. More... | |
static SharedMemoryIterator | find (const char *magic_token, SharedMemoryHeader *header, const char *registry_name=0) |
Find SharedMemory segments. More... | |
static SharedMemoryIterator | end () |
Get invalid iterator. More... | |
Static Public Attributes | |
static const unsigned int | MagicTokenSize = MAGIC_TOKEN_SIZE |
The magic token size. More... | |
static const short | MaxNumConcurrentReaders = 8 |
Maximum number of concurrent readers. More... | |
Protected Member Functions | |
SharedMemory (const char *magic_token, bool is_read_only, bool create, bool destroy_on_delete, const char *registry_name=0) | |
Constructor for derivates. More... | |
void | attach () |
Attach to the shared memory segment. More... | |
void | free () |
Detach from and maybe destroy the shared memory segment. More... | |
Protected Attributes | |
void * | _memptr |
Pointer to the data segment. More... | |
size_t | _mem_size |
Total size of the segment, including headers. More... | |
size_t | _data_size |
Size of the data segment only. More... | |
SharedMemoryHeader * | _header |
Data-specific header. More... | |
bool | _is_read_only |
Read-only. More... | |
bool | _destroy_on_delete |
destroy on delete. More... | |
bool | _should_create |
Create shared memory segment. More... | |
char * | _magic_token |
Magic token. More... | |
char * | _shm_magic_token |
Magic token as stored in the shared memory segment. More... | |
SharedMemory_header_t * | _shm_header |
general header as stored in the shared memory segment More... | |
void * | _shm_upper_bound |
Upper bound of memory. More... | |
long unsigned int | _shm_offset |
Offset to the master's base addr. More... | |
Shared memory segment.
This class gives access to shared memory segment to store arbitrary data. With shared memory data can be shared between several applications. Special means like semaphores have to be used to control access to the storage to prevent data corruption.
The shared memory segment is divided into three parts.
The general header consists of a magic token of MagicTokenSize that is used to find the basically compatible shared memory segments out of all existing shared memory segments. This is done for convenience. Although in general shared memory is accessed via keys or IDs it is easier from the maintenance side to just scan the segments to find the correct one, especially if there may be more than just one segment for the same application. The header also includes a semaphore ID which is unused at the moment.
The data-specific header is generated from a given SharedMemoryHeader implementation. It can be used to store any information that is needed to identify a specific shared memory segment and to store management data for the data segment. It should always contain enough information to derive the data segment size or if needed an explicit information about the memory size.
The data segment can be filled with any data you like.
Shared memory segments are protected with a read-write lock implemented with two IPC semaphores. The writer takes preference in locking. Only a limited number of concurrent readers can be allowed. The constant MaxNumberConcurrentReaders defines how many these are. If a shared memory segment already has a semaphore assigned at the time it is opened this semaphore is automatically opened. In any case add_semaphore() can be used to create (or open if it already exists) a semaphore for the shared memory segment. Information about the semaphore is stored in the shared memory general header.
This class provides utilities to list, erase and check existence of given shared memory segments. For this often a SharedMemoryLister is used that takes care of formatting the output of the specific information about the shared memory segment.
fawkes::SharedMemory::SharedMemory | ( | const char * | magic_token, |
SharedMemoryHeader * | header, | ||
bool | is_read_only, | ||
bool | create, | ||
bool | destroy_on_delete, | ||
const char * | registry_name = 0 |
||
) |
Create a new shared memory segment.
This will open a shared memory segment that exactly fits the given SharedMemoryHeader. It the segment does not exist and create is assured the segment is created from the given data, otherwise the SharedMemory instance remains in an invalid state and an exception is thrown. The segment can be destroyed automatically if the instance is destroyed. Shared memory segments can be opened read-only.
magic_token | This is the magic token discussed above that is used to identify the shared memory segment. The magic_token can be of arbitrary size but at most MagicTokenSize bytes are used. |
header | The data-sepcific header used for this shared memory segment |
is_read_only | if true the shared memory segment is opened in read-only mode |
create | if true the shared memory segment is created if no one matching the headers was found |
destroy_on_delete | if true the shared memory segment is destroyed when this SharedMemory instance is deleted. |
registry_name | name of the SharedMemoryRegistry to use |
ShmNoHeaderException | No header has been set |
ShmInconsistentSegmentSizeException | The memory size is not the expected memory size |
ShmCouldNotAttachException | Could not attach to shared memory segment |
Definition at line 352 of file shm.cpp.
References _data_size, _destroy_on_delete, _header, _is_read_only, _magic_token, _memptr, _shm_header, _shm_magic_token, _should_create, fawkes::Exception::append(), attach(), is_read_only(), and MagicTokenSize.
fawkes::SharedMemory::SharedMemory | ( | const SharedMemory & | s | ) |
Copy constructor.
If the given SharedMemory was attached this instance will also attach.
s | SharedMemory instance to copy. |
Definition at line 282 of file shm.cpp.
References _data_size, _destroy_on_delete, _header, _is_read_only, _magic_token, _memptr, _shm_header, _shm_magic_token, _should_create, fawkes::Exception::append(), attach(), fawkes::SharedMemoryHeader::clone(), and MagicTokenSize.
|
virtual |
Destructor.
Definition at line 400 of file shm.cpp.
References _destroy_on_delete, _is_read_only, _magic_token, _shm_header, free(), fawkes::SharedMemory::SharedMemory_header_t::semaphore, and fawkes::SemaphoreSet::set_destroy_on_delete().
|
protected |
Constructor for derivates.
This constructor may only be used by derivatives. It can be used to delay the call to attach() to do other preparations like creating a SharedMemoryHeader object.
magic_token | magic token of the shared memory segment |
is_read_only | if true the shared memory segment is opened in read-only mode |
create | if true the shared memory segment is created if no one matching the headers was found |
destroy_on_delete | if true the shared memory segment is destroyed when this SharedMemory instance is deleted. |
registry_name | name of the SharedMemoryRegistry to use |
Definition at line 241 of file shm.cpp.
References _data_size, _destroy_on_delete, _header, _is_read_only, _magic_token, _memptr, _shm_header, _shm_magic_token, _should_create, is_read_only(), and MagicTokenSize.
void fawkes::SharedMemory::add_semaphore | ( | ) |
Add semaphore to shared memory segment.
This adds a semaphore to the system and puts its key in the shared memory segment header. The semaphore can then be protected via the semaphore by appropriate locking. If a semaphore has been assigned to the shared memory segment already but after the segment was opened the semaphore is opened and no new semaphore is created.
Definition at line 810 of file shm.cpp.
References _is_read_only, _memptr, _shm_header, fawkes::SemaphoreSet::key(), MaxNumConcurrentReaders, fawkes::SharedMemory::SharedMemory_header_t::semaphore, fawkes::SemaphoreSet::set_value(), and fawkes::SemaphoreSet::unlock().
Referenced by attach(), fawkes::BlackBoardMemoryManager::BlackBoardMemoryManager(), and firevision::SharedMemoryImageBuffer::SharedMemoryImageBuffer().
void * fawkes::SharedMemory::addr | ( | void * | ptr | ) | const |
Get an address from a real pointer.
If there is address-dependent data in the shared memory segment (like pointers to the next element in a linked list) these are only valid for the process that created the shared memory segment, they are not necessarily valid for other processes.
This method takes a pointer that points to data in the shared memory segment that is valid in the local process and transform it to a pointer that is valid inside the shared memory segment with respect to the base address used by the creating process.
ptr | pointer to data inside the shared memory segment |
ShmPtrOutOfBoundsException | This exception is thrown if ptr is not NULL, smaller than the local base ptr and greater or equal to the local base ptr plus the memory size. |
Definition at line 637 of file shm.cpp.
References _shm_offset, and ptr().
Referenced by fawkes::BlackBoardMemoryManager::BlackBoardMemoryManager(), ptr(), fawkes::BlackBoardSharedMemoryHeader::set_alloc_list_head(), fawkes::BlackBoardSharedMemoryHeader::set_free_list_head(), and fawkes::BlackBoardMemoryManager::~BlackBoardMemoryManager().
|
protected |
Attach to the shared memory segment.
This method will try to open and/or create the shared memory segment.
ShmNoHeaderException | No header has been set |
ShmInconsistentSegmentSizeException | The memory size is not the expected memory size |
ShmCouldNotAttachException | Could not attach to shared memory segment |
Definition at line 450 of file shm.cpp.
References _data_size, _header, _is_read_only, _magic_token, _mem_size, _memptr, _shm_header, _shm_magic_token, _shm_offset, _shm_upper_bound, _should_create, fawkes::SharedMemoryRegistry::add_segment(), add_semaphore(), fawkes::SharedMemoryHeader::data_size(), fawkes::SharedMemoryRegistry::find_segments(), free(), fawkes::SharedMemoryHeader::initialize(), MagicTokenSize, fawkes::SharedMemoryHeader::matches(), fawkes::SharedMemory::SharedMemory_header_t::semaphore, fawkes::SharedMemoryHeader::set(), fawkes::SharedMemory::SharedMemory_header_t::shm_addr, and fawkes::SharedMemoryHeader::size().
Referenced by fawkes::SharedMemory::SharedMemoryIterator::operator++(), fawkes::SharedMemory::SharedMemoryIterator::operator=(), firevision::SharedMemoryImageBuffer::set_image_id(), firevision::SharedMemoryLookupTable::set_lut_id(), SharedMemory(), firevision::SharedMemoryImageBuffer::SharedMemoryImageBuffer(), fawkes::SharedMemory::SharedMemoryIterator::SharedMemoryIterator(), and firevision::SharedMemoryLookupTable::SharedMemoryLookupTable().
size_t fawkes::SharedMemory::data_size | ( | ) | const |
Get the size of the data-segment.
Use this method to get the size of the data segment. Calls dataSize() of the data-specific header internally.
Definition at line 694 of file shm.cpp.
References _data_size.
|
static |
|
static |
Erase shared memory segments of a given type.
This method erases (destroys) all shared memory segments that match the given magic token (first MagicTokenSize bytes, filled with zero) and the given header. The lister is called to format the output. If a semaphore has been assigned to this shared memory segment it is destroyed as well.
magic_token | Token to look for |
header | header to identify interesting segments with matching magic_token |
lister | Lister used to format output, maybe NULL (default) |
registry_name | name of the SharedMemoryRegistry to use |
Definition at line 1115 of file shm.cpp.
References fawkes::SharedMemory::SharedMemoryIterator::databuf(), fawkes::SemaphoreSet::destroy(), end(), find(), fawkes::SharedMemoryLister::print_footer(), fawkes::SharedMemoryLister::print_header(), fawkes::SharedMemoryLister::print_info(), fawkes::SharedMemoryLister::print_no_segments(), fawkes::SharedMemory::SharedMemoryIterator::segmsize(), fawkes::SharedMemory::SharedMemoryIterator::semaphore(), and fawkes::SharedMemory::SharedMemoryIterator::shmid().
|
static |
Erase orphaned (attach count = 0) shared memory segments of a given type.
This method erases (destroys) all shared memory segments that match the given magic token (first MagicTokenSize bytes, filled with zero) and the given header and where no process is attached to. If a semaphore has been assigned to this shared memory segment it is destroyed as well. The lister is called to format the output.
magic_token | Token to look for |
header | header to identify interesting segments with matching magic_token |
lister | Lister used to format output, maybe NULL (default) |
registry_name | name of the SharedMemoryRegistry to use |
Definition at line 1163 of file shm.cpp.
References fawkes::SharedMemory::SharedMemoryIterator::databuf(), fawkes::SemaphoreSet::destroy(), end(), find(), fawkes::SharedMemoryLister::print_footer(), fawkes::SharedMemoryLister::print_header(), fawkes::SharedMemoryLister::print_info(), fawkes::SharedMemoryLister::print_no_orphaned_segments(), fawkes::SharedMemoryLister::print_no_segments(), fawkes::SharedMemory::SharedMemoryIterator::segmnattch(), fawkes::SharedMemory::SharedMemoryIterator::segmsize(), fawkes::SharedMemory::SharedMemoryIterator::semaphore(), and fawkes::SharedMemory::SharedMemoryIterator::shmid().
Referenced by fawkes::LocalBlackBoard::cleanup().
|
static |
Check if a specific shared memory segment exists.
This method will search for a memory chunk that matches the given magic token and header.
magic_token | Token to look for |
header | header to identify interesting segments with matching magic_token |
registry_name | name of the SharedMemoryRegistry to use |
|
static |
Find SharedMemory segments.
Find SharedMemory segments identified by the supplied magic_token and header.
magic_token | magic token |
header | shared memory header |
registry_name | name of the SharedMemoryRegistry to use |
Definition at line 1237 of file shm.cpp.
References end(), and fawkes::SharedMemoryRegistry::find_segments().
Referenced by erase(), erase_orphaned(), exists(), and list().
|
protected |
Detach from and maybe destroy the shared memory segment.
This will detach from the shared memory segment. If destroy_on_delete is true this will destroy the shared memory segment before detaching.
Definition at line 423 of file shm.cpp.
References _destroy_on_delete, _is_read_only, _memptr, _shm_header, _shm_magic_token, and fawkes::SharedMemoryRegistry::remove_segment().
Referenced by attach(), firevision::SharedMemoryImageBufferHeader::reset(), firevision::SharedMemoryImageBufferHeader::set(), firevision::SharedMemoryImageBufferHeader::set_frame_id(), firevision::SharedMemoryImageBufferHeader::set_image_id(), firevision::SharedMemoryImageBuffer::set_image_id(), firevision::SharedMemoryLookupTableHeader::set_lut_id(), firevision::SharedMemoryLookupTable::set_lut_id(), firevision::SharedMemoryImageBuffer::SharedMemoryImageBuffer(), ~SharedMemory(), firevision::SharedMemoryImageBuffer::~SharedMemoryImageBuffer(), firevision::SharedMemoryImageBufferHeader::~SharedMemoryImageBufferHeader(), firevision::SharedMemoryLookupTable::~SharedMemoryLookupTable(), and firevision::SharedMemoryLookupTableHeader::~SharedMemoryLookupTableHeader().
bool fawkes::SharedMemory::is_creator | ( | ) | const |
Determine if the shared memory segment has been created by this instance.
In some situations you want to know if the current instance has created the shared memory segment or if it attached to an existing shared memory segment. This is handy for example in master-slave constellations where one process is the master over a given shared memory segment and other slaves may read but need special means to alter the data. This is a somewhat softer variant of exclusive access.
Definition at line 670 of file shm.cpp.
Referenced by fawkes::BlackBoardMemoryManager::BlackBoardMemoryManager().
bool fawkes::SharedMemory::is_destroyed | ( | ) | const |
Check if segment has been destroyed This can be used if the segment has been destroyed.
This means that no other process can connect to the shared memory segment. As long as some process is attached to the shared memory segment the segment will still show up in the list
|
static |
bool fawkes::SharedMemory::is_protected | ( | ) | const |
Check if memory segment is protected.
This method can be used to determine if a semaphore has been associated to this shared memory segment. Locking is not guaranteed, it depends on the application. Use lock(), tryLock() and unlock() appropriately. You can do this always, also if you start with unprotected memory. The operations are just noops in that case. Protection can be enabled by calling add_semaphore(). If a memory segment was protected when it was opened it is automatically opened in protected mode.
bool fawkes::SharedMemory::is_read_only | ( | ) | const |
Check for read-only mode.
Definition at line 653 of file shm.cpp.
References _is_read_only.
Referenced by SharedMemory(), firevision::SharedMemoryImageBuffer::SharedMemoryImageBuffer(), and firevision::SharedMemoryLookupTable::SharedMemoryLookupTable().
bool fawkes::SharedMemory::is_swapable | ( | ) | const |
|
static |
bool fawkes::SharedMemory::is_valid | ( | ) | const |
Check validity of shared memory segment.
Use this to check if the shared memory segmentis valid. That means that this instance is attached to the shared memory and data can be read from or written to the memptr.
Definition at line 766 of file shm.cpp.
References _memptr.
Referenced by fawkes::BlackBoardMemoryManager::BlackBoardMemoryManager(), and FvRetrieverThread::init().
|
static |
List shared memory segments of a given type.
This method lists all shared memory segments that match the given magic token (first MagicTokenSize bytes, filled with zero) and the given header. The lister is called to format the output.
magic_token | Token to look for |
header | header to identify interesting segments with matching magic_token |
lister | Lister used to format output |
registry_name | name of the SharedMemoryRegistry to use |
Definition at line 1079 of file shm.cpp.
References fawkes::SharedMemory::SharedMemoryIterator::databuf(), end(), find(), fawkes::SharedMemoryLister::print_footer(), fawkes::SharedMemoryLister::print_header(), fawkes::SharedMemoryLister::print_info(), fawkes::SharedMemoryLister::print_no_segments(), fawkes::SharedMemory::SharedMemoryIterator::segmsize(), fawkes::SharedMemory::SharedMemoryIterator::semaphore(), and fawkes::SharedMemory::SharedMemoryIterator::shmid().
void fawkes::SharedMemory::lock_for_read | ( | ) |
Lock shared memory segment for reading.
If the shared memory segment is protected by an associated semaphore it can be locked with this semaphore by calling this method.
Definition at line 867 of file shm.cpp.
References fawkes::SemaphoreSet::lock().
Referenced by firevision::FuseImageContent::FuseImageContent(), firevision::SharedMemoryCamera::lock_for_read(), and OpenNiPclOnlyThread::loop().
void fawkes::SharedMemory::lock_for_write | ( | ) |
Lock shared memory segment for writing.
If the shared memory segment is protected by an associated semaphore it can be locked with this semaphore by calling this method.
Definition at line 918 of file shm.cpp.
References fawkes::SemaphoreSet::lock(), MaxNumConcurrentReaders, and fawkes::SemaphoreSet::unlock().
Referenced by fawkes::BlackBoardMemoryManager::alloc(), OpenNiPointCloudThread::finalize(), fawkes::BlackBoardMemoryManager::free(), fawkes::BlackBoardMemoryManager::lock(), FvRetrieverThread::loop(), OpenNiImageThread::loop(), and Bumblebee2Thread::loop().
void * fawkes::SharedMemory::memptr | ( | ) | const |
Get a pointer to the shared memory This method returns a pointer to the data-segment of the shared memory segment.
It has the size stated as dataSize() from the header.
Definition at line 682 of file shm.cpp.
References _memptr.
Referenced by fawkes::BlackBoardMemoryManager::BlackBoardMemoryManager().
unsigned int fawkes::SharedMemory::num_attached | ( | ) | const |
Get number of attached processes.
Definition at line 714 of file shm.cpp.
Referenced by OpenNiDepthThread::loop(), OpenNiPclOnlyThread::loop(), OpenNiImageThread::loop(), OpenNiUserTrackerThread::loop(), Bumblebee2Thread::loop(), and OpenNiPointCloudThread::loop().
|
static |
void * fawkes::SharedMemory::ptr | ( | void * | addr | ) | const |
Get the real pointer to the data based on an address.
If there is address-dependent data in the shared memory segment (like pointers to the next element in a linked list) these are only valid for the process that created the shared memory segment, they are not necessarily valid for other processes.
The function takes an address that has been stored in the shared memory segment and transforms it into a valid local pointer. Not that this does only work with pointers inside the shared memory segment. You can only tranform addresses that point to somewhere inside the shared memory segment!
We could also have added local offsets, starting with 0 at the beginning of the shared memory segment. We decided against this since our major our main concern is that this works fast for the master, because this will be the Fawkes main application, and for attached processes it may work slower and we don't care.
addr | memory address read from the shared memory segment |
ShmAddrOutOfBoundsException | This exception is thrown if addr is not NULL, smaller than the base addr and greater or equal to the base addr plus the memory size. |
Definition at line 606 of file shm.cpp.
References _shm_offset, _shm_upper_bound, and addr().
Referenced by addr(), fawkes::BlackBoardSharedMemoryHeader::alloc_list_head(), fawkes::BlackBoardSharedMemoryHeader::free_list_head(), fawkes::BlackBoardMemoryManager::ChunkIterator::operator*(), and fawkes::BlackBoardMemoryManager::~BlackBoardMemoryManager().
void fawkes::SharedMemory::set | ( | void * | memptr | ) |
Copies data from the memptr to shared memory.
Use this method to copy data from the given external memptr to the data segment of the shared memory.
memptr | the memptr to copy from |
Definition at line 726 of file shm.cpp.
References _data_size, and _memptr.
void fawkes::SharedMemory::set_destroy_on_delete | ( | bool | destroy | ) |
Set deletion behaviour.
This has the same effect as the destroy_on_delete parameter given to the constructor.
destroy | set to true to destroy the shared memory segment on deletion |
Definition at line 796 of file shm.cpp.
References _destroy_on_delete.
Referenced by fawkes::BlackBoardMemoryManager::BlackBoardMemoryManager().
void fawkes::SharedMemory::set_swapable | ( | bool | swapable | ) |
Set shared memory swapable.
Setting memory unswapable (in terms of Linux memory management: lock all pages related to this memory segment) will only succeed for very small portions of memory. A resource limit is implied (see getrlimit(2)). In most cases the maximum amout of locked memory is about 32 KB.
swapable | set to true, if memory should be allowed to be swaped out. |
Definition at line 847 of file shm.cpp.
Referenced by fawkes::BlackBoardMemoryManager::BlackBoardMemoryManager().
int fawkes::SharedMemory::shmem_id | ( | ) | const |
bool fawkes::SharedMemory::try_lock_for_read | ( | ) |
Try to aquire lock on shared memory segment for reading.
If the shared memory segment is protected by an associated semaphore it can be locked. With tryLock() you can try to aquire the lock, but the method will not block if it cannot get the lock but simply return false. This can be used to detect if memory is locked:
Definition at line 897 of file shm.cpp.
References fawkes::SemaphoreSet::try_lock().
bool fawkes::SharedMemory::try_lock_for_write | ( | ) |
Try to aquire lock on shared memory segment for writing.
If the shared memory segment is protected by an associated semaphore it can be locked. With tryLock() you can try to aquire the lock, but the method will not block if it cannot get the lock but simply return false. This can be used to detect if memory is locked:
Definition at line 953 of file shm.cpp.
References MaxNumConcurrentReaders, fawkes::SemaphoreSet::try_lock(), and fawkes::SemaphoreSet::unlock().
Referenced by fawkes::BlackBoardMemoryManager::try_lock().
void fawkes::SharedMemory::unlock | ( | ) |
Unlock memory.
If the shared memory segment is protected by an associated semaphore it can be locked. With unlock() you lift the lock on the memory. Be aware that unlocking a not-locked piece of memory will result in havoc and insanity! Have only exactly guaranteed pairs of lock/successful tryLock() and unlock()!
Definition at line 985 of file shm.cpp.
References MaxNumConcurrentReaders, and fawkes::SemaphoreSet::unlock().
Referenced by fawkes::BlackBoardMemoryManager::alloc(), OpenNiPointCloudThread::finalize(), fawkes::BlackBoardMemoryManager::free(), firevision::FuseImageContent::FuseImageContent(), FvRetrieverThread::loop(), OpenNiPclOnlyThread::loop(), OpenNiImageThread::loop(), Bumblebee2Thread::loop(), and fawkes::BlackBoardMemoryManager::unlock().
|
protected |
Size of the data segment only.
Definition at line 179 of file shm.h.
Referenced by attach(), data_size(), set(), and SharedMemory().
|
protected |
destroy on delete.
If true before free() segment is destroyed.
Definition at line 182 of file shm.h.
Referenced by free(), set_destroy_on_delete(), SharedMemory(), and ~SharedMemory().
|
protected |
Data-specific header.
Definition at line 180 of file shm.h.
Referenced by attach(), firevision::SharedMemoryImageBufferHeader::colorspace(), firevision::SharedMemoryImageBufferHeader::data_size(), firevision::SharedMemoryImageBufferHeader::height(), firevision::SharedMemoryImageBufferHeader::initialize(), firevision::SharedMemoryImageBufferHeader::print_info(), firevision::SharedMemoryImageBufferHeader::raw_header(), firevision::SharedMemoryImageBufferHeader::reset(), firevision::SharedMemoryImageBufferHeader::set(), SharedMemory(), firevision::SharedMemoryImageBuffer::SharedMemoryImageBuffer(), firevision::SharedMemoryImageBufferHeader::SharedMemoryImageBufferHeader(), firevision::SharedMemoryLookupTable::SharedMemoryLookupTable(), and firevision::SharedMemoryImageBufferHeader::width().
|
protected |
Read-only.
if true before attach() open segment read-only
Definition at line 181 of file shm.h.
Referenced by add_semaphore(), attach(), free(), is_read_only(), firevision::SharedMemoryImageBuffer::set_capture_time(), firevision::SharedMemoryImageBuffer::set_circle(), firevision::SharedMemoryImageBuffer::set_circle_radius(), firevision::SharedMemoryImageBuffer::set_circle_x(), firevision::SharedMemoryImageBuffer::set_circle_y(), firevision::SharedMemoryImageBuffer::set_roi(), firevision::SharedMemoryImageBuffer::set_roi_height(), firevision::SharedMemoryImageBuffer::set_roi_width(), firevision::SharedMemoryImageBuffer::set_roi_x(), firevision::SharedMemoryImageBuffer::set_roi_y(), SharedMemory(), firevision::SharedMemoryImageBuffer::SharedMemoryImageBuffer(), firevision::SharedMemoryLookupTable::SharedMemoryLookupTable(), and ~SharedMemory().
|
protected |
Magic token.
Definition at line 184 of file shm.h.
Referenced by attach(), SharedMemory(), and ~SharedMemory().
|
protected |
|
protected |
Pointer to the data segment.
Definition at line 177 of file shm.h.
Referenced by add_semaphore(), attach(), firevision::SharedMemoryLookupTable::buffer(), firevision::SharedMemoryImageBuffer::buffer(), free(), is_valid(), memptr(), set(), firevision::SharedMemoryImageBuffer::set_image_id(), firevision::SharedMemoryLookupTable::set_lut_id(), SharedMemory(), and firevision::SharedMemoryLookupTable::SharedMemoryLookupTable().
|
protected |
general header as stored in the shared memory segment
Definition at line 186 of file shm.h.
Referenced by add_semaphore(), attach(), free(), SharedMemory(), and ~SharedMemory().
|
protected |
Magic token as stored in the shared memory segment.
Definition at line 185 of file shm.h.
Referenced by attach(), free(), and SharedMemory().
|
protected |
|
protected |
|
protected |
Create shared memory segment.
If true before attach shared memory segment is created if it does not exist.
Definition at line 183 of file shm.h.
Referenced by attach(), and SharedMemory().
|
static |
The magic token size.
Your magic token identifier may have an arbitrary size. It is truncated at MagicTokenSize bytes or filled with zeros up to a length of MagicTokenSize bytes.
Definition at line 54 of file shm.h.
Referenced by attach(), fawkes::SharedMemory::SharedMemoryIterator::operator++(), and SharedMemory().
|
static |
Maximum number of concurrent readers.
This constant defines how many readers may concurrently read from shared memory segments.
Definition at line 55 of file shm.h.
Referenced by add_semaphore(), lock_for_write(), try_lock_for_write(), and unlock().