⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 apr_pools.h

📁 apache的软件linux版本
💻 H
📖 第 1 页 / 共 2 页
字号:
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements.  See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License.  You may obtain a copy of the License at * *     http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */#ifndef APR_POOLS_H#define APR_POOLS_H/** * @file apr_pools.h * @brief APR memory allocation * * Resource allocation routines... * * designed so that we don't have to keep track of EVERYTHING so that * it can be explicitly freed later (a fundamentally unsound strategy --- * particularly in the presence of die()). * * Instead, we maintain pools, and allocate items (both memory and I/O * handlers) from the pools --- currently there are two, one for per * transaction info, and one for config info.  When a transaction is over, * we can delete everything in the per-transaction apr_pool_t without fear, * and without thinking too hard about it either. */#include "apr.h"#include "apr_errno.h"#include "apr_general.h" /* for APR_STRINGIFY */#define APR_WANT_MEMFUNC /**< for no good reason? */#include "apr_want.h"#ifdef __cplusplusextern "C" {#endif/** * @defgroup apr_pools Memory Pool Functions * @ingroup APR  * @{ *//** The fundamental pool type */typedef struct apr_pool_t apr_pool_t;/** * Declaration helper macro to construct apr_foo_pool_get()s. * * This standardized macro is used by opaque (APR) data types to return * the apr_pool_t that is associated with the data type. * * APR_POOL_DECLARE_ACCESSOR() is used in a header file to declare the * accessor function. A typical usage and result would be: * <pre> *    APR_POOL_DECLARE_ACCESSOR(file); * becomes: *    APR_DECLARE(apr_pool_t *) apr_file_pool_get(apr_file_t *ob); * </pre> * @remark Doxygen unwraps this macro (via doxygen.conf) to provide  * actual help for each specific occurance of apr_foo_pool_get. * @remark the linkage is specified for APR. It would be possible to expand *       the macros to support other linkages. */#define APR_POOL_DECLARE_ACCESSOR(type) \    APR_DECLARE(apr_pool_t *) apr_##type##_pool_get \        (const apr_##type##_t *the##type)/**  * Implementation helper macro to provide apr_foo_pool_get()s. * * In the implementation, the APR_POOL_IMPLEMENT_ACCESSOR() is used to * actually define the function. It assumes the field is named "pool". */#define APR_POOL_IMPLEMENT_ACCESSOR(type) \    APR_DECLARE(apr_pool_t *) apr_##type##_pool_get \            (const apr_##type##_t *the##type) \        { return the##type->pool; }/** * Pool debug levels * * <pre> * | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | * --------------------------------- * |   |   |   |   |   |   |   | x |  General debug code enabled (usefull in *                                    combination with --with-efence). * * |   |   |   |   |   |   | x |   |  Verbose output on stderr (report *                                    CREATE, CLEAR, DESTROY). * * |   |   |   | x |   |   |   |   |  Verbose output on stderr (report *                                    PALLOC, PCALLOC). * * |   |   |   |   |   | x |   |   |  Lifetime checking. On each use of a *                                    pool, check its lifetime.  If the pool *                                    is out of scope, abort(). *                                    In combination with the verbose flag *                                    above, it will output LIFE in such an *                                    event prior to aborting. * * |   |   |   |   | x |   |   |   |  Pool owner checking.  On each use of a *                                    pool, check if the current thread is the *                                    pools owner.  If not, abort().  In *                                    combination with the verbose flag above, *                                    it will output OWNER in such an event *                                    prior to aborting.  Use the debug *                                    function apr_pool_owner_set() to switch *                                    a pools ownership. * * When no debug level was specified, assume general debug mode. * If level 0 was specified, debugging is switched off * </pre> */#if defined(APR_POOL_DEBUG)#if (APR_POOL_DEBUG != 0) && (APR_POOL_DEBUG - 0 == 0)#undef APR_POOL_DEBUG#define APR_POOL_DEBUG 1#endif#else#define APR_POOL_DEBUG 0#endif/** the place in the code where the particular function was called */#define APR_POOL__FILE_LINE__ __FILE__ ":" APR_STRINGIFY(__LINE__)/** A function that is called when allocation fails. */typedef int (*apr_abortfunc_t)(int retcode);/* * APR memory structure manipulators (pools, tables, and arrays). *//* * Initialization *//** * Setup all of the internal structures required to use pools * @remark Programs do NOT need to call this directly.  APR will call this *      automatically from apr_initialize. * @internal */APR_DECLARE(apr_status_t) apr_pool_initialize(void);/** * Tear down all of the internal structures required to use pools * @remark Programs do NOT need to call this directly.  APR will call this *      automatically from apr_terminate. * @internal */APR_DECLARE(void) apr_pool_terminate(void);/* * Pool creation/destruction */#include "apr_allocator.h"/** * Create a new pool. * @param newpool The pool we have just created. * @param parent The parent pool.  If this is NULL, the new pool is a root *        pool.  If it is non-NULL, the new pool will inherit all *        of its parent pool's attributes, except the apr_pool_t will *        be a sub-pool. * @param abort_fn A function to use if the pool cannot allocate more memory. * @param allocator The allocator to use with the new pool.  If NULL the *        allocator of the parent pool will be used. */APR_DECLARE(apr_status_t) apr_pool_create_ex(apr_pool_t **newpool,                                             apr_pool_t *parent,                                             apr_abortfunc_t abort_fn,                                             apr_allocator_t *allocator);/** * Debug version of apr_pool_create_ex. * @param newpool @see apr_pool_create. * @param parent @see apr_pool_create. * @param abort_fn @see apr_pool_create. * @param allocator @see apr_pool_create. * @param file_line Where the function is called from. *        This is usually APR_POOL__FILE_LINE__. * @remark Only available when APR_POOL_DEBUG is defined. *         Call this directly if you have you apr_pool_create_ex *         calls in a wrapper function and wish to override *         the file_line argument to reflect the caller of *         your wrapper function.  If you do not have *         apr_pool_create_ex in a wrapper, trust the macro *         and don't call apr_pool_create_ex_debug directly. */APR_DECLARE(apr_status_t) apr_pool_create_ex_debug(apr_pool_t **newpool,                                                   apr_pool_t *parent,                                                   apr_abortfunc_t abort_fn,                                                   apr_allocator_t *allocator,                                                   const char *file_line);#if APR_POOL_DEBUG#define apr_pool_create_ex(newpool, parent, abort_fn, allocator)  \    apr_pool_create_ex_debug(newpool, parent, abort_fn, allocator, \                             APR_POOL__FILE_LINE__)#endif/** * Create a new pool. * @param newpool The pool we have just created. * @param parent The parent pool.  If this is NULL, the new pool is a root *        pool.  If it is non-NULL, the new pool will inherit all *        of its parent pool's attributes, except the apr_pool_t will *        be a sub-pool. */#if defined(DOXYGEN)APR_DECLARE(apr_status_t) apr_pool_create(apr_pool_t **newpool,                                          apr_pool_t *parent);#else#if APR_POOL_DEBUG#define apr_pool_create(newpool, parent) \    apr_pool_create_ex_debug(newpool, parent, NULL, NULL, \                             APR_POOL__FILE_LINE__)#else#define apr_pool_create(newpool, parent) \    apr_pool_create_ex(newpool, parent, NULL, NULL)#endif#endif/** @deprecated @see apr_pool_create_ex */#if APR_POOL_DEBUG#define apr_pool_sub_make(newpool, parent, abort_fn) \    (void)apr_pool_create_ex_debug(newpool, parent, abort_fn, \                                   NULL, \                                   APR_POOL__FILE_LINE__)#else#define apr_pool_sub_make(newpool, parent, abort_fn) \    (void)apr_pool_create_ex(newpool, parent, abort_fn, NULL)#endif/** * Find the pools allocator * @param pool The pool to get the allocator from. */APR_DECLARE(apr_allocator_t *) apr_pool_allocator_get(apr_pool_t *pool);/** * Clear all memory in the pool and run all the cleanups. This also destroys all * subpools. * @param p The pool to clear * @remark This does not actually free the memory, it just allows the pool *         to re-use this memory for the next allocation. * @see apr_pool_destroy() */APR_DECLARE(void) apr_pool_clear(apr_pool_t *p);/** * Debug version of apr_pool_clear. * @param p See: apr_pool_clear. * @param file_line Where the function is called from. *        This is usually APR_POOL__FILE_LINE__. * @remark Only available when APR_POOL_DEBUG is defined. *         Call this directly if you have you apr_pool_clear *         calls in a wrapper function and wish to override *         the file_line argument to reflect the caller of *         your wrapper function.  If you do not have *         apr_pool_clear in a wrapper, trust the macro *         and don't call apr_pool_destroy_clear directly. */APR_DECLARE(void) apr_pool_clear_debug(apr_pool_t *p,                                       const char *file_line);#if APR_POOL_DEBUG#define apr_pool_clear(p) \    apr_pool_clear_debug(p, APR_POOL__FILE_LINE__)#endif/** * Destroy the pool. This takes similar action as apr_pool_clear() and then * frees all the memory. * @param p The pool to destroy * @remark This will actually free the memory */APR_DECLARE(void) apr_pool_destroy(apr_pool_t *p);/** * Debug version of apr_pool_destroy. * @param p See: apr_pool_destroy. * @param file_line Where the function is called from. *        This is usually APR_POOL__FILE_LINE__. * @remark Only available when APR_POOL_DEBUG is defined. *         Call this directly if you have you apr_pool_destroy *         calls in a wrapper function and wish to override *         the file_line argument to reflect the caller of *         your wrapper function.  If you do not have *         apr_pool_destroy in a wrapper, trust the macro *         and don't call apr_pool_destroy_debug directly. */APR_DECLARE(void) apr_pool_destroy_debug(apr_pool_t *p,                                         const char *file_line);#if APR_POOL_DEBUG#define apr_pool_destroy(p) \    apr_pool_destroy_debug(p, APR_POOL__FILE_LINE__)#endif/* * Memory allocation *//** * Allocate a block of memory from a pool * @param p The pool to allocate from * @param size The amount of memory to allocate * @return The allocated memory */APR_DECLARE(void *) apr_palloc(apr_pool_t *p, apr_size_t size);/** * Debug version of apr_palloc * @param p See: apr_palloc * @param size See: apr_palloc

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -