Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief Feedback Pool Allocator API
0003  *  Basically for few fixed sizes we have configured cache for allocated
0004  *  blocks. If we go over the list we just malloc and free.
0005  *
0006  * @file fpalloc.h
0007  */
0008 /* -----------------------------------------------------------------------------
0009  * Enduro/X Middleware Platform for Distributed Transaction Processing
0010  * Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved.
0011  * Copyright (C) 2017-2023, Mavimax, Ltd. All Rights Reserved.
0012  * This software is released under one of the following licenses:
0013  * AGPL (with Java and Go exceptions) or Mavimax's license for commercial use.
0014  * See LICENSE file for full text.
0015  * -----------------------------------------------------------------------------
0016  * AGPL license:
0017  *
0018  * This program is free software; you can redistribute it and/or modify it under
0019  * the terms of the GNU Affero General Public License, version 3 as published
0020  * by the Free Software Foundation;
0021  *
0022  * This program is distributed in the hope that it will be useful, but WITHOUT ANY
0023  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
0024  * PARTICULAR PURPOSE. See the GNU Affero General Public License, version 3
0025  * for more details.
0026  *
0027  * You should have received a copy of the GNU Affero General Public License along 
0028  * with this program; if not, write to the Free Software Foundation, Inc.,
0029  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0030  *
0031  * -----------------------------------------------------------------------------
0032  * A commercial use license is available from Mavimax, Ltd
0033  * contact@mavimax.com
0034  * -----------------------------------------------------------------------------
0035  */
0036 #ifndef FPALLOC_H_
0037 #define FPALLOC_H_
0038 
0039 #if defined(__cplusplus)
0040 extern "C" {
0041 #endif
0042 
0043 /*---------------------------Includes-----------------------------------*/
0044 #include <ndrx_config.h>
0045 /*---------------------------Externs------------------------------------*/
0046 /*---------------------------Macros-------------------------------------*/
0047 #define NDRX_FPA_MAGIC          0xFEEDBCA1  /**< FPA Block magic            */
0048     
0049 /* FPA FLAGS: */
0050 #define NDRX_FPNOFLAG         0           /**< No special flags             */
0051 #define NDRX_FPNOPOOL         0x0001      /**< do not use alloc pool        */
0052 #define NDRX_FPSYSBUF         0x0002      /**< use NDRX_MSGSIZEMAX          */
0053 #define NDRX_FPABRSIZE        0x0004      /**< arbtirary size buf, free     */
0054     
0055 #define NDRX_FPA_SIZE_DEFAULT   -1   /**< these are default settings, use by init */
0056 #define NDRX_FPA_SIZE_SYSBUF   -2    /**< settings are for system buffer */
0057 
0058 /**
0059  * max number of sizes    
0060  * Note that dynamic range will be
0061  * NDRX_FPA_MAX - 1, as the last entry is SYSBUF
0062  */
0063 #define NDRX_FPA_MIN            0           /**< minimum dynamic range     */
0064 #define NDRX_FPA_MAX            7                   /**< NDRX_MSGSIZEMAX pool no*/
0065 #define NDRX_FPA_DYN_MAX        (NDRX_FPA_MAX-1)    /**< dynamic range          */
0066     
0067 #define NDRX_FPA_0_SIZE         (256)       /**< 256b pool                 */
0068 #define NDRX_FPA_0_DNUM         25          /**< default cache size        */
0069     
0070 #define NDRX_FPA_1_SIZE         (512)       /**< 512b pool                 */
0071 #define NDRX_FPA_1_DNUM         15          /**< default cache size        */
0072     
0073 #define NDRX_FPA_2_SIZE         (1*1024)    /**< 1KB pool                  */
0074 #define NDRX_FPA_2_DNUM         10          /**< default cache size        */
0075     
0076 #define NDRX_FPA_3_SIZE         (2*1024)    /**< 2KB pool                  */
0077 #define NDRX_FPA_3_DNUM         10          /**< default cache size        */
0078     
0079 #define NDRX_FPA_4_SIZE         (4*1024)    /**< 4KB pool                  */
0080 #define NDRX_FPA_4_DNUM         10          /**< default cache size        */
0081 
0082 #define NDRX_FPA_5_SIZE         (8*1024)    /**< 8KB pool                  */
0083 #define NDRX_FPA_5_DNUM         10          /**< default cache size        */
0084     
0085 #define NDRX_FPA_SIZE_MAX       NDRX_FPA_5_SIZE   /**< max dynamic range   */
0086 
0087 #define NDRX_FPA_SYSBUF_SIZE         NDRX_FPA_SIZE_SYSBUF   /**< sysbuf pool    */
0088 #define NDRX_FPA_SYSBUF_DNUM    10          /**< default cache size             */
0089 #define NDRX_FPA_SYSBUF_POOLNO    (NDRX_FPA_MAX-1)    /**< pool number of sysbuf*/
0090     
0091 /** print FPA statistics to ULOG  
0092 #define NDRX_FPA_STATS  1*/
0093 
0094 /*---------------------------Enums--------------------------------------*/
0095 /*---------------------------Typedefs-----------------------------------*/
0096 /*---------------------------Globals------------------------------------*/
0097 /*---------------------------Statics------------------------------------*/
0098 /*---------------------------Prototypes---------------------------------*/
0099 
0100 extern NDRX_API void ndrx_fpuninit(void);
0101 extern NDRX_API void *ndrx_fpmalloc(size_t size, int flags);
0102 extern NDRX_API void *ndrx_fprealloc(void *ptr, size_t size);
0103 extern NDRX_API void ndrx_fpfree(void *);
0104 
0105 #if defined(__cplusplus)
0106 }
0107 #endif
0108 
0109 #endif
0110 /* vim: set ts=4 sw=4 et smartindent: */