mutex helper api change

This commit is contained in:
Robin Müller 2020-08-07 22:15:03 +02:00
parent 458e849f7d
commit 979fea3400
6 changed files with 23 additions and 16 deletions

View File

@ -19,41 +19,41 @@ SharedRingBuffer::SharedRingBuffer(object_id_t objectId, uint8_t *buffer,
ReturnValue_t SharedRingBuffer::getFreeElementProtected(uint8_t** writePtr, ReturnValue_t SharedRingBuffer::getFreeElementProtected(uint8_t** writePtr,
size_t amount) { size_t amount) {
MutexHelper(mutex, mutexTimeout); MutexHelper(mutex, MutexIF::TimeoutType::WAITING, mutexTimeout);
return SimpleRingBuffer::getFreeElement(writePtr,amount); return SimpleRingBuffer::getFreeElement(writePtr,amount);
} }
ReturnValue_t SharedRingBuffer::writeDataProtected(const uint8_t *data, ReturnValue_t SharedRingBuffer::writeDataProtected(const uint8_t *data,
size_t amount) { size_t amount) {
MutexHelper(mutex, mutexTimeout); MutexHelper(mutex, MutexIF::TimeoutType::WAITING, mutexTimeout);
return SimpleRingBuffer::writeData(data,amount); return SimpleRingBuffer::writeData(data,amount);
} }
ReturnValue_t SharedRingBuffer::readDataProtected(uint8_t *data, size_t amount, ReturnValue_t SharedRingBuffer::readDataProtected(uint8_t *data, size_t amount,
bool incrementReadPtr, bool readRemaining, bool incrementReadPtr, bool readRemaining,
size_t *trueAmount) { size_t *trueAmount) {
MutexHelper(mutex, mutexTimeout); MutexHelper(mutex, MutexIF::TimeoutType::WAITING, mutexTimeout);
return SimpleRingBuffer::readData(data,amount, incrementReadPtr, return SimpleRingBuffer::readData(data,amount, incrementReadPtr,
readRemaining, trueAmount); readRemaining, trueAmount);
} }
ReturnValue_t SharedRingBuffer::deleteDataProtected(size_t amount, ReturnValue_t SharedRingBuffer::deleteDataProtected(size_t amount,
bool deleteRemaining, size_t *trueAmount) { bool deleteRemaining, size_t *trueAmount) {
MutexHelper(mutex, mutexTimeout); MutexHelper(mutex, MutexIF::TimeoutType::WAITING, mutexTimeout);
return SimpleRingBuffer::deleteData(amount, deleteRemaining, trueAmount); return SimpleRingBuffer::deleteData(amount, deleteRemaining, trueAmount);
} }
size_t SharedRingBuffer::getExcessBytes() const { size_t SharedRingBuffer::getExcessBytes() const {
MutexHelper(mutex, mutexTimeout); MutexHelper(mutex, MutexIF::TimeoutType::WAITING, mutexTimeout);
return SimpleRingBuffer::getExcessBytes(); return SimpleRingBuffer::getExcessBytes();
} }
void SharedRingBuffer::moveExcessBytesToStart() { void SharedRingBuffer::moveExcessBytesToStart() {
MutexHelper(mutex, mutexTimeout); MutexHelper(mutex, MutexIF::TimeoutType::WAITING, mutexTimeout);
return SimpleRingBuffer::moveExcessBytesToStart(); return SimpleRingBuffer::moveExcessBytesToStart();
} }
size_t SharedRingBuffer::getAvailableReadDataProtected(uint8_t n) const { size_t SharedRingBuffer::getAvailableReadDataProtected(uint8_t n) const {
MutexHelper(mutex, mutexTimeout); MutexHelper(mutex, MutexIF::TimeoutType::WAITING, mutexTimeout);
return ((write + size) - read[n]) % size; return ((write + size) - read[n]) % size;
} }

View File

@ -48,7 +48,8 @@ inline LocalPoolVar<T>::LocalPoolVar(lp_id_t poolId, object_id_t poolOwner,
template<typename T> template<typename T>
inline ReturnValue_t LocalPoolVar<T>::read(dur_millis_t lockTimeout) { inline ReturnValue_t LocalPoolVar<T>::read(dur_millis_t lockTimeout) {
MutexHelper(hkManager->getMutexHandle(), lockTimeout); MutexHelper(hkManager->getMutexHandle(), MutexIF::TimeoutType::WAITING,
lockTimeout);
return readWithoutLock(); return readWithoutLock();
} }
@ -76,7 +77,8 @@ inline ReturnValue_t LocalPoolVar<T>::readWithoutLock() {
template<typename T> template<typename T>
inline ReturnValue_t LocalPoolVar<T>::commit(dur_millis_t lockTimeout) { inline ReturnValue_t LocalPoolVar<T>::commit(dur_millis_t lockTimeout) {
MutexHelper(hkManager->getMutexHandle(), lockTimeout); MutexHelper(hkManager->getMutexHandle(), MutexIF::TimeoutType::WAITING,
lockTimeout);
return commitWithoutLock(); return commitWithoutLock();
} }

View File

@ -44,7 +44,8 @@ inline LocalPoolVector<T, vectorSize>::LocalPoolVector(lp_id_t poolId,
template<typename T, uint16_t vectorSize> template<typename T, uint16_t vectorSize>
inline ReturnValue_t LocalPoolVector<T, vectorSize>::read(uint32_t lockTimeout) { inline ReturnValue_t LocalPoolVector<T, vectorSize>::read(uint32_t lockTimeout) {
MutexHelper(hkManager->getMutexHandle(), lockTimeout); MutexHelper(hkManager->getMutexHandle(), MutexIF::TimeoutType::WAITING,
lockTimeout);
return readWithoutLock(); return readWithoutLock();
} }
template<typename T, uint16_t vectorSize> template<typename T, uint16_t vectorSize>
@ -74,7 +75,8 @@ inline ReturnValue_t LocalPoolVector<T, vectorSize>::readWithoutLock() {
template<typename T, uint16_t vectorSize> template<typename T, uint16_t vectorSize>
inline ReturnValue_t LocalPoolVector<T, vectorSize>::commit( inline ReturnValue_t LocalPoolVector<T, vectorSize>::commit(
uint32_t lockTimeout) { uint32_t lockTimeout) {
MutexHelper(hkManager->getMutexHandle(), lockTimeout); MutexHelper(hkManager->getMutexHandle(), MutexIF::TimeoutType::WAITING,
lockTimeout);
return commitWithoutLock(); return commitWithoutLock();
} }

View File

@ -7,7 +7,7 @@
class MutexHelper { class MutexHelper {
public: public:
MutexHelper(MutexIF* mutex, MutexIF::TimeoutType timeoutType = MutexHelper(MutexIF* mutex, MutexIF::TimeoutType timeoutType =
MutexIF::TimeoutType::BLOCKING, uint32_t timeoutMs) : MutexIF::TimeoutType::BLOCKING, uint32_t timeoutMs = 0) :
internalMutex(mutex) { internalMutex(mutex) {
ReturnValue_t status = mutex->lockMutex(timeoutType, ReturnValue_t status = mutex->lockMutex(timeoutType,
timeoutMs); timeoutMs);

View File

@ -85,7 +85,7 @@ ReturnValue_t TmTcUnixUdpBridge::sendTm(const uint8_t *data, size_t dataLen) {
} }
void TmTcUnixUdpBridge::checkAndSetClientAddress(sockaddr_in newAddress) { void TmTcUnixUdpBridge::checkAndSetClientAddress(sockaddr_in newAddress) {
MutexHelper lock(mutex, 10); MutexHelper lock(mutex, MutexIF::TimeoutType::WAITING, 10);
// char ipAddress [15]; // char ipAddress [15];
// sif::debug << "IP Address Sender: "<< inet_ntop(AF_INET, // sif::debug << "IP Address Sender: "<< inet_ntop(AF_INET,

View File

@ -21,7 +21,8 @@ inline PoolManager<NUMBER_OF_POOLS>::~PoolManager(void) {
template<uint8_t NUMBER_OF_POOLS> template<uint8_t NUMBER_OF_POOLS>
inline ReturnValue_t PoolManager<NUMBER_OF_POOLS>::reserveSpace( inline ReturnValue_t PoolManager<NUMBER_OF_POOLS>::reserveSpace(
const uint32_t size, store_address_t* address, bool ignoreFault) { const uint32_t size, store_address_t* address, bool ignoreFault) {
MutexHelper mutexHelper(mutex, mutexTimeout); MutexHelper mutexHelper(mutex, MutexIF::TimeoutType::WAITING,
mutexTimeout);
ReturnValue_t status = LocalPool<NUMBER_OF_POOLS>::reserveSpace(size, ReturnValue_t status = LocalPool<NUMBER_OF_POOLS>::reserveSpace(size,
address,ignoreFault); address,ignoreFault);
return status; return status;
@ -33,7 +34,8 @@ inline ReturnValue_t PoolManager<NUMBER_OF_POOLS>::deleteData(
// debug << "PoolManager( " << translateObject(getObjectId()) << // debug << "PoolManager( " << translateObject(getObjectId()) <<
// " )::deleteData from store " << packet_id.pool_index << // " )::deleteData from store " << packet_id.pool_index <<
// ". id is "<< packet_id.packet_index << std::endl; // ". id is "<< packet_id.packet_index << std::endl;
MutexHelper mutexHelper(mutex, mutexTimeout); MutexHelper mutexHelper(mutex, MutexIF::TimeoutType::WAITING,
mutexTimeout);
ReturnValue_t status = LocalPool<NUMBER_OF_POOLS>::deleteData(packet_id); ReturnValue_t status = LocalPool<NUMBER_OF_POOLS>::deleteData(packet_id);
return status; return status;
} }
@ -41,7 +43,8 @@ inline ReturnValue_t PoolManager<NUMBER_OF_POOLS>::deleteData(
template<uint8_t NUMBER_OF_POOLS> template<uint8_t NUMBER_OF_POOLS>
inline ReturnValue_t PoolManager<NUMBER_OF_POOLS>::deleteData(uint8_t* buffer, inline ReturnValue_t PoolManager<NUMBER_OF_POOLS>::deleteData(uint8_t* buffer,
size_t size, store_address_t* storeId) { size_t size, store_address_t* storeId) {
MutexHelper mutexHelper(mutex, mutexTimeout); MutexHelper mutexHelper(mutex, MutexIF::TimeoutType::WAITING,
mutexTimeout);
ReturnValue_t status = LocalPool<NUMBER_OF_POOLS>::deleteData(buffer, ReturnValue_t status = LocalPool<NUMBER_OF_POOLS>::deleteData(buffer,
size, storeId); size, storeId);
return status; return status;