34#ifndef _UTILS_BUFFER_HXX_
35#define _UTILS_BUFFER_HXX_
60template <
class T>
class Buffer;
291 template <
class BufferType>
294#ifdef DEBUG_BUFFER_MEMORY
300 if (*result && !flow)
322 alloc(&buffer, flow);
330 template <
class BufferType>
417 int next = va_arg(ap,
int);
428 for (
int i = 1; i <
count; ++i)
430 new (now)
Bucket(va_arg(aq,
int));
603 for (
size_t i = 0; i <
items; ++i)
607 current = (
QMember *)((
char *)current + item_size);
677 if (count_.fetch_sub(1) == 1u)
BufferPtr< T > get_buffer_deleter(Buffer< T > *b)
Helper function to create a BufferPtr of an appropriate type without having to explicitly specify the...
AutoReleaseBuffer< T > BufferPtr
Smart pointer for buffers.
std::unique_ptr< Buffer< T >, BufferDelete< T > > AutoReleaseBuffer
This class will automatically unref a Buffer when going out of scope.
void * g_current_alloc
This pointer will be saved for debugging the current allocation source.
Pool * init_main_buffer_pool()
Initializes the main buffer pool.
const unsigned LARGEST_BUFFERPOOL_BUCKET
Ensures that the largest bucket in the main buffer pool is exactly the size of a GenMessage.
DynamicPool * mainBufferPool
main buffer pool instance
Lightweight locking class for protecting small critical sections.
A BarrierNotifiable allows to create a number of child Notifiable and wait for all of them to finish.
void notify() override
Implementation of the barrier semantics.
BarrierNotifiable * new_child()
Call this for each child task.
This is a struct for storing info about a specific size item in the DynamicPool.
QMember * executables()
Pull out any pending Executables.
size_t size()
Get the size of the bucket.
static void destroy(Bucket *bucket)
destroy a bucket created with init.
Q pending_
list of anyone waiting for an item in the bucket
size_t size_
size of entry
Bucket(size_t size)
Constructor.
static Bucket * init(int s,...)
Allocate a Bucket array off of the heap initialized with sizes.
size_t allocCount_
total entries allocated
Abstract base class for all Buffers.
Pool * pool_
Reference to the pool from whence this buffer came.
uint16_t size_
size of data in bytes
BufferBase(size_t size, Pool *pool)
Constructor.
std::atomic_uint_least16_t count_
number of references in use
Pool * pool()
Get a pointer to the pool that this buffer belongs to.
BarrierNotifiable * new_child()
Creates a new child notifiable of the current done notifiable.
void set_done(BarrierNotifiable *done)
Specifies that a given BarrierNotifiable must be called when the Buffer is deallocated (unreffed to z...
BarrierNotifiable * done_
Notifiable to call when the buffer has finished processing everywhere.
Base class for all QMember types that hold data in an expandable format.
Buffer(Pool *pool)
Constructor.
Buffer< T > * ref()
Add another reference to the buffer.
void unref()
Decrement count.
T value_type
The type of payload this buffer contains.
T * data()
get a pointer to the start of the data.
Proxy Pool that can allocate DataBuffer objects of a certain size.
Specialization of the Buffer class that is designed for storing untyped data arrays.
A specialization of a pool which can allocate new elements dynamically upon request.
DynamicPool()
Default constructor.
void free(BufferBase *item) override
Releases an item back to the free pool.
size_t free_items() override
Number of free items in the pool.
~DynamicPool()
default destructor
DynamicPool(Bucket sizes[])
Constructor.
BufferBase * alloc_untyped(size_t size, Executable *flow) override
Get a free item out of the pool.
void * alloc_large(size_t size)
Allocates a large memory block directly from the heap.
Bucket * buckets
Free buffer queue.
void free_large(void *block)
Frees a large memory block allocated by alloc_large.
An object that can be scheduled on an executor to run.
Pool of fixed number of items which can be allocated up on request.
FixedPool()
Default Constructor.
void free(BufferBase *item) override
Release an item back to the free pool.
bool valid(QMember *item)
Used in static pools to tell if this item is a member of the pool.
~FixedPool()
default destructor
FixedPool(size_t item_size, size_t items)
Constructor for a fixed size pool.
size_t free_items() override
Number of free items in the pool.
BufferBase * alloc_untyped(size_t size, Executable *flow) override
Get a free item out of the pool.
size_t items
total number of items in the queue
size_t itemSize
item Size for fixed pools
bool empty
is the pool empty
size_t free_items(size_t size) override
Number of free items in the pool for a given allocation size.
char * mempool
First buffer in a pre-allocated array pool.
Q queue
Free buffer queue.
An arena allocator, which is optimized to not be able to free individual entries, only the entire all...
Implementation of a Pool interface that takes memory from mainBufferPool (configurable) but limits th...
Pool of previously allocated, but currently unused, items.
static void alloc_async_init(BufferBase *base, Buffer< BufferType > **result)
Cast the result of an asynchronous allocation and perform a placement new on it.
virtual void free(BufferBase *item)=0
Release an item back to the free pool.
Pool()
Default Constructor.
void alloc(BufferPtr< BufferType > *result)
Get a free item out of the pool.
virtual BufferBase * alloc_untyped(size_t size, Executable *flow)=0
Untyped buffer allocation method, used be descendants.
virtual size_t free_items()=0
Number of free items in the pool.
size_t totalSize
keep track of total allocated size of memory
void alloc(Buffer< BufferType > **result, Executable *flow=NULL)
Get a free item out of the pool.
virtual ~Pool()
default destructor.
void alloc_async(Executable *flow)
Get a free item out of the pool.
virtual size_t free_items(size_t size)=0
Number of free items in the pool for a given allocation size.
Essentially a "next" pointer container.
void init()
Initiailize a QMember, in place of a public placement construction.
This class implements a linked list "queue" of buffers.
void insert(QMember *item, unsigned index=0)
Add an item to the back of the queue.
Result next()
Get an item from the front of the queue.
QMember * next(unsigned index)
Get an item from the front of the queue.
size_t count
number of items in queue
Test fixture base class with helper methods for exercising the asynchronous interface code.
#define HASSERT(x)
Checks that the value of expression x is true, else terminates the current process.
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Removes default copy-constructor and assignment added by C++.
Helper class for correctly deleting a buffer.
void operator()(Buffer< T > *b)
unrefs the passed-in buffer.