        -:    0:Source:../../../os/rt/include/chmempools.h
        -:    0:Programs:17
        -:    1:/*
        -:    2:    ChibiOS - Copyright (C) 2006..2015 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    chmempools.h
        -:   22: * @brief   Memory Pools macros and structures.
        -:   23: *
        -:   24: * @addtogroup pools
        -:   25: * @{
        -:   26: */
        -:   27:
        -:   28:#ifndef _CHMEMPOOLS_H_
        -:   29:#define _CHMEMPOOLS_H_
        -:   30:
        -:   31:#if (CH_CFG_USE_MEMPOOLS == 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:#if CH_CFG_USE_MEMCORE == FALSE
        -:   46:#error "CH_CFG_USE_MEMPOOLS requires CH_CFG_USE_MEMCORE"
        -:   47:#endif
        -:   48:
        -:   49:/*===========================================================================*/
        -:   50:/* Module data structures and types.                                         */
        -:   51:/*===========================================================================*/
        -:   52:
        -:   53:/**
        -:   54: * @brief   Memory pool free object header.
        -:   55: */
        -:   56:struct pool_header {
        -:   57:  struct pool_header    *ph_next;       /**< @brief Pointer to the next pool
        -:   58:                                                    header in the list.     */
        -:   59:};
        -:   60:
        -:   61:/**
        -:   62: * @brief   Memory pool descriptor.
        -:   63: */
        -:   64:typedef struct {
        -:   65:  struct pool_header    *mp_next;       /**< @brief Pointer to the header.  */
        -:   66:  size_t                mp_object_size; /**< @brief Memory pool objects
        -:   67:                                                    size.                   */
        -:   68:  memgetfunc_t          mp_provider;    /**< @brief Memory blocks provider
        -:   69:                                                    for this pool.          */
        -:   70:} memory_pool_t;
        -:   71:
        -:   72:/*===========================================================================*/
        -:   73:/* Module macros.                                                            */
        -:   74:/*===========================================================================*/
        -:   75:
        -:   76:/**
        -:   77: * @brief   Data part of a static memory pool initializer.
        -:   78: * @details This macro should be used when statically initializing a
        -:   79: *          memory pool that is part of a bigger structure.
        -:   80: *
        -:   81: * @param[in] name      the name of the memory pool variable
        -:   82: * @param[in] size      size of the memory pool contained objects
        -:   83: * @param[in] provider  memory provider function for the memory pool
        -:   84: */
        -:   85:#define _MEMORYPOOL_DATA(name, size, provider)                              \
        -:   86:  {NULL, size, provider}
        -:   87:
        -:   88:/**
        -:   89: * @brief Static memory pool initializer in hungry mode.
        -:   90: * @details Statically initialized memory pools require no explicit
        -:   91: *          initialization using @p chPoolInit().
        -:   92: *
        -:   93: * @param[in] name the name of the memory pool variable
        -:   94: * @param[in] size size of the memory pool contained objects
        -:   95: * @param[in] provider memory provider function for the memory pool or @p NULL
        -:   96: *                     if the pool is not allowed to grow automatically
        -:   97: */
        -:   98:#define MEMORYPOOL_DECL(name, size, provider)                               \
        -:   99:  memory_pool_t name = _MEMORYPOOL_DATA(name, size, provider)
        -:  100:
        -:  101:/*===========================================================================*/
        -:  102:/* External declarations.                                                    */
        -:  103:/*===========================================================================*/
        -:  104:
        -:  105:#ifdef __cplusplus
        -:  106:extern "C" {
        -:  107:#endif
        -:  108:  void chPoolObjectInit(memory_pool_t *mp, size_t size, memgetfunc_t provider);
        -:  109:  void chPoolLoadArray(memory_pool_t *mp, void *p, size_t n);
        -:  110:  void *chPoolAllocI(memory_pool_t *mp);
        -:  111:  void *chPoolAlloc(memory_pool_t *mp);
        -:  112:  void chPoolFreeI(memory_pool_t *mp, void *objp);
        -:  113:  void chPoolFree(memory_pool_t *mp, void *objp);
        -:  114:#ifdef __cplusplus
        -:  115:}
        -:  116:#endif
        -:  117:
        -:  118:/*===========================================================================*/
        -:  119:/* Module inline functions.                                                  */
        -:  120:/*===========================================================================*/
        -:  121:
        -:  122:/**
        -:  123: * @brief   Adds an object to a memory pool.
        -:  124: * @pre     The memory pool must be already been initialized.
        -:  125: * @pre     The added object must be of the right size for the specified
        -:  126: *          memory pool.
        -:  127: * @pre     The added object must be memory aligned to the size of
        -:  128: *          @p stkalign_t type.
        -:  129: * @note    This function is just an alias for @p chPoolFree() and has been
        -:  130: *          added for clarity.
        -:  131: *
        -:  132: * @param[in] mp        pointer to a @p memory_pool_t structure
        -:  133: * @param[in] objp      the pointer to the object to be added
        -:  134: *
        -:  135: * @api
        -:  136: */
function chPoolAdd called 5 returned 100% blocks executed 100%
        5:  137:static inline void chPoolAdd(memory_pool_t *mp, void *objp) {
        -:  138:
        5:  139:  chPoolFree(mp, objp);
call    0 returned 100%
        5:  140:}
        -:  141:
        -:  142:/**
        -:  143: * @brief   Adds an object to a memory pool.
        -:  144: * @pre     The memory pool must be already been initialized.
        -:  145: * @pre     The added object must be of the right size for the specified
        -:  146: *          memory pool.
        -:  147: * @pre     The added object must be memory aligned to the size of
        -:  148: *          @p stkalign_t type.
        -:  149: * @note    This function is just an alias for @p chPoolFree() and has been
        -:  150: *          added for clarity.
        -:  151: *
        -:  152: * @param[in] mp        pointer to a @p memory_pool_t structure
        -:  153: * @param[in] objp      the pointer to the object to be added
        -:  154: *
        -:  155: * @iclass
        -:  156: */
        -:  157:static inline void chPoolAddI(memory_pool_t *mp, void *objp) {
        -:  158:
        -:  159:  chDbgCheckClassI();
        -:  160:
        -:  161:  chPoolFreeI(mp, objp);
        -:  162:}
        -:  163:
        -:  164:#endif /* CH_CFG_USE_MEMPOOLS == TRUE */
        -:  165:
        -:  166:#endif /* _CHMEMPOOLS_H_ */
        -:  167:
        -:  168:/** @} */
