mutex update

This commit is contained in:
Robin Müller 2021-07-19 15:07:56 +02:00
parent 08364e2dca
commit 7849b8e391
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC
1 changed files with 32 additions and 0 deletions

32
src/osal/host/Mutex.cpp Normal file
View File

@ -0,0 +1,32 @@
#include "Mutex.h"
#include "fsfw/serviceinterface/ServiceInterface.h"
Mutex::Mutex() {}
ReturnValue_t Mutex::lockMutex(TimeoutType timeoutType, uint32_t timeoutMs) {
if(timeoutType == TimeoutType::BLOCKING) {
mutex.lock();
return HasReturnvaluesIF::RETURN_OK;
}
else if(timeoutType == TimeoutType::POLLING) {
if(mutex.try_lock()) {
return HasReturnvaluesIF::RETURN_OK;
}
}
else if(timeoutType == TimeoutType::WAITING){
auto chronoMs = std::chrono::milliseconds(timeoutMs);
if(mutex.try_lock_for(chronoMs)) {
return HasReturnvaluesIF::RETURN_OK;
}
}
return MutexIF::MUTEX_TIMEOUT;
}
ReturnValue_t Mutex::unlockMutex() {
mutex.unlock();
return HasReturnvaluesIF::RETURN_OK;
}
std::timed_mutex* Mutex::getMutexHandle() {
return &mutex;
}