1.4.4.11 OSAL_MUTEX_Lock Function

1.4.4.11 C

OSAL_RESULT OSAL_MUTEX_Lock(OSAL_MUTEX_HANDLE_TYPE* mutexID, uint16_t waitMS)

1.4.4.11 Summary

Locks a mutex.

1.4.4.11 Description

This function locks a mutex, waiting for the specified time-out. If it cannot be obtained or the time-out period elapses 'false' is returned.

1.4.4.11 Precondition

Mutex must have been created.

1.4.4.11 Parameters

ParametersDescription
mutexIDPointer to the mutex handle
waitMSTime-out value in milliseconds:
  • 0 - do not wait return immediately
  • OSAL_WAIT_FOREVER - wait until mutex is obtained before returning
  • Other values - time-out delay

1.4.4.11 Returns

OSAL_RESULT_TRUE - Mutex successfully obtained.

OSAL_RESULT_FALSE - Mutex failed to be obtained or time-out occurred.

1.4.4.11 Example

...
if (OSAL_MUTEX_Lock(&mutexData, 1000) == OSAL_RESULT_TRUE)
{
    // manipulate the shared data
    ...
    
    // unlock the mutex
    OSAL_MUTEX_Unlock(&mutexData);
}

1.4.4.11 Remarks

None.