Versions Compared

Key

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

...

Assigns a “destructor function” to a TLS (thread-local storage) ID. All destructor functions that have been set for the TLS IDs will be called when the task is deleted. Destructor functions are thus common to all tasks. Note that a destructor function must be declared as follows:

Code Block
void  MyDestructFunction (OS_TCB     *p_tcb,
                          OS_TLS_ID   id,
                          OS_TLS      value);

When the destructor function is called, it will be passed the address of the OS_TCB for the task being deleted, the TLS ID that is being destructed and the value of p_tcb->TLS_Tbl[id] which was set by OS_TLS_SetValue().

Files

os.h/os_tls.c

Prototype

Code Block
void  OS_TLS_SetDestruct (OS_TLS_ID             id,
                          OS_TLS_DESTRUCT_PTR   p_destruct,
                          OS_ERR               *p_err)

Arguments

id

is the TLS ID for which you want to set the destructor function for.

...

  1. You can only call OS_TLS_SetDestruct() once for each TLS ID.
  2. Note that not all implementations of os_tls.c will have destructors for TLS IDs.

Example Usage

Code Block
titleOS_TLS_SetDestruct() example usage
          void  MyDestructFunction (OS_TCB    *p_tcb,
                                    OS_TLS_ID  id,
                                    OS_TLS     value);
           
          OS_TLS_ID   MyTLS_ID;
           
           
          void  main (void)
          {
              OS_ERR   err;
           
           
              :
              OSInit(&err);
              :
              :
              MyTLS_ID = OS_TLS_GetID(&err);  /* Obtain the next available TLS ID       */
              OS_TLS_SetDestruct((OS_TLS_ID)MyTLS_ID,
                                 (OS_TLS_DESTRUCT_PTR)MyTLS_Destructor,
                                 (OS_ERR *)&err);
              /* Check "err" */
              :
              :
          }
           
           
          void  MyDestructFunction (OS_TCB    *p_tcb,
                                    OS_TLS_ID  id,
                                    OS_TLS     value)
          {
              /* Note that 'value' is typically a 'void *' that points to storage area for the TLS */
          }