Description
Acquire a mutual exclusion semaphore. If a task calls OSMutexPend() and the mutex is available, OSMutexPend() gives the mutex to the caller and returns to its caller. Note that nothing is actually given to the caller except that if p_err is set to OS_ERR_NONE, the caller can assume that it owns the mutex. However, if the mutex is already owned by another task, OSMutexPend()
places the calling task in the wait list for the mutex. The task waits until the task that owns the mutex releases the mutex and therefore the resource, or until the specified timeout expires. If the mutex is signaled before the timeout expires, µC/OS-III resumes the highest-priority task that is waiting for the mutex. Note that if the mutex is owned by a lower-priority task, OSMutexPend()
raises the priority of the task that owns the mutex to the same priority as the task requesting the mutex. The priority of the owner will be returned to its original priority when the owner releases the mutex (see OSMutexPost()
). OSMutexPend()
allows nesting. The same task can call OSMutexPend()
multiple times. However, the same task must then call OSMutexPost()
an equivalent number of times to release the mutex.
Files
os.h/os_mutex.c
Prototype
Arguments
p_mutex
is a pointer to the mutex.
...
If the mutex is not available within the specified timeout.
Returned Value
None
Required Configuration
OS_CFG_MUTEX_EN
must be enabled in os_cfg.h. Refer to uC-OS-III Configuration Manual
Callers
Application.
Notes/Warnings
Mutexes must be created before they are used.