89 lines
3.3 KiB
C++
89 lines
3.3 KiB
C++
#ifndef POOLMANAGER_TPP_
|
|
#define POOLMANAGER_TPP_
|
|
|
|
template<uint8_t NUMBER_OF_POOLS>
|
|
inline PoolManager<NUMBER_OF_POOLS>::PoolManager(object_id_t setObjectId,
|
|
const uint16_t element_sizes[NUMBER_OF_POOLS],
|
|
const uint16_t n_elements[NUMBER_OF_POOLS]) :
|
|
LocalPool<NUMBER_OF_POOLS>(setObjectId, element_sizes, n_elements, true) {
|
|
mutex = MutexFactory::instance()->createMutex();
|
|
}
|
|
|
|
template<uint8_t NUMBER_OF_POOLS>
|
|
inline PoolManager<NUMBER_OF_POOLS>::~PoolManager(void) {
|
|
MutexFactory::instance()->deleteMutex(mutex);
|
|
}
|
|
|
|
template<uint8_t NUMBER_OF_POOLS>
|
|
inline ReturnValue_t PoolManager<NUMBER_OF_POOLS>::reserveSpace(
|
|
const uint32_t size, store_address_t* address, bool ignoreFault) {
|
|
MutexHelper mutexHelper(mutex,MutexIF::NO_TIMEOUT);
|
|
ReturnValue_t status = LocalPool<NUMBER_OF_POOLS>::reserveSpace(size,
|
|
address,ignoreFault);
|
|
return status;
|
|
}
|
|
|
|
template<uint8_t NUMBER_OF_POOLS>
|
|
inline ReturnValue_t PoolManager<NUMBER_OF_POOLS>::deleteData(
|
|
store_address_t packet_id) {
|
|
// debug << "PoolManager( " << translateObject(getObjectId()) <<
|
|
// " )::deleteData from store " << packet_id.pool_index <<
|
|
// ". id is "<< packet_id.packet_i#include <test/prototypes/StoreAccessWrapper.h>ndex << std::endl;
|
|
MutexHelper mutexHelper(mutex,MutexIF::NO_TIMEOUT);
|
|
ReturnValue_t status = LocalPool<NUMBER_OF_POOLS>::deleteData(packet_id);
|
|
return status;
|
|
}
|
|
|
|
template<uint8_t NUMBER_OF_POOLS>
|
|
inline ReturnValue_t PoolManager<NUMBER_OF_POOLS>::deleteData(uint8_t* buffer,
|
|
size_t size, store_address_t* storeId) {
|
|
MutexHelper mutexHelper(mutex,MutexIF::NO_TIMEOUT);
|
|
ReturnValue_t status = LocalPool<NUMBER_OF_POOLS>::deleteData(buffer,
|
|
size, storeId);
|
|
return status;
|
|
}
|
|
|
|
template<uint8_t NUMBER_OF_POOLS>
|
|
inline AccessorPair PoolManager<NUMBER_OF_POOLS>::modifyData(
|
|
store_address_t storeId) {
|
|
StorageAccessor storeAccessor(storeId);
|
|
ReturnValue_t result = storeAccessor.lock(mutex);
|
|
if(result != HasReturnvaluesIF::RETURN_OK) {
|
|
sif::error << "PoolManager: Error locking mutex with code 0x"
|
|
<< std::hex << result << std::dec <<std::endl;
|
|
// Unfortunately, I can not return nullptr for second argument
|
|
// but maybe it's better like that.
|
|
return AccessorPair(result, std::move(storeAccessor));
|
|
}
|
|
storeAccessor.assignStore(this);
|
|
result = LocalPool<NUMBER_OF_POOLS>::modifyData(
|
|
storeAccessor.storeId, &storeAccessor.dataPointer,
|
|
&storeAccessor.size_);
|
|
storeAccessor.assignConstPointer();
|
|
storeAccessor.print();
|
|
// Using move semantics to transfer the store accessor to the caller
|
|
return AccessorPair(result, std::move(storeAccessor));
|
|
}
|
|
|
|
template<uint8_t NUMBER_OF_POOLS>
|
|
inline ConstAccessorPair PoolManager<NUMBER_OF_POOLS>::getData(
|
|
store_address_t storeId) {
|
|
ConstStorageAccessor storeAccessor(storeId);
|
|
ReturnValue_t result = storeAccessor.lock(mutex);
|
|
if(result != HasReturnvaluesIF::RETURN_OK) {
|
|
sif::error << "PoolManager: Error locking mutex with code 0x"
|
|
<< std::hex << result << std::dec <<std::endl;
|
|
return ConstAccessorPair(result, std::move(storeAccessor));
|
|
}
|
|
storeAccessor.assignStore(this);
|
|
result = LocalPool<NUMBER_OF_POOLS>::getData(
|
|
storeAccessor.storeId, &storeAccessor.constDataPointer,
|
|
&storeAccessor.size_);
|
|
storeAccessor.print();
|
|
// Using move semantics to transfer the store accessor to the caller
|
|
return ConstAccessorPair(result, std::move(storeAccessor));
|
|
}
|
|
|
|
#endif
|
|
|