Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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. Anchor10012431001243 Arguments Anchor10012441001244 p_mutex Anchor10012451001245

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 Anchor10012471001247

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.

...

10012481001248p_erranchor10012491001249

is a pointer to a variable that is used to hold an error code:

...

classWebWorks_Indent_1

...

OS_ERR_NONE

...

classWebWorks_Indent_2

...

If the call is successful and the mutex has been deleted.

...

classWebWorks_Indent_1

...

OS_ERR_DEL_ISR

...

classWebWorks_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.

...

classWebWorks_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

...

classWebWorks_Indent_2

...

If OS_CFG_ARG_CHK_EN is set to

...

DEF_ENABLED in os_cfg.h: if p_mutex is a NULL pointer.

...

classWebWorks_Indent_1

...

OS_ERR_OBJ_TYPE

...

classWebWorks_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.

...

classWebWorks_Indent_1

...

...

OS_ERR_OPT_INVALID

...

classWebWorks_Indent_2

...

classWebWorks_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

...

classWebWorks_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. Anchor10507221050722. Zero either indicates an error or that no tasks were pending on the mutex.

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

...

  1. Use this call with care as other tasks may expect the presence of the mutex.

...

Example Usage

...

Code Block

...

OS_MUTEX DispMutex;     void Task (void *p_arg) { OS_ERR err;     while

              while (DEF_ON)
{ : : OSMutexDel(&DispMutex,
 {
                  :
                  :
                  qty = OSMutexDel(&DispMutex,
                                    OS_OPT_DEL_ALWAYS,
&err); /* Check “err” */ : : } }tr

                                   &err);
                  /* Check "err" */
                  :
                  :
              }
          }
HTML Table
summary
classCode_Listing
Table Row (tr)
Table Cell (td)
rowspan16
Anchor
10507261050726
Anchor
10507271050727
Anchor
10507281050728
Anchor
10507291050729
Anchor
10507301050730
Anchor
10507311050731
Anchor
10507321050732
Anchor
10507331050733
Anchor
10507341050734
titleOSMutexDel() example usage
          OS_MUTEX  DispMutex;
           
           
          void Task (void *p_arg)
          {
              OS_ERR      err;
              OS_OBJ_QTY  qty;
           
           
              (void)&p_arg;
Anchor
10507351050735
Anchor
10507361050736
Anchor
10507371050737
Anchor
10507381050738
Anchor
10507391050739
Anchor
10507401050740
Anchor
10507411050741
Anchor
10507421050742
Anchor
10507431050743
Anchor
10507441050744
Anchor
10507451050745
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)