UCommon
ucommon::mapped_reuse< T > Class Template Reference

Template class to map typed reusable objects into shared memory heap. More...

#include <mapped.h>

Inheritance diagram for ucommon::mapped_reuse< T >:
Collaboration diagram for ucommon::mapped_reuse< T >:

Public Member Functions

T * get (void)
 Request a typed reusable object from the free list or mapped space.
 
T * getLocked (void)
 Used to get a typed object from the reuse pool when the mutex lock is already held.
 
T * getTimed (timeout_t timeout)
 Request a typed reusable object from the free list or mapped space.
 
void initialize (void)
 Initialize typed data in mapped array.
 
 mapped_reuse (const char *name, unsigned number)
 Construct mapped reuse array of typed objects.
 
 operator bool () const
 Check whether there are typed objects available to be allocated.
 
 operator T* ()
 Request a typed reusable object from the free list or mapped space.
 
bool operator! () const
 Check whether there are typed objects available to be allocated.
 
T * operator* ()
 Request a typed reusable object from the free list or mapped space by pointer reference.
 
T * pos (size_t member)
 Get typed object from a specific member offset within the mapped segment.
 
void release (T *object)
 Used to release a typed object back to the reuse typed object pool.
 
void removeLocked (T *object)
 Used to return a typed object to the reuse pool when the mutex lock is already held.
 
T * request (void)
 Request a typed reusable object from the free list or mapped space.
 
- Public Member Functions inherited from ucommon::MappedReuse
bool avail (void) const
 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 (const 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.
 

Additional Inherited Members

- Protected Member Functions inherited from ucommon::MappedReuse
void create (const char *fname, unsigned count)
 
 MappedReuse (size_t osize)
 
- Protected Member Functions inherited from ucommon::ReusableAllocator
ReusableObjectnext (ReusableObject *object)
 Get next reusable object in the pool.
 
void release (ReusableObject *object)
 Release resuable object.
 
 ReusableAllocator ()
 Initialize reusable allocator through a conditional.
 
- Protected Member Functions inherited from ucommon::Conditional
void broadcast (void)
 Signal the conditional to release all waiting threads.
 
 Conditional ()
 Initialize and construct conditional.
 
void signal (void)
 Signal the conditional to release one waiting thread.
 
bool wait (struct timespec *timeout)
 Conditional wait for signal on timespec timeout.
 
bool wait (timeout_t timeout)
 Conditional wait for signal on millisecond timeout.
 
void wait (void)
 Wait (block) until signalled.
 
 ~Conditional ()
 Destroy conditional, release any blocked threads.
 
- Protected Member Functions inherited from ucommon::ConditionMutex
 ConditionMutex ()
 Initialize and construct conditional.
 
void lock (void)
 Lock the conditional's supporting mutex.
 
void unlock (void)
 Unlock the conditional's supporting mutex.
 
 ~ConditionMutex ()
 Destroy conditional, release any blocked threads.
 
- Protected Member Functions inherited from ucommon::MappedMemory
void create (const char *name, size_t size=(size_t) 0)
 Supporting function to construct a new or access an existing shared memory segment.
 
caddr_t addr (void)
 Get starting address of mapped segment.
 
bool copy (size_t offset, void *buffer, size_t size) const
 Copy memory from specific offset within the mapped memory segment.
 
size_t len (void) const
 Get size of mapped segment.
 
 MappedMemory (const char *name)
 Provide read-only mapped access to an existing named shared memory segment.
 
 MappedMemory (const char *name, size_t size)
 Construct a read/write access mapped shared segment of memory of a known size.
 
void * offset (size_t offset) const
 Get memory from a specific offset within the mapped memory segment.
 
 operator bool () const
 Test if map active.
 
bool operator! () const
 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.
 
- Static Protected Member Functions inherited from ucommon::Conditional
static pthread_condattr_t * initializer (void)
 Support function for getting conditional attributes for realtime scheduling.
 
static void set (struct timespec *hires, timeout_t timeout)
 Convert a millisecond timeout into use for high resolution conditional timers.
 
- 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 (const char *name)
 Destroy a previously existing memory segment under the specified name.
 
- Protected Attributes inherited from ucommon::ReusableAllocator
ReusableObjectfreelist
 
unsigned waiting
 
- Protected Attributes inherited from ucommon::Conditional
pthread_cond_t cond
 
- Protected Attributes inherited from ucommon::ConditionMutex
pthread_mutex_t mutex
 
- Protected Attributes inherited from ucommon::MappedMemory
bool erase
 
char idname [65]
 
size_t size
 
size_t used
 
- Static Protected Attributes inherited from ucommon::Conditional
static attribute attr
 

Detailed Description

template<class T>
class ucommon::mapped_reuse< T >

Template class to map typed reusable objects into shared memory heap.

This is used to construct a read/write heap of objects that are held in a named shared memory segment. Member objects are allocated from a reusable heap but are stored in the shared memory segment as a vector.

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

Definition at line 347 of file mapped.h.

Constructor & Destructor Documentation

◆ mapped_reuse() [1/2]

template<class T >
ucommon::mapped_reuse< T >::mapped_reuse ( )
inlineprotected

Definition at line 353 of file mapped.h.

◆ mapped_reuse() [2/2]

template<class T >
ucommon::mapped_reuse< T >::mapped_reuse ( const char * name,
unsigned number )
inline

Construct mapped reuse array of typed objects.

This is constructed for read/write access. mapped_view is used in all cases for read-only access to mapped data.

Parameters
nameof mapped segment to construct.
numberof objects in the mapped vector.

Definition at line 364 of file mapped.h.

Member Function Documentation

◆ get()

template<class T >
T * ucommon::mapped_reuse< T >::get ( void )
inline

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

This method blocks until an object becomes available.

Returns
free typed object.

Definition at line 417 of file mapped.h.

Here is the call graph for this function:

◆ getLocked()

template<class T >
T * ucommon::mapped_reuse< T >::getLocked ( void )
inline

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

Returns
typed object from pool or NULL if exhausted.

Definition at line 451 of file mapped.h.

Here is the call graph for this function:

◆ getTimed()

template<class T >
T * ucommon::mapped_reuse< T >::getTimed ( timeout_t timeout)
inline

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

This method blocks until an object becomes available from another thread or the timeout expires.

Parameters
timeoutin milliseconds.
Returns
free typed object.

Definition at line 427 of file mapped.h.

Here is the call graph for this function:

◆ initialize()

template<class T >
void ucommon::mapped_reuse< T >::initialize ( void )
inline

Initialize typed data in mapped array.

Assumes default constructor for type.

Definition at line 371 of file mapped.h.

Here is the call graph for this function:

◆ operator bool()

template<class T >
ucommon::mapped_reuse< T >::operator bool ( ) const
inline

Check whether there are typed objects available to be allocated.

Returns
true if objects are available.

Definition at line 378 of file mapped.h.

Here is the call graph for this function:

◆ operator T*()

template<class T >
ucommon::mapped_reuse< T >::operator T* ( )
inline

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

This method blocks until an object becomes available.

Returns
free object.

Definition at line 393 of file mapped.h.

Here is the call graph for this function:

◆ operator!()

template<class T >
bool ucommon::mapped_reuse< T >::operator! ( ) const
inline

Check whether there are typed objects available to be allocated.

Returns
true if no more typed objects are available.

Definition at line 385 of file mapped.h.

Here is the call graph for this function:

◆ operator*()

template<class T >
T * ucommon::mapped_reuse< T >::operator* ( )
inline

Request a typed reusable object from the free list or mapped space by pointer reference.

This method blocks until an object becomes available.

Returns
free object.

Definition at line 401 of file mapped.h.

Here is the call graph for this function:

◆ pos()

template<class T >
T * ucommon::mapped_reuse< T >::pos ( size_t member)
inline

Get typed object from a specific member offset within the mapped segment.

Parameters
memberoffset from start of segment. Will fault if past end.
Returns
typed object pointer.

Definition at line 409 of file mapped.h.

Here is the call graph for this function:

◆ release()

template<class T >
void ucommon::mapped_reuse< T >::release ( T * object)
inline

Used to release a typed object back to the reuse typed object pool.

Parameters
objectbeing released.

Definition at line 458 of file mapped.h.

Here is the call graph for this function:

◆ removeLocked()

template<class T >
void ucommon::mapped_reuse< T >::removeLocked ( T * object)
inline

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

Parameters
objectbeing returned.

Definition at line 443 of file mapped.h.

Here is the call graph for this function:

◆ request()

template<class T >
T * ucommon::mapped_reuse< T >::request ( void )
inline

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

This method does not block or wait.

Returns
free typed object if available or NULL.

Definition at line 435 of file mapped.h.

Here is the call graph for this function:

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