UCommon
|
Map a reusable allocator over a named shared memory segment. More...
#include <mapped.h>
Public Member Functions | |
bool | avail (void) const |
Check whether there are objects available to be allocated. More... | |
ReusableObject * | get (void) |
Request a reusable object from the free list or mapped space. More... | |
ReusableObject * | getLocked (void) |
Used to get an object from the reuse pool when the mutex lock is already held. More... | |
ReusableObject * | getTimed (timeout_t timeout) |
Request a reusable object from the free list or mapped space. More... | |
MappedReuse (const char *name, size_t size, unsigned count) | |
Construct a named memory segment for use with managed fixed size reusable objects. More... | |
void | removeLocked (ReusableObject *object) |
Used to return an object to the reuse pool when the mutex lock is already held. More... | |
ReusableObject * | request (void) |
Request a reusable object from the free list or mapped space. More... | |
Protected Member Functions | |
void | create (const char *fname, unsigned count) |
MappedReuse (size_t osize) | |
![]() | |
ReusableObject * | next (ReusableObject *object) |
Get next reusable object in the pool. More... | |
void | release (ReusableObject *object) |
Release resuable object. More... | |
ReusableAllocator () | |
Initialize reusable allocator through a conditional. More... | |
![]() | |
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 (timeout_t timeout) |
Conditional wait for signal on millisecond timeout. More... | |
bool | wait (struct timespec *timeout) |
Conditional wait for signal on timespec timeout. More... | |
void | wait (void) |
Wait (block) until signalled. | |
~Conditional () | |
Destroy conditional, release any blocked threads. | |
![]() | |
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. | |
![]() | |
void | create (const char *name, size_t size=(size_t) 0) |
Supporting function to construct a new or access an existing shared memory segment. More... | |
caddr_t | addr (void) |
Get starting address of mapped segment. More... | |
bool | copy (size_t offset, void *buffer, size_t size) const |
Copy memory from specific offset within the mapped memory segment. More... | |
size_t | len (void) const |
Get size of mapped segment. More... | |
MappedMemory (const char *name, size_t size) | |
Construct a read/write access mapped shared segment of memory of a known size. More... | |
MappedMemory (const char *name) | |
Provide read-only mapped access to an existing named shared memory segment. More... | |
void * | offset (size_t offset) const |
Get memory from a specific offset within the mapped memory segment. More... | |
operator bool () const | |
Test if map active. More... | |
bool | operator! () const |
Test if map is inactive. More... | |
void | release (void) |
Unmap memory segment. | |
void * | sbrk (size_t size) |
Extend size of managed heap on shared memory segment. More... | |
virtual | ~MappedMemory () |
Unmap memory segment. | |
Additional Inherited Members | |
![]() | |
static pthread_condattr_t * | initializer (void) |
Support function for getting conditional attributes for realtime scheduling. More... | |
static void | set (struct timespec *hires, timeout_t timeout) |
Convert a millisecond timeout into use for high resolution conditional timers. More... | |
![]() | |
static void | disable (void) |
An API that allows "disabling" of publishing shared memory maps. More... | |
static void | remove (const char *name) |
Destroy a previously existing memory segment under the specified name. More... | |
![]() | |
ReusableObject * | freelist |
unsigned | waiting |
![]() | |
pthread_cond_t | cond |
![]() | |
pthread_mutex_t | mutex |
![]() | |
bool | erase |
char | idname [65] |
size_t | size |
size_t | used |
![]() | |
static attribute | attr |
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.
ucommon::MappedReuse::MappedReuse | ( | const 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.
name | of shared memory segment. |
size | of the object type being mapped. |
count | of the maximum number of active mapped objects. |
bool ucommon::MappedReuse::avail | ( | void | ) | const |
Check whether there are objects available to be allocated.
ReusableObject* ucommon::MappedReuse::get | ( | void | ) |
Request a reusable object from the free list or mapped space.
This method blocks until an object becomes available.
ReusableObject* ucommon::MappedReuse::getLocked | ( | void | ) |
Used to get an object from the reuse pool when the mutex lock is already held.
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.
timeout | to wait in milliseconds. |
void ucommon::MappedReuse::removeLocked | ( | ReusableObject * | object | ) |
Used to return an object to the reuse pool when the mutex lock is already held.
object | being returned. |
ReusableObject* ucommon::MappedReuse::request | ( | void | ) |
Request a reusable object from the free list or mapped space.