2021-06-08 13:35:49 +02:00
|
|
|
#include "MutexExample.h"
|
|
|
|
|
|
|
|
#include <fsfw/ipc/MutexFactory.h>
|
2022-05-09 00:09:39 +02:00
|
|
|
#include <fsfw/serviceinterface.h>
|
2021-06-08 13:35:49 +02:00
|
|
|
|
2022-05-05 20:55:28 +02:00
|
|
|
void MutexExample::example() {
|
2022-05-22 15:30:08 +02:00
|
|
|
MutexIF *mutex = MutexFactory::instance()->createMutex();
|
|
|
|
MutexIF *mutex2 = MutexFactory::instance()->createMutex();
|
2021-06-08 13:35:49 +02:00
|
|
|
|
2022-05-22 15:30:08 +02:00
|
|
|
ReturnValue_t result =
|
|
|
|
mutex->lockMutex(MutexIF::TimeoutType::WAITING, 2 * 60 * 1000);
|
2022-05-05 20:55:28 +02:00
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
2022-05-09 01:14:53 +02:00
|
|
|
FSFW_LOGET("MutexExample::example: Lock Failed with {}\n", result);
|
2022-05-05 20:55:28 +02:00
|
|
|
}
|
2021-06-08 13:35:49 +02:00
|
|
|
|
2022-05-05 20:55:28 +02:00
|
|
|
result = mutex2->lockMutex(MutexIF::TimeoutType::BLOCKING);
|
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
2022-05-09 01:14:53 +02:00
|
|
|
FSFW_LOGET("MutexExample::example: Lock Failed with {}\n", result);
|
2022-05-05 20:55:28 +02:00
|
|
|
}
|
2021-06-08 13:35:49 +02:00
|
|
|
|
2022-05-05 20:55:28 +02:00
|
|
|
result = mutex->unlockMutex();
|
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
2022-05-09 01:14:53 +02:00
|
|
|
FSFW_LOGET("MutexExample::example: Unlock Failed with {}\n", result);
|
2022-05-05 20:55:28 +02:00
|
|
|
}
|
2021-06-08 13:35:49 +02:00
|
|
|
|
2022-05-05 20:55:28 +02:00
|
|
|
result = mutex2->unlockMutex();
|
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
2022-05-09 01:14:53 +02:00
|
|
|
FSFW_LOGET("MutexExample::example: Unlock Failed with {}\n", result);
|
2022-05-05 20:55:28 +02:00
|
|
|
}
|
2021-06-08 13:35:49 +02:00
|
|
|
}
|