1.4.4.11 OSAL_MUTEX_Lock Function

C

OSAL_RESULT OSAL_MUTEX_Lock(OSAL_MUTEX_HANDLE_TYPE* mutexID, uint16_t waitMS)

Summary

Locks a mutex.

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.

Precondition

Mutex must have been created.

Parameters

ParamDescription
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

Returns

OSAL_RESULT_TRUE - Mutex successfully obtained

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

Example

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

Remarks

None.