OSTaskDelHook

Description

This function is called by OSTaskDel() after the task is removed from the ready list or any pend list.

You can use this hook to deallocate storage assigned to the task.

OSTaskDelHook() is part of the CPU port code and this function must not be called by the application code. OSTaskDelHook() is actually used by the µC/OS-III port developer.

Files

os.h/os_cpu_c.c and os_app_hooks.c

Prototype

void  OSTaskDelHook (OS_TCB  *p_tcb)

Arguments

p_tcb

is a pointer to the TCB of the task being created. Note that the OS_TCB has been validated by OSTaskDel() and is guaranteed to not be a NULL pointer when OSTaskDelHook() is called.

Returned Value

None

Required Configuration

OS_CFG_APP_HOOKS_EN must be enabled in os_cfg.h. Refer to µC-OS-III Configuration Manual.

Callers

OSTaskDel().

Notes/Warnings

  1. Do not call this function from the application.

Example Usage

The code below calls an application-specific hook that the application programmer can define. The user can simply set the value of OS_AppTaskDelHookPtr to point to the desired hook function. OSTaskDel() calls OSTaskDelHook() which in turns calls App_OS_TaskDelHook() through OS_AppTaskDelHookPtr. As can be seen, when called, the application hook is passed the address of the OS_TCB of the task being deleted.

OSTaskDelHook() example usage
          void  App_OS_TaskDelHook (OS_TCB *p_tcb)                  /* os_app_hooks.c        */
          {
              /* Your code goes here! */
          }
           
           
          void App_OS_SetAllHooks (void)                            /* os_app_hooks.c         */
          {
              CPU_SR_ALLOC();
           
              CPU_CRITICAL_ENTER();
              :
              OS_AppTaskDelHookPtr = App_OS_TaskDelHook;
              :
              CPU_CRITICAL_EXIT();
          }
           
           
           
          void  OSTaskDelHook (OS_TCB *p_tcb)                        /* os_cpu_c.c            */
          {
          #if OS_CFG_APP_HOOKS_EN > 0u
              if (OS_AppTaskDelHookPtr != (OS_APP_HOOK_TCB)0) {      /* Call application hook */
                  (*OS_AppTaskDelHookPtr)(p_tcb);
              }
          #endif
          }