UCommon
Public Member Functions | Protected Member Functions
ucommon::MappedReuse Class Reference

Map a reusable allocator over a named shared memory segment. More...

#include <mapped.h>

Inheritance diagram for ucommon::MappedReuse:
Inheritance graph
[legend]
Collaboration diagram for ucommon::MappedReuse:
Collaboration graph
[legend]

Public Member Functions

bool avail (void)
 Check whether there are objects available to be allocated.
ReusableObjectget (void)
 Request a reusable object from the free list or mapped space.
ReusableObjectgetLocked (void)
 Used to get an object from the reuse pool when the mutex lock is already held.
ReusableObjectgetTimed (timeout_t timeout)
 Request a reusable object from the free list or mapped space.
 MappedReuse (char *name, size_t size, unsigned count)
 Construct a named memory segment for use with managed fixed size reusable objects.
void removeLocked (ReusableObject *object)
 Used to return an object to the reuse pool when the mutex lock is already held.
ReusableObjectrequest (void)
 Request a reusable object from the free list or mapped space.

Protected Member Functions

void create (char *fname, unsigned count)
 MappedReuse (size_t osize)
- Protected Member Functions inherited from ucommon::MappedMemory
void copy (size_t offset, void *buffer, size_t size)
 Copy memory from specific offset within the mapped memory segment.
caddr_t getStart (void)
 Get starting address of mapped segment.
size_t len (void)
 Get size of mapped segment.
 MappedMemory (char *name, size_t size)
 Construct a read/write access mapped shared segment of memory of a known size.
 MappedMemory (char *name)
 Provide read-only mapped access to an existing named shared memory segment.
void * offset (size_t offset)
 Get memory from a specific offset within the mapped memory segment.
 operator bool ()
 Test if map active.
bool operator! ()
 Test if map is inactive.
void release (void)
 Unmap memory segment.
void * sbrk (size_t size)
 Extend size of managed heap on shared memory segment.
virtual ~MappedMemory ()
 Unmap memory segment.
void create (char *name, size_t size=(size_t) 0)
 Supporting function to construct a new or access an existing shared memory segment.
virtual void fault (void)
 Handler to invoke in derived class when accessing outside the shared memory segment boundary.

Additional Inherited Members

- Static Protected Member Functions inherited from ucommon::MappedMemory
static void disable (void)
 An API that allows "disabling" of publishing shared memory maps.
static void remove (char *name)
 Destroy a previously existing memory segment under the specified name.

Detailed Description

Map a reusable allocator over a named shared memory segment.

This may be used to form a resource bound fixed size managed heap in shared memory. The request can either be fulfilled from the object reuse pool or from a new section of memory, and if all memory in the segment has been exhausted, it can wait until more objects are returned by another thread to the reuse pool.

Author:
David Sugar dyfet.nosp@m.@gnu.nosp@m.telep.nosp@m.hony.nosp@m..org

Definition at line 193 of file mapped.h.


Constructor & Destructor Documentation

ucommon::MappedReuse::MappedReuse ( char *  name,
size_t  size,
unsigned  count 
)

Construct a named memory segment for use with managed fixed size reusable objects.

The segment is created as writable. There is no read-only version of mapped reuse since the mapped segment can be read by another process directly as a mapped read-only vector. The actual mapped type will be derived from ReusableObject to meet the needs of the reusable allocator. The template version should be used to assure type correctness rather than using this class directly.

Parameters:
nameof shared memory segment.
sizeof the object type being mapped.
countof the maximum number of active mapped objects.

Member Function Documentation

bool ucommon::MappedReuse::avail ( void  )

Check whether there are objects available to be allocated.

Returns:
true if objects are available.
ReusableObject* ucommon::MappedReuse::get ( void  )

Request a reusable object from the free list or mapped space.

This method blocks until an object becomes available.

Returns:
free object.

Reimplemented in ucommon::mapped_reuse< T >.

ReusableObject* ucommon::MappedReuse::getLocked ( void  )

Used to get an object from the reuse pool when the mutex lock is already held.

Returns:
object from pool or NULL if exhausted.

Reimplemented in ucommon::mapped_reuse< T >.

ReusableObject* ucommon::MappedReuse::getTimed ( timeout_t  timeout)

Request a reusable object from the free list or mapped space.

This method blocks until an object becomes available or the timeout has expired.

Parameters:
timeoutto wait in milliseconds.
Returns:
free object or NULL if timeout.

Reimplemented in ucommon::mapped_reuse< T >.

void ucommon::MappedReuse::removeLocked ( ReusableObject object)

Used to return an object to the reuse pool when the mutex lock is already held.

Parameters:
objectbeing returned.
ReusableObject* ucommon::MappedReuse::request ( void  )

Request a reusable object from the free list or mapped space.

Returns:
free object or NULL if pool is exhausted.

Reimplemented in ucommon::mapped_reuse< T >.


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