Image Component Library (ICL)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Public Member Functions | Private Attributes
icl::io::SharedMemorySegment Class Reference

Implementation of a cross-process shared memory. More...

#include <SharedMemorySegment.h>

List of all members.

Public Member Functions

 SharedMemorySegment (std::string name="", int minsize=1)
 Creates a SharedMemorySegment instance.
 ~SharedMemorySegment ()
 The destructor basically calls release.
void release ()
 Releases the acuired SharedMemorySegment.
std::string getName ()
 Returns the current SharedMemorySegments name.
void reset (std::string name, int minsize=0)
 Sets name and minsize to the passed values.
bool isAttached ()
 Tells whether this instance is currently attached to a SharedMemory.
bool lock (int minsize=0)
 Locks the underlying SharedMemorySegment, aquireing when needed.
bool unlock ()
 Unlocks the underlying SharedMemorySegment.
void forceMinSize (int minsize)
 Forces a resize of the SharedMemory to the passed minsize.
int getSize ()
 Returns the current size of the SharedMemorySegment in bytes.
bool isEmpty () const
 Tells whether the Segment is empty.
void * data ()
 getter for the MemorySegment data.
const void * data () const
 implicit const getter for the MemorySegment data.
const void * constData () const
 explicit const getter for the MemorySegment data.

Private Attributes

utils::Mutex m_Mutex
 instance locking
Impl * m_Impl
 pointer to the internal implementation
std::string m_Name
 the current name of the SharedMemorySegment
int m_Minsize
 local minimal size tf the Segment

Detailed Description

Implementation of a cross-process shared memory.

The SharedMemorySegment can be used to share information between multiple processes on a single system.

This class uses in iternal singleton implementation and map allowing multiple thereads to read a ShredMemory concurrent. The drawback is that external locking is needed for concurrent reading and writing.

Created SharedMemorySegments are registered via the SharedMemorySegmentRegister.

A signal handler is installed to ensure that all SharedMemorySegments are released.


Constructor & Destructor Documentation

icl::io::SharedMemorySegment::SharedMemorySegment ( std::string  name = "",
int  minsize = 1 
)

Creates a SharedMemorySegment instance.

No memory allocation is done here. To connect to the corresponding SharedMemorySegment call lock().

Parameters:
nameThe name identifying the segment.
minsizeThe minimal needed size.

The destructor basically calls release.


Member Function Documentation

explicit const getter for the MemorySegment data.

Returns:
a pointer to the memory block. Null when not attached or not locked.

getter for the MemorySegment data.

Returns:
a pointer to the memory block. Null when not attached or not locked.
const void* icl::io::SharedMemorySegment::data ( ) const

implicit const getter for the MemorySegment data.

Returns:
a pointer to the memory block. Null when not attached or not locked.

Forces a resize of the SharedMemory to the passed minsize.

This can shrink the SharedMemorySegment when the current space is no longer needed. It will force a recreation of the underlying SharedMemory to the passed size. It will not prevend other processes from re-enlarging the Segment. Caution: Don't use this to ensure that the SharedMemory is large enough. Call lock() with the desired size instead.

Returns the current SharedMemorySegments name.

Returns the current size of the SharedMemorySegment in bytes.

Returns:
-1 when this instance is not attached

Tells whether this instance is currently attached to a SharedMemory.

Attachment is performed lock() and detachment release().

Tells whether the Segment is empty.

Basically checks whether all data bits are zero. A freshly created SharedMemorySegment is always overwritten with zeros.

bool icl::io::SharedMemorySegment::lock ( int  minsize = 0)

Locks the underlying SharedMemorySegment, aquireing when needed.

Here happens all the fun. When this instance is not connected, it will be connected. When minsize > getSize or a resize is requested, this will detach and reattach/recreate with the needed size. Every call to lock needs a call to unlock. Multiple threads of the same process cat get the lock simultaneously. That way, concurrent access in one process is possible but extra locking is necessary when this is not desired. Can return true without having the necessary size when already locked by this process.

Returns:
whether the segment is locked. may sometimes not be reached, when this process already holds the lock.

Releases the acuired SharedMemorySegment.

When the last instance calls release the underlying singleton implementation unlocks and detatches from the systems SharedMemory.

void icl::io::SharedMemorySegment::reset ( std::string  name,
int  minsize = 0 
)

Sets name and minsize to the passed values.

This function just sets the variables. Potential releasing and reattaching happens on the following lock().

Unlocks the underlying SharedMemorySegment.

Returns:
whether the segment is not locked. true when still locked.

Member Data Documentation

pointer to the internal implementation

local minimal size tf the Segment

instance locking

std::string icl::io::SharedMemorySegment::m_Name [private]

the current name of the SharedMemorySegment


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines