Versions Compared

Key

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

File

Called from

Code enabled by

os_mutex.c

Task only

OS_CFG_MUTEX_EN and OS_CFG_MUTEX_DEL_EN

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.

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.

...

If OS_CFG_CALLED_FROM_ISR_CHK_EN set to 1 in DEF_ENABLED in os_cfg.h: if attempting to delete a mutex from an ISR.

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

If OS_CFG_ARG_CHK_EN is set to 1 in DEF_ENABLED in os_cfg.h: if p_mutex is a NULL pointer.

...

If OS_CFG_OBJ_TYPE_CHK_EN is set to 1 in DEF_ENABLED in os_cfg.h: if p_mutex is not pointing to a mutex.

OS_ERR_OPT_INVALID

If OS_CFG_ARG_CHK_EN is set to DEF_ENABLED in os_cfg.h: if a valid option is not specified.If the user does not specify one of the two options mentioned in the opt argument

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

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. 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
titleOSMutexDel() example usage
          OS_MUTEX  DispMutex;
           
           
          void Task (void *p_arg)
          {
              OS_ERR      err;
              OS_OBJ_QTY  qty;
           
           
              (void)&p_arg;
              while (DEF_ON) {
                  :
                  :
                  qty = OSMutexDel(&DispMutex,
                                    OS_OPT_DEL_ALWAYS,
                                   &err);
                  /* Check "err" */
                  :
                  :
              }
          }