#include <OnixS/FIXEngine/Threading/ThreadSafePool.h>
Public Member Functions | |
ThreadSafePool (size_t preferredSize, PoolAllocatorBase &allocator) | |
~ThreadSafePool () | |
void | get (ItemBaseUniquePtr &poolItem) |
void | put (ItemBaseUniquePtr &poolItem) |
size_t | preferredSize () |
The pool is safe for many writers and one reader. The common scenario : a producer of data creates the objects using the pool and sends them to a consumer threads to process, then these threads returns objects back to producer's pool and so on.
Definition at line 33 of file ThreadSafePool.h.
ThreadSafePool | ( | size_t | preferredSize, |
PoolAllocatorBase & | allocator | ||
) |
Initializes the instance.
preferredSize | The preferred size of the pool. |
allocator | The allocator to provide a strategy to create/destroy pool items. |
~ThreadSafePool | ( | ) |
Removes pooled elements and cleans up internal resources.
void get | ( | ItemBaseUniquePtr & | poolItem | ) |
Gets an item from the pool.
Gives the ownership of the item to the smart pointer. If the pool is empty then creates an item by the allocator strategy. If the number of allocated elements becomes greater than the preferred pool size, after a high load, then destroys a one element, when possible, by the allocator strategy.
poolItem | The smart pointer to store the pool item. |
size_t preferredSize | ( | ) |
Returns the preferred size of the pool.
void put | ( | ItemBaseUniquePtr & | poolItem | ) |
Returns an item to the pool.
Takes the ownership of the item from the smart pointer.
The | DomainException if the smart pointer is null. |
poolItem | The smart pointer to the pool item for returning to the pool. |