#include <shm_allocator.h>
Collaboration diagram for shm_allocator:
Public Member Functions | |
shm_allocator (shm_segment &s) | |
shm_allocator_block * | split_block (shm_allocator_block *b, size_t s) |
shm_allocator_block * | insert_block (shm_allocator_block *b) |
shm_allocator_block * | remove_block (shm_allocator_block *b) |
void * | alloc (size_t nbytes) |
void | free (void *addr) |
const shm_segment & | get_segment () const |
size_t | get_overhead () |
Private Member Functions | |
void | init () |
void | init_allocator_header () |
void | init_allocator_header_lock (shm_allocator_header *head) |
Private Attributes | |
shm_segment & | seg |
shm_allocator_header * | header |
Classes | |
struct | shm_allocator_block |
shared memory allocation block More... | |
struct | shm_allocator_header |
shared memory allocator header structure More... |
The shared allocator uses a sorted circular doubly linked list for the free block list and tries to merge contiguous blocks on free. Currently the allocator initializes the shm_allocator_header in the constructor.
Note : use the following to provide new and delete to work with shm_allocator *
void* operator new(size_t s, shm_allocator& a)
{
return a.alloc(s);
}
void operator delete(void* p, shm_allocator& a)
{
a.free(p);
}
Definition at line 44 of file shm_allocator.h.
shm_allocator::shm_allocator | ( | shm_segment & | s | ) | [inline] |
construct a shared memory allocator with a shm_segment.
The allocator will use the entire segment for allocation. The allocator header structure will be at offset zero. Access to the segment is protected using a process shared POSIX mutex.
s | shared memory segment as source for memory allocation. |
Definition at line 148 of file shm_allocator.h.
References init().
Here is the call graph for this function:
void shm_allocator::init | ( | ) | [inline, private] |
initialize the shared memory allocator
The initialization does a simple check for the shared memory segment having already been initialized. This consists of a check of the memory at the base of the shared segment for the shared memory key. If there is a situation where this check fails, the initialization of the shared memory segment to all zero's may be required.
Definition at line 92 of file shm_allocator.h.
References shm_segment::get_base(), shm_segment::get_key(), header, init_allocator_header(), shm_allocator::shm_allocator_header::key, and seg.
Referenced by shm_allocator().
Here is the call graph for this function:
void shm_allocator::init_allocator_header | ( | ) | [inline, private] |
initialize allocator header structure
The initialization creates the first allocator block with a size of the shared memory segement minus the size of the header information. The allocator header mutex lock initialization method is also invoked.
Definition at line 108 of file shm_allocator.h.
References shm_allocator::shm_allocator_header::freelist, shm_segment::get_base(), shm_segment::get_key(), shm_segment::get_size(), header, init_allocator_header_lock(), shm_allocator::shm_allocator_header::key, shm_allocator::shm_allocator_block::next, overhead, shm_allocator::shm_allocator_block::prev, seg, and shm_allocator::shm_allocator_block::size.
Referenced by init().
Here is the call graph for this function:
void shm_allocator::init_allocator_header_lock | ( | shm_allocator_header * | head | ) | [inline, private] |
initialize allocator header mutex lock with all process scope
head | allocator header block containing lock to be initialized |
Definition at line 125 of file shm_allocator.h.
References shm_allocator::shm_allocator_header::lock.
Referenced by init_allocator_header().
shm_allocator::shm_allocator_block * shm_allocator::split_block | ( | shm_allocator::shm_allocator_block * | b, | |
size_t | s | |||
) |
split an allocator block into two blocks given a request size.
b | pointer to the current block to split | |
s | request size already rounded up for alignment |
Definition at line 289 of file shm_allocator.h.
References shm_allocator::shm_allocator_block::next, shm_allocator::shm_allocator_block::prev, and shm_allocator::shm_allocator_block::size.
Referenced by alloc().
shm_allocator::shm_allocator_block * shm_allocator::insert_block | ( | shm_allocator::shm_allocator_block * | b | ) |
insert an allocator block to the free list
b | pointer to the block to insert |
Definition at line 250 of file shm_allocator.h.
References block_size, get_freelist, next_block, prev_block, set_freelist, set_next_block, and set_prev_block.
shm_allocator::shm_allocator_block * shm_allocator::remove_block | ( | shm_allocator::shm_allocator_block * | b | ) |
remove an allocator block from the free list
Get the first block from the freelist. If the block to remove is the first block, fix up the freelist reference.
b | pointer to the current block to remove |
Definition at line 228 of file shm_allocator.h.
References shm_segment::get_base(), get_freelist, next_block, prev_block, seg, set_freelist, set_next_block, and set_prev_block.
Referenced by alloc().
Here is the call graph for this function:
void * shm_allocator::alloc | ( | size_t | bytes | ) |
allocate a block of memory
The allocation of a block of memory, that is appropriate given the requested size, scans the free list of memory blocks picking the first block that is large enough to service the request, removing it from the free list. If the free block to be used is larger than required, the block is split with the remainder being placed back into the free list.
Definition at line 176 of file shm_allocator.h.
References shm_ptr< T >::get(), get_freelist, header, insert_block(), shm_allocator::shm_allocator_header::lock, shm_allocator::shm_allocator_block::next, next_block, shm_allocator::shm_allocator_block::prev, remove_block(), seg, shm_allocator::shm_allocator_block::size, and split_block().
Referenced by main(), shm_queue< T >::operator new(), shm_queue_header< T >::operator new(), shm_queue_node< T >::operator new(), shm_message::operator new(), and shm_message::setText().
Here is the call graph for this function:
void shm_allocator::free | ( | void * | addr | ) |
Definition at line 210 of file shm_allocator.h.
References header, insert_block(), and shm_allocator::shm_allocator_header::lock.
Referenced by shm_queue< T >::operator delete(), shm_queue_header< T >::operator delete(), shm_queue_node< T >::operator delete(), and shm_message::operator delete().
Here is the call graph for this function:
const shm_segment& shm_allocator::get_segment | ( | ) | const [inline] |
size_t shm_allocator::get_overhead | ( | ) | [inline] |
Definition at line 159 of file shm_allocator.h.
Referenced by shm_queue< T >::pop(), shm_queue< T >::push(), and shm_queue< T >::shm_queue().
shm_segment& shm_allocator::seg [private] |
Definition at line 134 of file shm_allocator.h.
Referenced by alloc(), get_segment(), init(), init_allocator_header(), and remove_block().
shm_allocator_header* shm_allocator::header [private] |
Definition at line 135 of file shm_allocator.h.
Referenced by alloc(), free(), init(), and init_allocator_header().
Project shmq hosted by | Documentation generated on Sat Sep 2 10:07:40 2006 for shmq by 1.4.6 |