ucommon
|
Map a reusable allocator over a named shared memory segment. More...
#include <mapped.h>
Public Member Functions | |
bool | avail (void) |
Check whether there are objects available to be allocated. | |
ReusableObject * | get (void) |
Request a reusable object from the free list or mapped space. | |
ReusableObject * | getLocked (void) |
Used to get an object from the reuse pool when the mutex lock is already held. | |
ReusableObject * | getTimed (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. | |
ReusableObject * | request (void) |
Request a reusable object from the free list or mapped space. | |
Protected Member Functions | |
void | create (const char *fname, unsigned count) |
MappedReuse (size_t osize) |
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 | ) |
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.
Reimplemented in ucommon::mapped_reuse< T >.
Used to get an object from the reuse pool when the mutex lock is already held.
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.
timeout | to wait in milliseconds. |
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.
object | being returned. |
ReusableObject* ucommon::MappedReuse::request | ( | void | ) |
Request a reusable object from the free list or mapped space.
Reimplemented in ucommon::mapped_reuse< T >.