Fawkes API
Fawkes Development Version
|
Shared memory registry. More...
#include <>>
Classes | |
struct | SharedMemID |
Shared memory identifier. More... | |
Public Member Functions | |
SharedMemoryRegistry (const char *name=0) | |
Constructor. More... | |
~SharedMemoryRegistry () | |
Destructor. More... | |
std::list< SharedMemoryRegistry::SharedMemID > | get_snapshot () const |
Get a snapshot of currently registered segments. More... | |
std::list< SharedMemoryRegistry::SharedMemID > | find_segments (const char *magic_token) const |
Find segments with particular magic token. More... | |
void | add_segment (int shmid, const char *magic_token) |
Register a segment. More... | |
void | remove_segment (int shmid) |
Remove segment. More... | |
Static Public Member Functions | |
static void | cleanup (const char *name=0) |
Cleanup existing shared memory segments. More... | |
Shared memory registry.
This class opens a named POSIX shared memory segment, which contains one instance of the MemInfo struct. It is used to detect and maintain existing SysV IPC shared memory segments in a platform independent way. SysV IPC shared memory segments have some advanced functionality, for example reporting how many processes have attached to the segment. For the registry however, we are more interested in using a symbolic name which is the same for registry entries. Therefore, we use this here. The struct is protected by a lock implemented as a semaphore. Whenever a shared memory segment is created, it is registered to the registry so others can find it. On destruction, it is unregistered from the registry.
Definition at line 40 of file shm_registry.h.
fawkes::SharedMemoryRegistry::SharedMemoryRegistry | ( | const char * | name = 0 | ) |
Constructor.
name | name of the shared memory region. Must follow the rules set by shm_open(). If NULL defaults to "/fawkes-shmem-registry". |
Definition at line 62 of file shm_registry.cpp.
fawkes::SharedMemoryRegistry::~SharedMemoryRegistry | ( | ) |
Destructor.
Definition at line 128 of file shm_registry.cpp.
void fawkes::SharedMemoryRegistry::add_segment | ( | int | shmid, |
const char * | magic_token | ||
) |
Register a segment.
shmid | shared memory ID of the SysV IPC segment |
magic_token | magic token for the new segment |
Definition at line 204 of file shm_registry.cpp.
Referenced by fawkes::SharedMemory::attach().
|
static |
Cleanup existing shared memory segments.
name | shared memory segment name |
Definition at line 144 of file shm_registry.cpp.
std::list< SharedMemoryRegistry::SharedMemID > fawkes::SharedMemoryRegistry::find_segments | ( | const char * | magic_token | ) | const |
Find segments with particular magic token.
magic_token | magic token to return IDs for |
Definition at line 178 of file shm_registry.cpp.
Referenced by fawkes::SharedMemory::attach(), and fawkes::SharedMemory::find().
std::list< SharedMemoryRegistry::SharedMemID > fawkes::SharedMemoryRegistry::get_snapshot | ( | ) | const |
Get a snapshot of currently registered segments.
Definition at line 154 of file shm_registry.cpp.
void fawkes::SharedMemoryRegistry::remove_segment | ( | int | shmid | ) |
Remove segment.
shmid | shared memory ID of the segment to remove. |
Definition at line 236 of file shm_registry.cpp.
Referenced by fawkes::SharedMemory::free().