Fawkes API  Fawkes Development Version
fawkes::SharedMemoryRegistry Class Reference

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::SharedMemIDget_snapshot () const
 Get a snapshot of currently registered segments. More...
 
std::list< SharedMemoryRegistry::SharedMemIDfind_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...
 

Detailed Description

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.

Author
Tim Niemueller

Definition at line 40 of file shm_registry.h.

Constructor & Destructor Documentation

◆ SharedMemoryRegistry()

fawkes::SharedMemoryRegistry::SharedMemoryRegistry ( const char *  name = 0)

Constructor.

Parameters
namename 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.

◆ ~SharedMemoryRegistry()

fawkes::SharedMemoryRegistry::~SharedMemoryRegistry ( )

Destructor.

Definition at line 128 of file shm_registry.cpp.

Member Function Documentation

◆ add_segment()

void fawkes::SharedMemoryRegistry::add_segment ( int  shmid,
const char *  magic_token 
)

Register a segment.

Parameters
shmidshared memory ID of the SysV IPC segment
magic_tokenmagic token for the new segment

Definition at line 204 of file shm_registry.cpp.

Referenced by fawkes::SharedMemory::attach().

◆ cleanup()

void fawkes::SharedMemoryRegistry::cleanup ( const char *  name = 0)
static

Cleanup existing shared memory segments.

Parameters
nameshared memory segment name

Definition at line 144 of file shm_registry.cpp.

◆ find_segments()

std::list< SharedMemoryRegistry::SharedMemID > fawkes::SharedMemoryRegistry::find_segments ( const char *  magic_token) const

Find segments with particular magic token.

Parameters
magic_tokenmagic token to return IDs for
Returns
list of segments that currently exist with the given magic token

Definition at line 178 of file shm_registry.cpp.

Referenced by fawkes::SharedMemory::attach(), and fawkes::SharedMemory::find().

◆ get_snapshot()

std::list< SharedMemoryRegistry::SharedMemID > fawkes::SharedMemoryRegistry::get_snapshot ( ) const

Get a snapshot of currently registered segments.

Returns
list of all currently registered segments

Definition at line 154 of file shm_registry.cpp.

◆ remove_segment()

void fawkes::SharedMemoryRegistry::remove_segment ( int  shmid)

Remove segment.

Parameters
shmidshared memory ID of the segment to remove.

Definition at line 236 of file shm_registry.cpp.

Referenced by fawkes::SharedMemory::free().


The documentation for this class was generated from the following files: