From 98e6ca5f78b19e679f5f527db1c3612f8e1f214a Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Sun, 7 Jun 2020 15:22:32 +0200 Subject: [PATCH] removed locks in lockless functions --- datapoollocal/LocalPoolVariable.tpp | 2 -- datapoollocal/LocalPoolVector.h | 10 +++++++--- datapoollocal/LocalPoolVector.tpp | 16 ++++++++++------ 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/datapoollocal/LocalPoolVariable.tpp b/datapoollocal/LocalPoolVariable.tpp index 0140b29d..9dcd0699 100644 --- a/datapoollocal/LocalPoolVariable.tpp +++ b/datapoollocal/LocalPoolVariable.tpp @@ -87,8 +87,6 @@ inline ReturnValue_t LocalPoolVar::commitWithoutLock() { "mode for commit() call." << std::endl; return PoolVariableIF::INVALID_READ_WRITE_MODE; } - // Wait maximum of 50 milliseconds. - MutexHelper(hkManager->getMutexHandle(), 50); PoolEntry* poolEntry = nullptr; ReturnValue_t result = hkManager->fetchPoolEntry(localPoolId, &poolEntry); if(result != RETURN_OK) { diff --git a/datapoollocal/LocalPoolVector.h b/datapoollocal/LocalPoolVector.h index 1c5f1d65..a8d0a7bb 100644 --- a/datapoollocal/LocalPoolVector.h +++ b/datapoollocal/LocalPoolVector.h @@ -70,8 +70,9 @@ public: /** * @brief This is the local copy of the data pool entry. - * @details The user can work on this attribute - * just like he would on a local array of this type. + * @details + * The user can work on this attribute just like he would on a local + * array of this type. */ T value[vectorSize]; /** @@ -109,7 +110,7 @@ public: void setValid(bool valid) override; uint8_t getValid() const; - T &operator [](int i); + T& operator [](int i); const T &operator [](int i) const; 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. */ ReturnValue_t commit(uint32_t lockTimeout = MutexIF::BLOCKING) override; + protected: /** * @brief Like #read, but without a lock protection of the global pool. @@ -185,6 +187,8 @@ private: template friend std::ostream& operator<< (std::ostream &out, const LocalPoolVector &var); + + }; #include diff --git a/datapoollocal/LocalPoolVector.tpp b/datapoollocal/LocalPoolVector.tpp index bd35eed3..a18f8327 100644 --- a/datapoollocal/LocalPoolVector.tpp +++ b/datapoollocal/LocalPoolVector.tpp @@ -85,8 +85,6 @@ inline ReturnValue_t LocalPoolVector::commitWithoutLock() { "mode for commit() call." << std::endl; return PoolVariableIF::INVALID_READ_WRITE_MODE; } - // Wait maximum of 50 milliseconds. - MutexHelper(hkManager->getMutexHandle(), 50); PoolEntry* poolEntry = nullptr; ReturnValue_t result = hkManager->fetchPoolEntry(localPoolId, &poolEntry); if(result != RETURN_OK) { @@ -106,8 +104,11 @@ inline T& LocalPoolVector::operator [](int i) { if(i <= vectorSize) { return value[i]; } - sif::warning << "LocalPoolVector: Invalid index" << std::endl; - return 0; + // If this happens, I have to set some value. I consider this + // a configuration error, but I wont exit here. + sif::error << "LocalPoolVector: Invalid index. Setting or returning" + " last value!" << std::endl; + return value[i]; } template @@ -115,8 +116,11 @@ inline const T& LocalPoolVector::operator [](int i) const { if(i <= vectorSize) { return value[i]; } - sif::warning << "LocalPoolVector: Invalid index" << std::endl; - return 0; + // If this happens, I have to set some value. I consider this + // a configuration error, but I wont exit here. + sif::error << "LocalPoolVector: Invalid index. Setting or returning" + " last value!" << std::endl; + return value[i]; } template