removed locks in lockless functions

This commit is contained in:
Robin Müller 2020-06-07 15:22:32 +02:00
parent 73932f0349
commit 98e6ca5f78
3 changed files with 17 additions and 11 deletions

View File

@ -87,8 +87,6 @@ inline ReturnValue_t LocalPoolVar<T>::commitWithoutLock() {
"mode for commit() call." << std::endl; "mode for commit() call." << std::endl;
return PoolVariableIF::INVALID_READ_WRITE_MODE; return PoolVariableIF::INVALID_READ_WRITE_MODE;
} }
// Wait maximum of 50 milliseconds.
MutexHelper(hkManager->getMutexHandle(), 50);
PoolEntry<T>* poolEntry = nullptr; PoolEntry<T>* poolEntry = nullptr;
ReturnValue_t result = hkManager->fetchPoolEntry(localPoolId, &poolEntry); ReturnValue_t result = hkManager->fetchPoolEntry(localPoolId, &poolEntry);
if(result != RETURN_OK) { if(result != RETURN_OK) {

View File

@ -70,8 +70,9 @@ public:
/** /**
* @brief This is the local copy of the data pool entry. * @brief This is the local copy of the data pool entry.
* @details The user can work on this attribute * @details
* just like he would on a local array of this type. * The user can work on this attribute just like he would on a local
* array of this type.
*/ */
T value[vectorSize]; T value[vectorSize];
/** /**
@ -109,7 +110,7 @@ public:
void setValid(bool valid) override; void setValid(bool valid) override;
uint8_t getValid() const; uint8_t getValid() const;
T &operator [](int i); T& operator [](int i);
const T &operator [](int i) const; const T &operator [](int i) const;
virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size, virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size,
@ -142,6 +143,7 @@ public:
* at once to avoid the overhead of unnecessary lock und unlock operations. * at once to avoid the overhead of unnecessary lock und unlock operations.
*/ */
ReturnValue_t commit(uint32_t lockTimeout = MutexIF::BLOCKING) override; ReturnValue_t commit(uint32_t lockTimeout = MutexIF::BLOCKING) override;
protected: protected:
/** /**
* @brief Like #read, but without a lock protection of the global pool. * @brief Like #read, but without a lock protection of the global pool.
@ -185,6 +187,8 @@ private:
template <typename U, uint16_t otherSize> template <typename U, uint16_t otherSize>
friend std::ostream& operator<< (std::ostream &out, friend std::ostream& operator<< (std::ostream &out,
const LocalPoolVector<U, otherSize> &var); const LocalPoolVector<U, otherSize> &var);
}; };
#include <framework/datapoollocal/LocalPoolVector.tpp> #include <framework/datapoollocal/LocalPoolVector.tpp>

View File

@ -85,8 +85,6 @@ inline ReturnValue_t LocalPoolVector<T, vectorSize>::commitWithoutLock() {
"mode for commit() call." << std::endl; "mode for commit() call." << std::endl;
return PoolVariableIF::INVALID_READ_WRITE_MODE; return PoolVariableIF::INVALID_READ_WRITE_MODE;
} }
// Wait maximum of 50 milliseconds.
MutexHelper(hkManager->getMutexHandle(), 50);
PoolEntry<T>* poolEntry = nullptr; PoolEntry<T>* poolEntry = nullptr;
ReturnValue_t result = hkManager->fetchPoolEntry(localPoolId, &poolEntry); ReturnValue_t result = hkManager->fetchPoolEntry(localPoolId, &poolEntry);
if(result != RETURN_OK) { if(result != RETURN_OK) {
@ -106,8 +104,11 @@ inline T& LocalPoolVector<T, vectorSize>::operator [](int i) {
if(i <= vectorSize) { if(i <= vectorSize) {
return value[i]; return value[i];
} }
sif::warning << "LocalPoolVector: Invalid index" << std::endl; // If this happens, I have to set some value. I consider this
return 0; // a configuration error, but I wont exit here.
sif::error << "LocalPoolVector: Invalid index. Setting or returning"
" last value!" << std::endl;
return value[i];
} }
template<typename T, uint16_t vectorSize> template<typename T, uint16_t vectorSize>
@ -115,8 +116,11 @@ inline const T& LocalPoolVector<T, vectorSize>::operator [](int i) const {
if(i <= vectorSize) { if(i <= vectorSize) {
return value[i]; return value[i];
} }
sif::warning << "LocalPoolVector: Invalid index" << std::endl; // If this happens, I have to set some value. I consider this
return 0; // a configuration error, but I wont exit here.
sif::error << "LocalPoolVector: Invalid index. Setting or returning"
" last value!" << std::endl;
return value[i];
} }
template<typename T, uint16_t vectorSize> template<typename T, uint16_t vectorSize>