fsfw/src/fsfw/osal/host/Mutex.cpp

30 lines
807 B
C++
Raw Normal View History

2021-07-19 16:25:51 +02:00
#include "fsfw/osal/host/Mutex.h"
2022-02-02 10:29:30 +01:00
2022-05-09 01:14:23 +02:00
#include "fsfw/serviceinterface.h"
2021-07-19 15:07:56 +02:00
2022-05-09 01:14:23 +02:00
Mutex::Mutex() = default;
2021-07-19 15:07:56 +02:00
ReturnValue_t Mutex::lockMutex(TimeoutType timeoutType, uint32_t timeoutMs) {
2022-02-02 10:29:30 +01:00
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;
2021-07-19 15:07:56 +02:00
}
ReturnValue_t Mutex::unlockMutex() {
2022-02-02 10:29:30 +01:00
mutex.unlock();
return HasReturnvaluesIF::RETURN_OK;
2021-07-19 15:07:56 +02:00
}
2022-02-02 10:29:30 +01:00
std::timed_mutex* Mutex::getMutexHandle() { return &mutex; }