renamed mutex helper to mutex guard
This commit is contained in:
parent
caa3cf538b
commit
da2f594a00
@ -31,7 +31,7 @@ ReturnValue_t HealthTable::registerObject(object_id_t object,
|
||||
|
||||
void HealthTable::setHealth(object_id_t object,
|
||||
HasHealthIF::HealthState newState) {
|
||||
MutexHelper(mutex, timeoutType, mutexTimeoutMs);
|
||||
MutexGuard(mutex, timeoutType, mutexTimeoutMs);
|
||||
HealthMap::iterator iter = healthMap.find(object);
|
||||
if (iter != healthMap.end()) {
|
||||
iter->second = newState;
|
||||
@ -40,7 +40,7 @@ void HealthTable::setHealth(object_id_t object,
|
||||
|
||||
HasHealthIF::HealthState HealthTable::getHealth(object_id_t object) {
|
||||
HasHealthIF::HealthState state = HasHealthIF::HEALTHY;
|
||||
MutexHelper(mutex, timeoutType, mutexTimeoutMs);
|
||||
MutexGuard(mutex, timeoutType, mutexTimeoutMs);
|
||||
HealthMap::iterator iter = healthMap.find(object);
|
||||
if (iter != healthMap.end()) {
|
||||
state = iter->second;
|
||||
@ -49,7 +49,7 @@ HasHealthIF::HealthState HealthTable::getHealth(object_id_t object) {
|
||||
}
|
||||
|
||||
bool HealthTable::hasHealth(object_id_t object) {
|
||||
MutexHelper(mutex, timeoutType, mutexTimeoutMs);
|
||||
MutexGuard(mutex, timeoutType, mutexTimeoutMs);
|
||||
HealthMap::iterator iter = healthMap.find(object);
|
||||
if (iter != healthMap.end()) {
|
||||
return true;
|
||||
@ -58,14 +58,14 @@ bool HealthTable::hasHealth(object_id_t object) {
|
||||
}
|
||||
|
||||
size_t HealthTable::getPrintSize() {
|
||||
MutexHelper(mutex, timeoutType, mutexTimeoutMs);
|
||||
MutexGuard(mutex, timeoutType, mutexTimeoutMs);
|
||||
uint32_t size = healthMap.size() * sizeof(object_id_t) +
|
||||
sizeof(HasHealthIF::HealthState) + sizeof(uint16_t);
|
||||
return size;
|
||||
}
|
||||
|
||||
void HealthTable::printAll(uint8_t* pointer, size_t maxSize) {
|
||||
MutexHelper(mutex, timeoutType, mutexTimeoutMs);
|
||||
MutexGuard(mutex, timeoutType, mutexTimeoutMs);
|
||||
size_t size = 0;
|
||||
uint16_t count = healthMap.size();
|
||||
SerializeAdapter::serialize(&count,
|
||||
@ -81,7 +81,7 @@ void HealthTable::printAll(uint8_t* pointer, size_t maxSize) {
|
||||
|
||||
ReturnValue_t HealthTable::iterate(HealthEntry *value, bool reset) {
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||
MutexHelper(mutex, timeoutType, mutexTimeoutMs);
|
||||
MutexGuard(mutex, timeoutType, mutexTimeoutMs);
|
||||
if (reset) {
|
||||
mapIterator = healthMap.begin();
|
||||
}
|
||||
|
@ -4,9 +4,9 @@
|
||||
#include "MutexFactory.h"
|
||||
#include "../serviceinterface/ServiceInterface.h"
|
||||
|
||||
class MutexHelper {
|
||||
class MutexGuard {
|
||||
public:
|
||||
MutexHelper(MutexIF* mutex, MutexIF::TimeoutType timeoutType =
|
||||
MutexGuard(MutexIF* mutex, MutexIF::TimeoutType timeoutType =
|
||||
MutexIF::TimeoutType::BLOCKING, uint32_t timeoutMs = 0):
|
||||
internalMutex(mutex) {
|
||||
if(mutex == nullptr) {
|
||||
@ -19,10 +19,10 @@ public:
|
||||
#endif /* FSFW_VERBOSE_LEVEL >= 1 */
|
||||
return;
|
||||
}
|
||||
ReturnValue_t status = mutex->lockMutex(timeoutType,
|
||||
result = mutex->lockMutex(timeoutType,
|
||||
timeoutMs);
|
||||
#if FSFW_VERBOSE_LEVEL >= 1
|
||||
if(status == MutexIF::MUTEX_TIMEOUT) {
|
||||
if(result == MutexIF::MUTEX_TIMEOUT) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "MutexHelper: Lock of mutex failed with timeout of "
|
||||
<< timeoutMs << " milliseconds!" << std::endl;
|
||||
@ -32,9 +32,9 @@ public:
|
||||
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
||||
|
||||
}
|
||||
else if(status != HasReturnvaluesIF::RETURN_OK) {
|
||||
else if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "MutexHelper: Lock of Mutex failed with code " << status << std::endl;
|
||||
sif::error << "MutexHelper: Lock of Mutex failed with code " << result << std::endl;
|
||||
#else
|
||||
sif::printError("MutexHelper: Lock of Mutex failed with code %d\n", status);
|
||||
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
||||
@ -45,13 +45,18 @@ public:
|
||||
#endif /* FSFW_VERBOSE_LEVEL >= 1 */
|
||||
}
|
||||
|
||||
~MutexHelper() {
|
||||
ReturnValue_t getLockResult() const {
|
||||
return result;
|
||||
}
|
||||
|
||||
~MutexGuard() {
|
||||
if(internalMutex != nullptr) {
|
||||
internalMutex->unlockMutex();
|
||||
}
|
||||
}
|
||||
private:
|
||||
MutexIF* internalMutex;
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_FAILED;
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_IPC_MUTEXHELPER_H_ */
|
@ -106,7 +106,7 @@ ReturnValue_t TmTcWinUdpBridge::sendTm(const uint8_t *data, size_t dataLen) {
|
||||
}
|
||||
|
||||
void TmTcWinUdpBridge::checkAndSetClientAddress(sockaddr_in newAddress) {
|
||||
MutexHelper lock(mutex, MutexIF::TimeoutType::WAITING, 10);
|
||||
MutexGuard lock(mutex, MutexIF::TimeoutType::WAITING, 10);
|
||||
|
||||
// char ipAddress [15];
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
|
@ -15,7 +15,7 @@ PoolManager::~PoolManager(void) {
|
||||
|
||||
ReturnValue_t PoolManager::reserveSpace(const size_t size,
|
||||
store_address_t* address, bool ignoreFault) {
|
||||
MutexHelper mutexHelper(mutex, MutexIF::TimeoutType::WAITING,
|
||||
MutexGuard mutexHelper(mutex, MutexIF::TimeoutType::WAITING,
|
||||
mutexTimeoutMs);
|
||||
ReturnValue_t status = LocalPool::reserveSpace(size,
|
||||
address,ignoreFault);
|
||||
@ -32,7 +32,7 @@ ReturnValue_t PoolManager::deleteData(
|
||||
". id is "<< storeId.packetIndex << std::endl;
|
||||
#endif
|
||||
#endif
|
||||
MutexHelper mutexHelper(mutex, MutexIF::TimeoutType::WAITING,
|
||||
MutexGuard mutexHelper(mutex, MutexIF::TimeoutType::WAITING,
|
||||
mutexTimeoutMs);
|
||||
return LocalPool::deleteData(storeId);
|
||||
}
|
||||
@ -40,7 +40,7 @@ ReturnValue_t PoolManager::deleteData(
|
||||
|
||||
ReturnValue_t PoolManager::deleteData(uint8_t* buffer,
|
||||
size_t size, store_address_t* storeId) {
|
||||
MutexHelper mutexHelper(mutex, MutexIF::TimeoutType::WAITING, 20);
|
||||
MutexGuard mutexHelper(mutex, MutexIF::TimeoutType::WAITING, 20);
|
||||
ReturnValue_t status = LocalPool::deleteData(buffer,
|
||||
size, storeId);
|
||||
return status;
|
||||
|
Loading…
Reference in New Issue
Block a user