rtems mutex update

This commit is contained in:
Robin Müller 2020-06-09 13:26:27 +02:00
parent 20abb810f2
commit b5567e8aae
2 changed files with 16 additions and 3 deletions

View File

@ -1,7 +1,7 @@
#include "Mutex.h" #include "Mutex.h"
#include <framework/serviceinterface/ServiceInterfaceStream.h> #include <framework/serviceinterface/ServiceInterfaceStream.h>
const uint32_t MutexIF::BLOCKING = RTEMS_NO_TIMEOUT; const uint32_t MutexIF::BLOCKING = RTEMS_WAIT;
const uint32_t MutexIF::POLLING = RTEMS_NO_WAIT; const uint32_t MutexIF::POLLING = RTEMS_NO_WAIT;
uint8_t Mutex::count = 0; uint8_t Mutex::count = 0;
@ -26,7 +26,20 @@ Mutex::~Mutex() {
} }
ReturnValue_t Mutex::lockMutex(uint32_t timeoutMs) { ReturnValue_t Mutex::lockMutex(uint32_t timeoutMs) {
rtems_status_code status = rtems_semaphore_obtain(mutexId, RTEMS_WAIT, timeoutMs); if(timeoutMs == MutexIF::BLOCKING) {
rtems_status_code status = rtems_semaphore_obtain(mutexId,
RTEMS_WAIT, timeoutMs);
}
else if(timeoutMs == MutexIF::POLLING) {
timeoutMs = RTEMS_NO_TIMEOUT;
rtems_status_code status = rtems_semaphore_obtain(mutexId,
RTEMS_NO_WAIT, timeoutMs);
}
else {
rtems_status_code status = rtems_semaphore_obtain(mutexId,
RTEMS_NO_WAIT, timeoutMs);
}
switch(status){ switch(status){
case RTEMS_SUCCESSFUL: case RTEMS_SUCCESSFUL:
//semaphore obtained successfully //semaphore obtained successfully

View File

@ -8,7 +8,7 @@ class Mutex : public MutexIF {
public: public:
Mutex(); Mutex();
~Mutex(); ~Mutex();
ReturnValue_t lockMutex(uint32_t timeoutMs); ReturnValue_t lockMutex(uint32_t timeoutMs = MutexIF::BLOCKING);
ReturnValue_t unlockMutex(); ReturnValue_t unlockMutex();
private: private:
rtems_id mutexId; rtems_id mutexId;