implemented new mutex interface
This commit is contained in:
@ -8,7 +8,8 @@ class MutexHelper {
|
||||
public:
|
||||
MutexHelper(MutexIF* mutex, uint32_t timeoutMs) :
|
||||
internalMutex(mutex) {
|
||||
ReturnValue_t status = mutex->lockMutex(timeoutMs);
|
||||
ReturnValue_t status = mutex->lockMutex(MutexIF::TimeoutType::WAITING,
|
||||
timeoutMs);
|
||||
if(status == MutexIF::MUTEX_TIMEOUT) {
|
||||
sif::error << "MutexHelper: Lock of mutex failed with timeout of "
|
||||
<< timeoutMs << " milliseconds!" << std::endl;
|
||||
|
@ -12,20 +12,25 @@
|
||||
*/
|
||||
class MutexIF {
|
||||
public:
|
||||
/**
|
||||
* @brief Timeout value used for polling lock attempt.
|
||||
* @details
|
||||
* If the lock is not successfull, MUTEX_TIMEOUT will be returned
|
||||
* immediately. Value needs to be defined in implementation.
|
||||
*/
|
||||
static const uint32_t POLLING;
|
||||
/**
|
||||
* @brief Timeout value used for permanent blocking lock attempt.
|
||||
* @details
|
||||
* The task will be blocked (indefinitely) until the mutex is unlocked.
|
||||
* Value needs to be defined in implementation.
|
||||
*/
|
||||
static const uint32_t BLOCKING;
|
||||
/**
|
||||
* Different types of timeout for the mutex lock.
|
||||
*/
|
||||
enum TimeoutType {
|
||||
POLLING, //!< If mutex is not available, return immediately
|
||||
WAITING, //!< Wait a specified time for the mutex to become available
|
||||
BLOCKING //!< Block indefinitely until the mutex becomes available.
|
||||
};
|
||||
|
||||
/**
|
||||
* Lock the mutex.
|
||||
* @param timeoutType
|
||||
* @param timeoutMs
|
||||
* This value will only be used for TimeoutType::WAIT
|
||||
* @return
|
||||
*/
|
||||
virtual ReturnValue_t lockMutex(TimeoutType timeoutType =
|
||||
TimeoutType::BLOCKING, uint32_t timeoutMs = 0) = 0;
|
||||
virtual ReturnValue_t unlockMutex() = 0;
|
||||
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::MUTEX_IF;
|
||||
/**
|
||||
@ -77,9 +82,7 @@ public:
|
||||
*/
|
||||
static const ReturnValue_t MUTEX_DESTROYED_WHILE_WAITING = MAKE_RETURN_CODE(12);
|
||||
|
||||
virtual ~MutexIF() {}
|
||||
virtual ReturnValue_t lockMutex(uint32_t timeoutMs) = 0;
|
||||
virtual ReturnValue_t unlockMutex() = 0;
|
||||
virtual ~MutexIF() {}
|
||||
};
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user