        -:    0:Source:../../../os/rt/include/chregistry.h
        -:    0:Programs:15
        -:    1:/*
        -:    2:    ChibiOS - Copyright (C) 2006..2016 Giovanni Di Sirio.
        -:    3:
        -:    4:    This file is part of ChibiOS.
        -:    5:
        -:    6:    ChibiOS is free software; you can redistribute it and/or modify
        -:    7:    it under the terms of the GNU General Public License as published by
        -:    8:    the Free Software Foundation; either version 3 of the License, or
        -:    9:    (at your option) any later version.
        -:   10:
        -:   11:    ChibiOS is distributed in the hope that it will be useful,
        -:   12:    but WITHOUT ANY WARRANTY; without even the implied warranty of
        -:   13:    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        -:   14:    GNU General Public License for more details.
        -:   15:
        -:   16:    You should have received a copy of the GNU General Public License
        -:   17:    along with this program.  If not, see <http://www.gnu.org/licenses/>.
        -:   18:*/
        -:   19:
        -:   20:/**
        -:   21: * @file    chregistry.h
        -:   22: * @brief   Threads registry macros and structures.
        -:   23: *
        -:   24: * @addtogroup registry
        -:   25: * @{
        -:   26: */
        -:   27:
        -:   28:#ifndef CHREGISTRY_H
        -:   29:#define CHREGISTRY_H
        -:   30:
        -:   31:#if (CH_CFG_USE_REGISTRY == TRUE) || defined(__DOXYGEN__)
        -:   32:
        -:   33:/*===========================================================================*/
        -:   34:/* Module constants.                                                         */
        -:   35:/*===========================================================================*/
        -:   36:
        -:   37:/*===========================================================================*/
        -:   38:/* Module pre-compile time settings.                                         */
        -:   39:/*===========================================================================*/
        -:   40:
        -:   41:/*===========================================================================*/
        -:   42:/* Derived constants and error checks.                                       */
        -:   43:/*===========================================================================*/
        -:   44:
        -:   45:/*===========================================================================*/
        -:   46:/* Module data structures and types.                                         */
        -:   47:/*===========================================================================*/
        -:   48:
        -:   49:/**
        -:   50: * @brief   ChibiOS/RT memory signature record.
        -:   51: */
        -:   52:typedef struct {
        -:   53:  char      identifier[4];          /**< @brief Always set to "main".       */
        -:   54:  uint8_t   zero;                   /**< @brief Must be zero.               */
        -:   55:  uint8_t   size;                   /**< @brief Size of this structure.     */
        -:   56:  uint16_t  version;                /**< @brief Encoded ChibiOS/RT version. */
        -:   57:  uint8_t   ptrsize;                /**< @brief Size of a pointer.          */
        -:   58:  uint8_t   timesize;               /**< @brief Size of a @p systime_t.     */
        -:   59:  uint8_t   threadsize;             /**< @brief Size of a @p thread_t.      */
        -:   60:  uint8_t   off_prio;               /**< @brief Offset of @p prio field.    */
        -:   61:  uint8_t   off_ctx;                /**< @brief Offset of @p ctx field.     */
        -:   62:  uint8_t   off_newer;              /**< @brief Offset of @p newer field.   */
        -:   63:  uint8_t   off_older;              /**< @brief Offset of @p older field.   */
        -:   64:  uint8_t   off_name;               /**< @brief Offset of @p name field.    */
        -:   65:  uint8_t   off_stklimit;           /**< @brief Offset of @p stklimit field.*/
        -:   66:  uint8_t   off_state;              /**< @brief Offset of @p state field.   */
        -:   67:  uint8_t   off_flags;              /**< @brief Offset of @p flags field.   */
        -:   68:  uint8_t   off_refs;               /**< @brief Offset of @p refs field.    */
        -:   69:  uint8_t   off_preempt;            /**< @brief Offset of @p preempt field. */
        -:   70:  uint8_t   off_time;               /**< @brief Offset of @p time field.    */
        -:   71:} chdebug_t;
        -:   72:
        -:   73:/*===========================================================================*/
        -:   74:/* Module macros.                                                            */
        -:   75:/*===========================================================================*/
        -:   76:
        -:   77:/**
        -:   78: * @brief   Removes a thread from the registry list.
        -:   79: * @note    This macro is not meant for use in application code.
        -:   80: *
        -:   81: * @param[in] tp        thread to remove from the registry
        -:   82: */
        -:   83:#define REG_REMOVE(tp) {                                                    \
        -:   84:  (tp)->older->newer = (tp)->newer;                                         \
        -:   85:  (tp)->newer->older = (tp)->older;                                         \
        -:   86:}
        -:   87:
        -:   88:/**
        -:   89: * @brief   Adds a thread to the registry list.
        -:   90: * @note    This macro is not meant for use in application code.
        -:   91: *
        -:   92: * @param[in] tp        thread to add to the registry
        -:   93: */
        -:   94:#define REG_INSERT(tp) {                                                    \
        -:   95:  (tp)->newer = (thread_t *)&ch.rlist;                                      \
        -:   96:  (tp)->older = ch.rlist.older;                                           \
        -:   97:  (tp)->older->newer = (tp);                                                \
        -:   98:  ch.rlist.older = (tp);                                                  \
        -:   99:}
        -:  100:
        -:  101:/*===========================================================================*/
        -:  102:/* External declarations.                                                    */
        -:  103:/*===========================================================================*/
        -:  104:
        -:  105:#ifdef __cplusplus
        -:  106:extern "C" {
        -:  107:#endif
        -:  108:  extern ROMCONST chdebug_t ch_debug;
        -:  109:  thread_t *chRegFirstThread(void);
        -:  110:  thread_t *chRegNextThread(thread_t *tp);
        -:  111:  thread_t *chRegFindThreadByName(const char *name);
        -:  112:  thread_t *chRegFindThreadByPointer(thread_t *tp);
        -:  113:  thread_t *chRegFindThreadByWorkingArea(stkalign_t *wa);
        -:  114:#ifdef __cplusplus
        -:  115:}
        -:  116:#endif
        -:  117:
        -:  118:#endif /* CH_CFG_USE_REGISTRY == TRUE */
        -:  119:
        -:  120:/*===========================================================================*/
        -:  121:/* Module inline functions.                                                  */
        -:  122:/*===========================================================================*/
        -:  123:
        -:  124:/**
        -:  125: * @brief   Sets the current thread name.
        -:  126: * @pre     This function only stores the pointer to the name if the option
        -:  127: *          @p CH_CFG_USE_REGISTRY is enabled else no action is performed.
        -:  128: *
        -:  129: * @param[in] name      thread name as a zero terminated string
        -:  130: *
        -:  131: * @api
        -:  132: */
        -:  133:static inline void chRegSetThreadName(const char *name) {
        -:  134:
        -:  135:#if CH_CFG_USE_REGISTRY == TRUE
        -:  136:  ch.rlist.current->name = name;
        -:  137:#else
        -:  138:  (void)name;
        -:  139:#endif
        -:  140:}
        -:  141:
        -:  142:/**
        -:  143: * @brief   Returns the name of the specified thread.
        -:  144: * @pre     This function only returns the pointer to the name if the option
        -:  145: *          @p CH_CFG_USE_REGISTRY is enabled else @p NULL is returned.
        -:  146: *
        -:  147: * @param[in] tp        pointer to the thread
        -:  148: *
        -:  149: * @return              Thread name as a zero terminated string.
        -:  150: * @retval NULL         if the thread name has not been set.
        -:  151: *
        -:  152: */
function chRegGetThreadNameX called 0 returned 0% blocks executed 0%
    #####:  153:static inline const char *chRegGetThreadNameX(thread_t *tp) {
        -:  154:
        -:  155:#if CH_CFG_USE_REGISTRY == TRUE
    #####:  156:  return tp->name;
unconditional  0 never executed
        -:  157:#else
        -:  158:  (void)tp;
        -:  159:  return NULL;
        -:  160:#endif
        -:  161:}
        -:  162:
        -:  163:/**
        -:  164: * @brief   Changes the name of the specified thread.
        -:  165: * @pre     This function only stores the pointer to the name if the option
        -:  166: *          @p CH_CFG_USE_REGISTRY is enabled else no action is performed.
        -:  167: *
        -:  168: * @param[in] tp        pointer to the thread
        -:  169: * @param[in] name      thread name as a zero terminated string
        -:  170: *
        -:  171: * @xclass
        -:  172: */
        -:  173:static inline void chRegSetThreadNameX(thread_t *tp, const char *name) {
        -:  174:
        -:  175:#if CH_CFG_USE_REGISTRY == TRUE
        -:  176:  tp->name = name;
        -:  177:#else
        -:  178:  (void)tp;
        -:  179:  (void)name;
        -:  180:#endif
        -:  181:}
        -:  182:
        -:  183:#endif /* CHREGISTRY_H */
        -:  184:
        -:  185:/** @} */
