2020-09-05 21:19:53 +02:00
|
|
|
#include "Mutex.h"
|
2020-09-05 20:18:52 +02:00
|
|
|
#include "../../serviceinterface/ServiceInterfaceStream.h"
|
|
|
|
|
2020-09-05 21:19:53 +02:00
|
|
|
Mutex::Mutex() {}
|
2020-09-05 20:18:52 +02:00
|
|
|
|
2020-09-05 21:19:53 +02:00
|
|
|
ReturnValue_t Mutex::lockMutex(TimeoutType timeoutType, uint32_t timeoutMs) {
|
2021-01-06 21:14:23 +01:00
|
|
|
if(timeoutType == TimeoutType::BLOCKING) {
|
2020-09-05 20:18:52 +02:00
|
|
|
mutex.lock();
|
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
|
|
|
}
|
2021-01-06 21:14:23 +01:00
|
|
|
else if(timeoutType == TimeoutType::POLLING) {
|
2020-09-05 20:18:52 +02:00
|
|
|
if(mutex.try_lock()) {
|
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
|
|
|
}
|
|
|
|
}
|
2021-01-06 21:14:23 +01:00
|
|
|
else if(timeoutType == TimeoutType::WAITING){
|
2020-09-05 20:18:52 +02:00
|
|
|
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;
|
|
|
|
}
|