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,
size_t amount) {
MutexHelper(mutex, mutexTimeout);
MutexHelper(mutex, MutexIF::TimeoutType::WAITING, mutexTimeout);
return SimpleRingBuffer::getFreeElement(writePtr,amount);
}
ReturnValue_t SharedRingBuffer::writeDataProtected(const uint8_t *data,
size_t amount) {
MutexHelper(mutex, mutexTimeout);
MutexHelper(mutex, MutexIF::TimeoutType::WAITING, mutexTimeout);
return SimpleRingBuffer::writeData(data,amount);
}
ReturnValue_t SharedRingBuffer::readDataProtected(uint8_t *data, size_t amount,
bool incrementReadPtr, bool readRemaining,
size_t *trueAmount) {
MutexHelper(mutex, mutexTimeout);
MutexHelper(mutex, MutexIF::TimeoutType::WAITING, mutexTimeout);
return SimpleRingBuffer::readData(data,amount, incrementReadPtr,
readRemaining, trueAmount);
}
ReturnValue_t SharedRingBuffer::deleteDataProtected(size_t amount,
bool deleteRemaining, size_t *trueAmount) {
MutexHelper(mutex, mutexTimeout);
MutexHelper(mutex, MutexIF::TimeoutType::WAITING, mutexTimeout);
return SimpleRingBuffer::deleteData(amount, deleteRemaining, trueAmount);
}
size_t SharedRingBuffer::getExcessBytes() const {
MutexHelper(mutex, mutexTimeout);
MutexHelper(mutex, MutexIF::TimeoutType::WAITING, mutexTimeout);
return SimpleRingBuffer::getExcessBytes();
}
void SharedRingBuffer::moveExcessBytesToStart() {
MutexHelper(mutex, mutexTimeout);
MutexHelper(mutex, MutexIF::TimeoutType::WAITING, mutexTimeout);
return SimpleRingBuffer::moveExcessBytesToStart();
}
size_t SharedRingBuffer::getAvailableReadDataProtected(uint8_t n) const {
MutexHelper(mutex, mutexTimeout);
MutexHelper(mutex, MutexIF::TimeoutType::WAITING, mutexTimeout);
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>
inline ReturnValue_t LocalPoolVar<T>::read(dur_millis_t lockTimeout) {
MutexHelper(hkManager->getMutexHandle(), lockTimeout);
MutexHelper(hkManager->getMutexHandle(), MutexIF::TimeoutType::WAITING,
lockTimeout);
return readWithoutLock();
}
@ -76,7 +77,8 @@ inline ReturnValue_t LocalPoolVar<T>::readWithoutLock() {
template<typename T>
inline ReturnValue_t LocalPoolVar<T>::commit(dur_millis_t lockTimeout) {
MutexHelper(hkManager->getMutexHandle(), lockTimeout);
MutexHelper(hkManager->getMutexHandle(), MutexIF::TimeoutType::WAITING,
lockTimeout);
return commitWithoutLock();
}

View File

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

View File

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

View File

@ -85,7 +85,7 @@ ReturnValue_t TmTcUnixUdpBridge::sendTm(const uint8_t *data, size_t dataLen) {
}
void TmTcUnixUdpBridge::checkAndSetClientAddress(sockaddr_in newAddress) {
MutexHelper lock(mutex, 10);
MutexHelper lock(mutex, MutexIF::TimeoutType::WAITING, 10);
// char ipAddress [15];
// 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>
inline ReturnValue_t PoolManager<NUMBER_OF_POOLS>::reserveSpace(
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,
address,ignoreFault);
return status;
@ -33,7 +34,8 @@ inline ReturnValue_t PoolManager<NUMBER_OF_POOLS>::deleteData(
// debug << "PoolManager( " << translateObject(getObjectId()) <<
// " )::deleteData from store " << packet_id.pool_index <<
// ". 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);
return status;
}
@ -41,7 +43,8 @@ inline ReturnValue_t PoolManager<NUMBER_OF_POOLS>::deleteData(
template<uint8_t NUMBER_OF_POOLS>
inline ReturnValue_t PoolManager<NUMBER_OF_POOLS>::deleteData(uint8_t* buffer,
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,
size, storeId);
return status;