rearchitectured a little bit
This commit is contained in:
parent
2d28f71eca
commit
6010246592
@ -88,7 +88,8 @@ ReturnValue_t PoolDataSetBase::readVariable(uint16_t count) {
|
|||||||
{
|
{
|
||||||
if(protectEveryReadCommitCall) {
|
if(protectEveryReadCommitCall) {
|
||||||
result = registeredVariables[count]->read(
|
result = registeredVariables[count]->read(
|
||||||
MutexIF::TimeoutType::WAITING, mutexTimeout);
|
timeoutTypeForSingleVars,
|
||||||
|
mutexTimeoutForSingleVars);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
result = registeredVariables[count]->readWithoutLock();
|
result = registeredVariables[count]->readWithoutLock();
|
||||||
@ -122,7 +123,8 @@ void PoolDataSetBase::handleAlreadyReadDatasetCommit(
|
|||||||
!= PoolVariableIF::NO_PARAMETER) {
|
!= PoolVariableIF::NO_PARAMETER) {
|
||||||
if(protectEveryReadCommitCall) {
|
if(protectEveryReadCommitCall) {
|
||||||
registeredVariables[count]->commit(
|
registeredVariables[count]->commit(
|
||||||
MutexIF::TimeoutType::WAITING, mutexTimeout);
|
timeoutTypeForSingleVars,
|
||||||
|
mutexTimeoutForSingleVars);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
registeredVariables[count]->commitWithoutLock();
|
registeredVariables[count]->commitWithoutLock();
|
||||||
@ -144,7 +146,8 @@ ReturnValue_t PoolDataSetBase::handleUnreadDatasetCommit(
|
|||||||
!= PoolVariableIF::NO_PARAMETER) {
|
!= PoolVariableIF::NO_PARAMETER) {
|
||||||
if(protectEveryReadCommitCall) {
|
if(protectEveryReadCommitCall) {
|
||||||
result = registeredVariables[count]->commit(
|
result = registeredVariables[count]->commit(
|
||||||
MutexIF::TimeoutType::WAITING, mutexTimeout);
|
timeoutTypeForSingleVars,
|
||||||
|
mutexTimeoutForSingleVars);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
result = registeredVariables[count]->commitWithoutLock();
|
result = registeredVariables[count]->commitWithoutLock();
|
||||||
@ -219,7 +222,9 @@ PoolVariableIF** PoolDataSetBase::getContainer() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PoolDataSetBase::setReadCommitProtectionBehaviour(
|
void PoolDataSetBase::setReadCommitProtectionBehaviour(
|
||||||
bool protectEveryReadCommit, uint32_t mutexTimeout) {
|
bool protectEveryReadCommit, MutexIF::TimeoutType timeoutType,
|
||||||
|
uint32_t mutexTimeout) {
|
||||||
this->protectEveryReadCommitCall = protectEveryReadCommit;
|
this->protectEveryReadCommitCall = protectEveryReadCommit;
|
||||||
this->mutexTimeout = mutexTimeout;
|
this->timeoutTypeForSingleVars = timeoutType;
|
||||||
|
this->mutexTimeoutForSingleVars = mutexTimeout;
|
||||||
}
|
}
|
||||||
|
@ -127,6 +127,7 @@ protected:
|
|||||||
* @param mutexTimeout
|
* @param mutexTimeout
|
||||||
*/
|
*/
|
||||||
void setReadCommitProtectionBehaviour(bool protectEveryReadCommit,
|
void setReadCommitProtectionBehaviour(bool protectEveryReadCommit,
|
||||||
|
MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING,
|
||||||
uint32_t mutexTimeout = 20);
|
uint32_t mutexTimeout = 20);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -161,7 +162,8 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
bool protectEveryReadCommitCall = false;
|
bool protectEveryReadCommitCall = false;
|
||||||
uint32_t mutexTimeout = 20;
|
MutexIF::TimeoutType timeoutTypeForSingleVars;
|
||||||
|
uint32_t mutexTimeoutForSingleVars = 20;
|
||||||
|
|
||||||
ReturnValue_t readVariable(uint16_t count);
|
ReturnValue_t readVariable(uint16_t count);
|
||||||
void handleAlreadyReadDatasetCommit(
|
void handleAlreadyReadDatasetCommit(
|
||||||
|
@ -19,15 +19,16 @@ LocalPoolDataSetBase::LocalPoolDataSetBase(HasLocalDataPoolIF *hkOwner,
|
|||||||
<< "invalid!" << std::endl;
|
<< "invalid!" << std::endl;
|
||||||
#else
|
#else
|
||||||
fsfw::printError("LocalPoolDataSetBase::LocalPoolDataSetBase: Owner "
|
fsfw::printError("LocalPoolDataSetBase::LocalPoolDataSetBase: Owner "
|
||||||
"invalid!\n\r");
|
"invalid!\n");
|
||||||
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
hkManager = hkOwner->getHkManagerHandle();
|
LocalDataPoolManager* hkManager = hkOwner->getHkManagerHandle();
|
||||||
|
mutexIfSingleDataCreator = hkManager->getMutexHandle();
|
||||||
this->sid.objectId = hkOwner->getObjectId();
|
this->sid.objectId = hkOwner->getObjectId();
|
||||||
this->sid.ownerSetId = setId;
|
this->sid.ownerSetId = setId;
|
||||||
|
|
||||||
mutex = MutexFactory::instance()->createMutex();
|
//mutex = MutexFactory::instance()->createMutex();
|
||||||
|
|
||||||
// Data creators get a periodic helper for periodic HK data generation.
|
// Data creators get a periodic helper for periodic HK data generation.
|
||||||
if(periodicHandling) {
|
if(periodicHandling) {
|
||||||
@ -41,34 +42,29 @@ LocalPoolDataSetBase::LocalPoolDataSetBase(sid_t sid,
|
|||||||
PoolDataSetBase(registeredVariablesArray, maxNumberOfVariables) {
|
PoolDataSetBase(registeredVariablesArray, maxNumberOfVariables) {
|
||||||
HasLocalDataPoolIF* hkOwner = objectManager->get<HasLocalDataPoolIF>(
|
HasLocalDataPoolIF* hkOwner = objectManager->get<HasLocalDataPoolIF>(
|
||||||
sid.objectId);
|
sid.objectId);
|
||||||
if(hkOwner != nullptr) {
|
LocalDataPoolManager* hkManager = hkOwner->getHkManagerHandle();
|
||||||
hkManager = hkOwner->getHkManagerHandle();
|
mutexIfSingleDataCreator = hkManager->getMutexHandle();
|
||||||
}
|
|
||||||
this->sid = sid;
|
this->sid = sid;
|
||||||
|
|
||||||
mutex = MutexFactory::instance()->createMutex();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LocalPoolDataSetBase::LocalPoolDataSetBase(
|
LocalPoolDataSetBase::LocalPoolDataSetBase(
|
||||||
PoolVariableIF **registeredVariablesArray,
|
PoolVariableIF **registeredVariablesArray,
|
||||||
const size_t maxNumberOfVariables, bool protectFunctions):
|
const size_t maxNumberOfVariables):
|
||||||
PoolDataSetBase(registeredVariablesArray, maxNumberOfVariables) {
|
PoolDataSetBase(registeredVariablesArray, maxNumberOfVariables) {
|
||||||
if(protectFunctions) {
|
|
||||||
mutex = MutexFactory::instance()->createMutex();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
LocalPoolDataSetBase::~LocalPoolDataSetBase() {
|
LocalPoolDataSetBase::~LocalPoolDataSetBase() {
|
||||||
|
if(periodicHelper != nullptr) {
|
||||||
|
delete periodicHelper;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t LocalPoolDataSetBase::lockDataPool(
|
ReturnValue_t LocalPoolDataSetBase::lockDataPool(
|
||||||
MutexIF::TimeoutType timeoutType,
|
MutexIF::TimeoutType timeoutType,
|
||||||
uint32_t timeoutMs) {
|
uint32_t timeoutMs) {
|
||||||
if(hkManager != nullptr) {
|
if(mutexIfSingleDataCreator != nullptr) {
|
||||||
MutexIF* poolMutex = hkManager->getMutexHandle();
|
return mutexIfSingleDataCreator->lockMutex(timeoutType, timeoutMs);
|
||||||
return poolMutex->lockMutex(timeoutType, timeoutMs);
|
|
||||||
}
|
}
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
@ -146,9 +142,8 @@ ReturnValue_t LocalPoolDataSetBase::deSerializeWithValidityBuffer(
|
|||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t LocalPoolDataSetBase::unlockDataPool() {
|
ReturnValue_t LocalPoolDataSetBase::unlockDataPool() {
|
||||||
if(hkManager != nullptr) {
|
if(mutexIfSingleDataCreator != nullptr) {
|
||||||
MutexIF* mutex = hkManager->getMutexHandle();
|
return mutexIfSingleDataCreator->unlockMutex();
|
||||||
return mutex->unlockMutex();
|
|
||||||
}
|
}
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
@ -268,19 +263,10 @@ void LocalPoolDataSetBase::initializePeriodicHelper(
|
|||||||
}
|
}
|
||||||
|
|
||||||
void LocalPoolDataSetBase::setChanged(bool changed) {
|
void LocalPoolDataSetBase::setChanged(bool changed) {
|
||||||
if(mutex == nullptr) {
|
|
||||||
this->changed = changed;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
MutexHelper(mutex, MutexIF::TimeoutType::WAITING, mutexTimeout);
|
|
||||||
this->changed = changed;
|
this->changed = changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LocalPoolDataSetBase::hasChanged() const {
|
bool LocalPoolDataSetBase::hasChanged() const {
|
||||||
if(mutex == nullptr) {
|
|
||||||
return changed;
|
|
||||||
}
|
|
||||||
MutexHelper(mutex, MutexIF::TimeoutType::WAITING, mutexTimeout);
|
|
||||||
return changed;
|
return changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -302,32 +288,16 @@ bool LocalPoolDataSetBase::bitGetter(const uint8_t* byte,
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool LocalPoolDataSetBase::isValid() const {
|
bool LocalPoolDataSetBase::isValid() const {
|
||||||
if(mutex == nullptr) {
|
|
||||||
return this->valid;
|
|
||||||
}
|
|
||||||
MutexHelper(mutex, MutexIF::TimeoutType::WAITING, 5);
|
|
||||||
return this->valid;
|
return this->valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocalPoolDataSetBase::setValidity(bool valid, bool setEntriesRecursively) {
|
void LocalPoolDataSetBase::setValidity(bool valid, bool setEntriesRecursively) {
|
||||||
mutex->lockMutex(timeoutType, mutexTimeout);
|
|
||||||
if(setEntriesRecursively) {
|
if(setEntriesRecursively) {
|
||||||
for(size_t idx = 0; idx < this->getFillCount(); idx++) {
|
for(size_t idx = 0; idx < this->getFillCount(); idx++) {
|
||||||
registeredVariables[idx] -> setValid(valid);
|
registeredVariables[idx] -> setValid(valid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this->valid = valid;
|
this->valid = valid;
|
||||||
mutex->unlockMutex();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocalPoolDataSetBase::setReadCommitProtectionBehaviour(
|
|
||||||
bool protectEveryReadCommit, uint32_t mutexTimeout) {
|
|
||||||
PoolDataSetBase::setReadCommitProtectionBehaviour(protectEveryReadCommit,
|
|
||||||
mutexTimeout);
|
|
||||||
}
|
|
||||||
|
|
||||||
void LocalPoolDataSetBase::setDataSetMutexTimeout(
|
|
||||||
MutexIF::TimeoutType timeoutType, uint32_t mutexTimeout) {
|
|
||||||
this->timeoutType = timeoutType;
|
|
||||||
this->mutexTimeout = mutexTimeout;
|
|
||||||
}
|
|
||||||
|
@ -57,7 +57,8 @@ public:
|
|||||||
const size_t maxNumberOfVariables, bool periodicHandling = true);
|
const size_t maxNumberOfVariables, bool periodicHandling = true);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Constructor for users of local pool data.
|
* @brief Constructor for users of the local pool data, which need
|
||||||
|
* to access data created by one HK manager.
|
||||||
* @details
|
* @details
|
||||||
* @param sid Unique identifier of dataset consisting of object ID and
|
* @param sid Unique identifier of dataset consisting of object ID and
|
||||||
* set ID.
|
* set ID.
|
||||||
@ -68,13 +69,22 @@ public:
|
|||||||
const size_t maxNumberOfVariables);
|
const size_t maxNumberOfVariables);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple constructor, if the dataset is not owner permanently by
|
* Simple constructor, if the dataset is not the owner by
|
||||||
* a class with a HK manager.
|
* a class with a HK manager. This function should also be called by
|
||||||
|
* classes which needs to access pool variables from different creators.
|
||||||
|
*
|
||||||
|
* If the class is intended to access pool variables from different
|
||||||
|
* creators, the third argument should be set to true. The mutex
|
||||||
|
* properties can be set with #setReadCommitProtectionBehaviour .
|
||||||
* @param registeredVariablesArray
|
* @param registeredVariablesArray
|
||||||
* @param maxNumberOfVariables
|
* @param maxNumberOfVariables
|
||||||
|
* @param protectEveryReadCommitCall If the pool variables are created by
|
||||||
|
* multiple creators, this flag can be set to protect all read and
|
||||||
|
* commit calls separately.
|
||||||
*/
|
*/
|
||||||
LocalPoolDataSetBase(PoolVariableIF** registeredVariablesArray,
|
LocalPoolDataSetBase(PoolVariableIF** registeredVariablesArray,
|
||||||
const size_t maxNumberOfVariables, bool protectFunctions = true);
|
const size_t maxNumberOfVariables,
|
||||||
|
bool protectEveryReadCommitCall = true);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The destructor automatically manages writing the valid
|
* @brief The destructor automatically manages writing the valid
|
||||||
@ -86,19 +96,6 @@ public:
|
|||||||
*/
|
*/
|
||||||
~LocalPoolDataSetBase();
|
~LocalPoolDataSetBase();
|
||||||
|
|
||||||
/**
|
|
||||||
* If the data is pulled from different local data pools, every read and
|
|
||||||
* commit call should be mutex protected for thread safety.
|
|
||||||
* This can be specified with the second parameter.
|
|
||||||
* @param dataCreator
|
|
||||||
* @param protectEveryReadCommit
|
|
||||||
*/
|
|
||||||
void setReadCommitProtectionBehaviour(bool protectEveryReadCommit,
|
|
||||||
uint32_t mutexTimeout = 20);
|
|
||||||
|
|
||||||
void setDataSetMutexTimeout(MutexIF::TimeoutType timeoutType,
|
|
||||||
uint32_t mutexTimeout);
|
|
||||||
|
|
||||||
void setValidityBufferGeneration(bool withValidityBuffer);
|
void setValidityBufferGeneration(bool withValidityBuffer);
|
||||||
|
|
||||||
sid_t getSid() const;
|
sid_t getSid() const;
|
||||||
@ -150,13 +147,8 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
sid_t sid;
|
sid_t sid;
|
||||||
MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING;
|
//! This mutex is used if the data is created by one object only.
|
||||||
uint32_t mutexTimeout = 20;
|
MutexIF* mutexIfSingleDataCreator = nullptr;
|
||||||
/**
|
|
||||||
* This mutex is required because the dataset can potentially be accessed
|
|
||||||
* by multiple threads for information like change status or validity.
|
|
||||||
*/
|
|
||||||
MutexIF* mutex = nullptr;
|
|
||||||
|
|
||||||
bool diagnostic = false;
|
bool diagnostic = false;
|
||||||
void setDiagnostic(bool diagnostics);
|
void setDiagnostic(bool diagnostics);
|
||||||
@ -211,8 +203,6 @@ protected:
|
|||||||
*/
|
*/
|
||||||
ReturnValue_t unlockDataPool() override;
|
ReturnValue_t unlockDataPool() override;
|
||||||
|
|
||||||
LocalDataPoolManager* hkManager = nullptr;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set n-th bit of a byte, with n being the position from 0
|
* Set n-th bit of a byte, with n being the position from 0
|
||||||
* (most significant bit) to 7 (least significant bit)
|
* (most significant bit) to 7 (least significant bit)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user