...
Description
Deletes a mutex. This function should be used with care because multiple tasks may rely on the presence of the mutex. Generally makes all pending tasks ready to run and clears the mutex data. It also sets the owning task's priority to the highest priority in the owner's task mutex group or its base priority, whichever is higher. Generally speaking, before deleting a mutex, first delete all the tasks that access the mutex. However, as a general ruleguideline, do not delete kernel objects at run-time. Anchor
Files
os.h/os_mutex.c
Prototype
Code Block |
---|
OS_OBJ_QTY OSMutexDel (OS_MUTEX *p_mutex,
OS_OPT opt,
OS_ERR *p_err) |
Arguments
p_mutex
is a pointer to the mutex to delete.
...
opt
Anchor
specifies whether to delete the mutex only if there are no pending tasks (OS_OPT_DEL_NO_PEND
), or whether to always delete the mutex regardless of whether tasks are pending or not (OS_OPT_DEL_ALWAYS
). In this case, all pending tasks are readied.
...
p_err
anchoris a pointer to a variable that is used to hold an error code:
...
class | WebWorks_Indent_1 |
---|
...
OS_ERR_NONE
...
class | WebWorks_Indent_2 |
---|
...
If the call is successful and the mutex has been deleted.
...
class | WebWorks_Indent_1 |
---|
...
OS_ERR_DEL_ISR
...
class | WebWorks_Indent_2 |
---|
...
If OS_CFG_CALLED_FROM_ISR_CHK_EN
set to
...
DEF_ENABLED
in os_cfg.h
: if attempting to delete a mutex from an ISR.
...
class | WebWorks_Indent_1 |
---|
...
OS_ERR_ILLEGAL_DEL_RUN_TIME
If OS_SAFETY_CRITICAL_IEC61508
is defined: you are trying to delete the mutex after you called OSStart()
.
OS_ERR_OBJ_PTR_NULL
...
class | WebWorks_Indent_2 |
---|
...
If OS_CFG_ARG_CHK_EN
is set to
...
DEF_ENABLED
in os_cfg.h
: if p_mutex
is a NULL
pointer.
...
class | WebWorks_Indent_1 |
---|
...
OS_ERR_OBJ_TYPE
...
class | WebWorks_Indent_2 |
---|
...
If OS_CFG_OBJ_TYPE_CHK_EN
is set to
...
DEF_ENABLED
in os_cfg.h
: if p_mutex
is not pointing to a mutex.
...
class | WebWorks_Indent_1 |
---|
...
...
OS_ERR_OPT_INVALID
...
class | WebWorks_Indent_2 |
---|
...
class | WebWorks_Indent_1 |
---|
...
If OS_CFG_ARG_CHK_EN
is set to DEF_ENABLED
in os_cfg.h
: if a valid option is not specified.
OS_ERR_OS_NOT_RUNNING
If OS_CFG_INVALID_OS_CALLS_CHK_EN
is set to DEF_ENABLED
in os_cfg.h
: If µC/OS-III is not running yet.
OS_ERR_TASK_WAITING
...
class | WebWorks_Indent_2 |
---|
...
If one or more task are waiting on the mutex and OS_OPT_DEL_NO_PEND
is specified.
...
Returned Value
...
The number of tasks that were waiting for the mutex and 0 if an error occurred. Anchor
Required Configuration
OS_CFG_MUTEX_EN
and OS_CFG_MUTEX_DEL_EN
must be enabled in os_cfg.h
. Refer to µC-OS-III Configuration Manual.
Callers
Application.
Notes/Warnings
...
- Use this call with care as other tasks may expect the presence of the mutex.
...
Example Usage
...
Code Block |
---|
...
HTML Table | |||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
summary | |||||||||||||||||||||||||||||||||||||||||||||||
class | Code_Listing | ||||||||||||||||||||||||||||||||||||||||||||||
Table Row (tr) | |||||||||||||||||||||||||||||||||||||||||||||||
Table Cell (td) | |||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||
Anchor | 1050726 | 1050726 | OS_MUTEX DispMutex;|||||||||||||||||||||||||||||||||||||||||||||
Anchor | 1050727 | 1050727 | |||||||||||||||||||||||||||||||||||||||||||||
Anchor | 1050728 | 1050728 | |||||||||||||||||||||||||||||||||||||||||||||
Anchor | 1050729 | 1050729 | void Task (void *p_arg)|||||||||||||||||||||||||||||||||||||||||||||
Anchor | 1050730 | 1050730 | {|||||||||||||||||||||||||||||||||||||||||||||
Anchor | 1050731 | 1050731 | OS_ERR err;|||||||||||||||||||||||||||||||||||||||||||||
Anchor | 1050732 | 1050732 | |||||||||||||||||||||||||||||||||||||||||||||
Anchor | 1050733 | 1050733 | |||||||||||||||||||||||||||||||||||||||||||||
Anchor | 1050734 | 1050734 |
| ||||||||||||||||||||||||||||||||||||||||||||
OS_MUTEX DispMutex; void Task (void *p_arg) { OS_ERR err; OS_OBJ_QTY qty; (void)&p_arg; Anchor | | 1050735 | 1050735 | while||||||||||||||||||||||||||||||||||||||||||||
Anchor | 1050736 | 1050736 | :|||||||||||||||||||||||||||||||||||||||||||||
Anchor | 1050737 | 1050737 | :|||||||||||||||||||||||||||||||||||||||||||||
Anchor | 1050738 | 1050738 | OSMutexDel(&DispMutex,|||||||||||||||||||||||||||||||||||||||||||||
Anchor | 1050739 | 1050739 | |||||||||||||||||||||||||||||||||||||||||||||
Anchor | 1050740 | 1050740 | &err);|||||||||||||||||||||||||||||||||||||||||||||
Anchor | 1050741 | 1050741 | /* Check “err” */|||||||||||||||||||||||||||||||||||||||||||||
Anchor | 1050742 | 1050742 | :|||||||||||||||||||||||||||||||||||||||||||||
Anchor | 1050743 | 1050743 | :|||||||||||||||||||||||||||||||||||||||||||||
Anchor | 1050744 | 1050744 | }|||||||||||||||||||||||||||||||||||||||||||||
Anchor | 1050745 | 1050745 | }|||||||||||||||||||||||||||||||||||||||||||||
Table Row (tr) | |||||||||||||||||||||||||||||||||||||||||||||||
Table Row (tr) | |||||||||||||||||||||||||||||||||||||||||||||||
Table Row (tr) | |||||||||||||||||||||||||||||||||||||||||||||||
Table Row (tr) | |||||||||||||||||||||||||||||||||||||||||||||||
Table Row (tr) | |||||||||||||||||||||||||||||||||||||||||||||||
Table Row (tr) | |||||||||||||||||||||||||||||||||||||||||||||||
Table Row (tr) | |||||||||||||||||||||||||||||||||||||||||||||||
Table Row (tr) | |||||||||||||||||||||||||||||||||||||||||||||||
Table Row (tr) | |||||||||||||||||||||||||||||||||||||||||||||||
Table Row (tr) | |||||||||||||||||||||||||||||||||||||||||||||||
Table Row (tr) | |||||||||||||||||||||||||||||||||||||||||||||||
Table Row (tr) | |||||||||||||||||||||||||||||||||||||||||||||||
Table Row (tr) | |||||||||||||||||||||||||||||||||||||||||||||||
Table Row (tr) |