101 lines
2.5 KiB
C++
101 lines
2.5 KiB
C++
/**
|
|
* @file include/ActivMiddleware/ActivFramework/HeapPool.h
|
|
*
|
|
* @brief Header file for heap pool class.
|
|
*/
|
|
|
|
#if (!defined ACTIV_FRAMEWORK_HEAP_POOL_H)
|
|
#define ACTIV_FRAMEWORK_HEAP_POOL_H
|
|
|
|
#include "ActivMiddleware/ActivFramework/External.h"
|
|
#include "ActivMiddleware/ActivFramework/IHeap.h"
|
|
|
|
#include <vector>
|
|
|
|
//! Activ namespace.
|
|
namespace Activ
|
|
{
|
|
|
|
/**
|
|
* @brief Heap pool.
|
|
*/
|
|
class HeapPool : private Boost::noncopyable
|
|
{
|
|
public:
|
|
/**
|
|
* @brief Constructor.
|
|
*
|
|
* @param pSystem system to create heaps in.
|
|
* @param heapSettings properties of heaps to create.
|
|
* @param initialSize number of heaps to create initially.
|
|
* @param namePrefix prefix to give to heap names.
|
|
*/
|
|
ACTIV_FRAMEWORK_API
|
|
HeapPool(ISystem * const pSystem, const IHeap::Settings &heapSettings, const size_t initialSize,
|
|
const String &namePrefix);
|
|
|
|
/**
|
|
* @brief Get a message from the pool of free heaps.
|
|
*
|
|
* @param pData
|
|
* @param dataLength
|
|
* @param heapMessage to receive the allocated message.
|
|
*/
|
|
ACTIV_FRAMEWORK_API
|
|
void GetMessage(const void * const pData, const size_t dataLength, HeapMessage &heapMessage);
|
|
|
|
/**
|
|
* @brief Get a heap from the pool.
|
|
*
|
|
* If no heaps are in the pool, a new heap is created.
|
|
*
|
|
* @return Pointer to a heap, or 0 if failed to create a heap.
|
|
*/
|
|
ACTIV_FRAMEWORK_API
|
|
IHeap *Get();
|
|
|
|
/**
|
|
* @brief Return a heap to the pool.
|
|
*
|
|
* @param pHeap the heap to return.
|
|
*
|
|
* @return true if the heap was returned to the pool, or false if the heap wasn't created by this pool (and therefore
|
|
* has not been returned to it).
|
|
*/
|
|
ACTIV_FRAMEWORK_API
|
|
bool Return(IHeap * const pHeap);
|
|
|
|
/**
|
|
* @brief Extend the number of heaps in the pool.
|
|
*
|
|
* @param numberOfHeaps number of heaps to create.
|
|
*
|
|
* @return Number of heaps actually created.
|
|
*/
|
|
ACTIV_FRAMEWORK_API
|
|
size_t Extend(const size_t numberOfHeaps);
|
|
|
|
private:
|
|
/**
|
|
* @brief Create an individual heap.
|
|
*
|
|
* @return pHeap the heap, or 0 on error.
|
|
*/
|
|
IHeap *CreateHeap();
|
|
|
|
typedef std::set<IHeap *> HeapSet;
|
|
typedef std::vector<IHeap *> HeapList;
|
|
|
|
ISystem * const m_pSystem; ///< System to create heaps in.
|
|
const IHeap::Settings m_heapSettings; ///< Properties of heaps to create.
|
|
const String m_namePrefix; ///< Prefix to give to heap names.
|
|
|
|
size_t m_nextHeapNumber; ///< Increasing count to make unique heap names.
|
|
HeapSet m_heapSet; ///< Set of all heaps created by this object.
|
|
HeapList m_freeHeapList; ///< Free heaps in the pool.
|
|
};
|
|
|
|
} // namespace Activ
|
|
|
|
#endif // (!defined ACTIV_FRAMEWORK_HEAP_POOL_H)
|