Local Pool Bugfix #8
@ -39,7 +39,67 @@ public:
|
|||||||
* @brief This definition generally sets the number of different sized pools.
|
* @brief This definition generally sets the number of different sized pools.
|
||||||
* @details This must be less than the maximum number of pools (currently 0xff).
|
* @details This must be less than the maximum number of pools (currently 0xff).
|
||||||
*/
|
*/
|
||||||
// static const uint32_t NUMBER_OF_POOLS;
|
// static const uint32_t NUMBER_OF_POOLS;
|
||||||
|
/**
|
||||||
|
* @brief This is the default constructor for a pool manager instance.
|
||||||
|
* @details By passing two arrays of size NUMBER_OF_POOLS, the constructor
|
||||||
|
* allocates memory (with \c new) for store and size_list. These
|
||||||
|
* regions are all set to zero on start up.
|
||||||
|
* @param setObjectId The object identifier to be set. This allows for
|
||||||
|
* multiple instances of LocalPool in the system.
|
||||||
|
* @param element_sizes An array of size NUMBER_OF_POOLS in which the size
|
||||||
|
* of a single element in each pool is determined.
|
||||||
|
* <b>The sizes must be provided in ascending order.
|
||||||
|
* </b>
|
||||||
|
* @param n_elements An array of size NUMBER_OF_POOLS in which the
|
||||||
|
* number of elements for each pool is determined.
|
||||||
|
* The position of these values correspond to those in
|
||||||
|
* element_sizes.
|
||||||
|
* @param registered Register the pool in object manager or not. Default is false (local pool).
|
||||||
|
*/
|
||||||
|
LocalPool(object_id_t setObjectId,
|
||||||
|
const uint16_t element_sizes[NUMBER_OF_POOLS],
|
||||||
|
const uint16_t n_elements[NUMBER_OF_POOLS],
|
||||||
|
bool registered = false,
|
||||||
|
bool spillsToHigherPools = false);
|
||||||
|
/**
|
||||||
|
* @brief In the LocalPool's destructor all allocated memory is freed.
|
||||||
|
*/
|
||||||
|
virtual ~LocalPool(void);
|
||||||
|
ReturnValue_t addData(store_address_t* storageId, const uint8_t * data,
|
||||||
|
uint32_t size, bool ignoreFault = false);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* With this helper method, a free element of \c size is reserved.
|
||||||
|
*
|
||||||
|
* @param size The minimum packet size that shall be reserved.
|
||||||
|
* @return Returns the storage identifier within the storage or
|
||||||
|
* StorageManagerIF::INVALID_ADDRESS (in raw).
|
||||||
|
*/
|
||||||
|
ReturnValue_t getFreeElement(store_address_t* storageId,
|
||||||
|
const uint32_t size, uint8_t** p_data, bool ignoreFault = false);
|
||||||
|
ReturnValue_t getData(store_address_t packet_id, const uint8_t** packet_ptr,
|
||||||
|
uint32_t* size);
|
||||||
|
ReturnValue_t modifyData(store_address_t packet_id, uint8_t** packet_ptr,
|
||||||
|
uint32_t* size);
|
||||||
|
virtual ReturnValue_t deleteData(store_address_t);
|
||||||
|
virtual ReturnValue_t deleteData(uint8_t* ptr, uint32_t size,
|
||||||
|
store_address_t* storeId = NULL);
|
||||||
|
void clearStore();
|
||||||
|
ReturnValue_t initialize();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
/**
|
||||||
|
* With this helper method, a free element of \c size is reserved.
|
||||||
|
* @param size The minimum packet size that shall be reserved.
|
||||||
|
* @param[out] address Storage ID of the reserved data.
|
||||||
|
* @return - #RETURN_OK on success,
|
||||||
|
* - the return codes of #getPoolIndex or #findEmpty otherwise.
|
||||||
|
*/
|
||||||
|
virtual ReturnValue_t reserveSpace(const uint32_t size, store_address_t* address, bool ignoreFault);
|
||||||
|
|
||||||
|
InternalErrorReporterIF *internalErrorReporter;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
* Indicates that this element is free.
|
* Indicates that this element is free.
|
||||||
@ -69,7 +129,8 @@ private:
|
|||||||
* is also dynamically allocated there.
|
* is also dynamically allocated there.
|
||||||
*/
|
*/
|
||||||
uint32_t* size_list[NUMBER_OF_POOLS];
|
uint32_t* size_list[NUMBER_OF_POOLS];
|
||||||
bool spillsToHigherPools; //!< A variable to determine whether higher n pools are used if the store is full.
|
//!< A variable to determine whether higher n pools are used if the store is full.
|
||||||
|
bool spillsToHigherPools;
|
||||||
/**
|
/**
|
||||||
* @brief This method safely stores the given data in the given packet_id.
|
* @brief This method safely stores the given data in the given packet_id.
|
||||||
* @details It also sets the size in size_list. The method does not perform
|
* @details It also sets the size in size_list. The method does not perform
|
||||||
@ -121,67 +182,27 @@ private:
|
|||||||
* - #DATA_STORAGE_FULL if the store is full
|
* - #DATA_STORAGE_FULL if the store is full
|
||||||
*/
|
*/
|
||||||
ReturnValue_t findEmpty(uint16_t pool_index, uint16_t* element);
|
ReturnValue_t findEmpty(uint16_t pool_index, uint16_t* element);
|
||||||
protected:
|
|
||||||
/**
|
|
||||||
* With this helper method, a free element of \c size is reserved.
|
|
||||||
* @param size The minimum packet size that shall be reserved.
|
|
||||||
* @param[out] address Storage ID of the reserved data.
|
|
||||||
* @return - #RETURN_OK on success,
|
|
||||||
* - the return codes of #getPoolIndex or #findEmpty otherwise.
|
|
||||||
*/
|
|
||||||
virtual ReturnValue_t reserveSpace(const uint32_t size, store_address_t* address, bool ignoreFault);
|
|
||||||
|
|
||||||
InternalErrorReporterIF *internalErrorReporter;
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* @brief This is the default constructor for a pool manager instance.
|
|
||||||
* @details By passing two arrays of size NUMBER_OF_POOLS, the constructor
|
|
||||||
* allocates memory (with \c new) for store and size_list. These
|
|
||||||
* regions are all set to zero on start up.
|
|
||||||
* @param setObjectId The object identifier to be set. This allows for
|
|
||||||
* multiple instances of LocalPool in the system.
|
|
||||||
* @param element_sizes An array of size NUMBER_OF_POOLS in which the size
|
|
||||||
* of a single element in each pool is determined.
|
|
||||||
* <b>The sizes must be provided in ascending order.
|
|
||||||
* </b>
|
|
||||||
* @param n_elements An array of size NUMBER_OF_POOLS in which the
|
|
||||||
* number of elements for each pool is determined.
|
|
||||||
* The position of these values correspond to those in
|
|
||||||
* element_sizes.
|
|
||||||
* @param registered Register the pool in object manager or not. Default is false (local pool).
|
|
||||||
*/
|
|
||||||
LocalPool(object_id_t setObjectId,
|
|
||||||
const uint16_t element_sizes[NUMBER_OF_POOLS],
|
|
||||||
const uint16_t n_elements[NUMBER_OF_POOLS],
|
|
||||||
bool registered = false,
|
|
||||||
bool spillsToHigherPools = false);
|
|
||||||
/**
|
|
||||||
* @brief In the LocalPool's destructor all allocated memory is freed.
|
|
||||||
*/
|
|
||||||
virtual ~LocalPool(void);
|
|
||||||
ReturnValue_t addData(store_address_t* storageId, const uint8_t * data,
|
|
||||||
uint32_t size, bool ignoreFault = false);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* With this helper method, a free element of \c size is reserved.
|
|
||||||
*
|
|
||||||
* @param size The minimum packet size that shall be reserved.
|
|
||||||
* @return Returns the storage identifier within the storage or
|
|
||||||
* StorageManagerIF::INVALID_ADDRESS (in raw).
|
|
||||||
*/
|
|
||||||
ReturnValue_t getFreeElement(store_address_t* storageId,
|
|
||||||
const uint32_t size, uint8_t** p_data, bool ignoreFault = false);
|
|
||||||
ReturnValue_t getData(store_address_t packet_id, const uint8_t** packet_ptr,
|
|
||||||
uint32_t* size);
|
|
||||||
ReturnValue_t modifyData(store_address_t packet_id, uint8_t** packet_ptr,
|
|
||||||
uint32_t* size);
|
|
||||||
virtual ReturnValue_t deleteData(store_address_t);
|
|
||||||
virtual ReturnValue_t deleteData(uint8_t* ptr, uint32_t size,
|
|
||||||
store_address_t* storeId = NULL);
|
|
||||||
void clearStore();
|
|
||||||
ReturnValue_t initialize();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
template<uint8_t NUMBER_OF_POOLS>
|
||||||
|
inline LocalPool<NUMBER_OF_POOLS>::LocalPool(object_id_t setObjectId,
|
||||||
|
const uint16_t element_sizes[NUMBER_OF_POOLS],
|
||||||
|
const uint16_t n_elements[NUMBER_OF_POOLS], bool registered,
|
||||||
|
bool spillsToHigherPools) :
|
||||||
|
SystemObject(setObjectId, registered), internalErrorReporter(nullptr),
|
||||||
|
spillsToHigherPools(spillsToHigherPools) {
|
||||||
|
for (uint16_t n = 0; n < NUMBER_OF_POOLS; n++) {
|
||||||
|
this->element_sizes[n] = element_sizes[n];
|
||||||
|
this->n_elements[n] = n_elements[n];
|
||||||
|
store[n] = new uint8_t[n_elements[n] * element_sizes[n]];
|
||||||
|
size_list[n] = new uint32_t[n_elements[n]];
|
||||||
|
memset(store[n], 0x00, (n_elements[n] * element_sizes[n]));
|
||||||
|
//TODO checkme
|
||||||
|
memset(size_list[n], STORAGE_FREE, (n_elements[n] * sizeof(**size_list)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
template<uint8_t NUMBER_OF_POOLS>
|
template<uint8_t NUMBER_OF_POOLS>
|
||||||
inline ReturnValue_t LocalPool<NUMBER_OF_POOLS>::findEmpty(uint16_t pool_index,
|
inline ReturnValue_t LocalPool<NUMBER_OF_POOLS>::findEmpty(uint16_t pool_index,
|
||||||
uint16_t* element) {
|
uint16_t* element) {
|
||||||
@ -263,7 +284,7 @@ inline ReturnValue_t LocalPool<NUMBER_OF_POOLS>::reserveSpace(
|
|||||||
|
|
||||||
size_list[address->pool_index][address->packet_index] = size;
|
size_list[address->pool_index][address->packet_index] = size;
|
||||||
} else {
|
} else {
|
||||||
if (!ignoreFault) {
|
if (!ignoreFault and internalErrorReporter != nullptr) {
|
||||||
internalErrorReporter->storeFull();
|
internalErrorReporter->storeFull();
|
||||||
}
|
}
|
||||||
// error << "LocalPool( " << std::hex << getObjectId() << std::dec
|
// error << "LocalPool( " << std::hex << getObjectId() << std::dec
|
||||||
@ -272,21 +293,6 @@ inline ReturnValue_t LocalPool<NUMBER_OF_POOLS>::reserveSpace(
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<uint8_t NUMBER_OF_POOLS>
|
|
||||||
inline LocalPool<NUMBER_OF_POOLS>::LocalPool(object_id_t setObjectId,
|
|
||||||
const uint16_t element_sizes[NUMBER_OF_POOLS],
|
|
||||||
const uint16_t n_elements[NUMBER_OF_POOLS], bool registered, bool spillsToHigherPools) :
|
|
||||||
SystemObject(setObjectId, registered), spillsToHigherPools(spillsToHigherPools), internalErrorReporter(NULL) {
|
|
||||||
for (uint16_t n = 0; n < NUMBER_OF_POOLS; n++) {
|
|
||||||
this->element_sizes[n] = element_sizes[n];
|
|
||||||
this->n_elements[n] = n_elements[n];
|
|
||||||
store[n] = new uint8_t[n_elements[n] * element_sizes[n]];
|
|
||||||
size_list[n] = new uint32_t[n_elements[n]];
|
|
||||||
memset(store[n], 0x00, (n_elements[n] * element_sizes[n]));
|
|
||||||
memset(size_list[n], STORAGE_FREE, (n_elements[n] * sizeof(**size_list))); //TODO checkme
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template<uint8_t NUMBER_OF_POOLS>
|
template<uint8_t NUMBER_OF_POOLS>
|
||||||
inline LocalPool<NUMBER_OF_POOLS>::~LocalPool(void) {
|
inline LocalPool<NUMBER_OF_POOLS>::~LocalPool(void) {
|
||||||
for (uint16_t n = 0; n < NUMBER_OF_POOLS; n++) {
|
for (uint16_t n = 0; n < NUMBER_OF_POOLS; n++) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user