Main Page | Modules | Data Structures | File List | Data Fields | Globals | Related Pages

apr_pools.h

Go to the documentation of this file.
00001 /* Copyright 2000-2004 The Apache Software Foundation
00002  *
00003  * Licensed under the Apache License, Version 2.0 (the "License");
00004  * you may not use this file except in compliance with the License.
00005  * You may obtain a copy of the License at
00006  *
00007  *     http://www.apache.org/licenses/LICENSE-2.0
00008  *
00009  * Unless required by applicable law or agreed to in writing, software
00010  * distributed under the License is distributed on an "AS IS" BASIS,
00011  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00012  * See the License for the specific language governing permissions and
00013  * limitations under the License.
00014  */
00015 
00016 #ifndef APR_POOLS_H
00017 #define APR_POOLS_H
00018 
00036 #include "apr.h"
00037 #include "apr_errno.h"
00038 #include "apr_general.h" /* for APR_STRINGIFY */
00039 #define APR_WANT_MEMFUNC 
00040 #include "apr_want.h"
00041 
00042 #ifdef __cplusplus
00043 extern "C" {
00044 #endif
00045 
00053 typedef struct apr_pool_t apr_pool_t;
00054 
00055 
00074 #define APR_POOL_DECLARE_ACCESSOR(type) \
00075     APR_DECLARE(apr_pool_t *) apr_##type##_pool_get \
00076         (const apr_##type##_t *the##type)
00077 
00084 #define APR_POOL_IMPLEMENT_ACCESSOR(type) \
00085     APR_DECLARE(apr_pool_t *) apr_##type##_pool_get \
00086             (const apr_##type##_t *the##type) \
00087         { return the##type->pool; }
00088 
00089 
00125 #if defined(APR_POOL_DEBUG)
00126 #if (APR_POOL_DEBUG != 0) && (APR_POOL_DEBUG - 0 == 0)
00127 #undef APR_POOL_DEBUG
00128 #define APR_POOL_DEBUG 1
00129 #endif
00130 #else
00131 #define APR_POOL_DEBUG 0
00132 #endif
00133 
00135 #define APR_POOL__FILE_LINE__ __FILE__ ":" APR_STRINGIFY(__LINE__)
00136 
00137 
00138 
00140 typedef int (*apr_abortfunc_t)(int retcode);
00141 
00142 /*
00143  * APR memory structure manipulators (pools, tables, and arrays).
00144  */
00145 
00146 /*
00147  * Initialization
00148  */
00149 
00156 APR_DECLARE(apr_status_t) apr_pool_initialize(void);
00157 
00164 APR_DECLARE(void) apr_pool_terminate(void);
00165 
00166 
00167 /*
00168  * Pool creation/destruction
00169  */
00170 
00171 #include "apr_allocator.h"
00172 
00184 APR_DECLARE(apr_status_t) apr_pool_create_ex(apr_pool_t **newpool,
00185                                              apr_pool_t *parent,
00186                                              apr_abortfunc_t abort_fn,
00187                                              apr_allocator_t *allocator);
00188 
00205 APR_DECLARE(apr_status_t) apr_pool_create_ex_debug(apr_pool_t **newpool,
00206                                                    apr_pool_t *parent,
00207                                                    apr_abortfunc_t abort_fn,
00208                                                    apr_allocator_t *allocator,
00209                                                    const char *file_line);
00210 
00211 #if APR_POOL_DEBUG
00212 #define apr_pool_create_ex(newpool, parent, abort_fn, allocator)  \
00213     apr_pool_create_ex_debug(newpool, parent, abort_fn, allocator, \
00214                              APR_POOL__FILE_LINE__)
00215 #endif
00216 
00225 #if defined(DOXYGEN)
00226 APR_DECLARE(apr_status_t) apr_pool_create(apr_pool_t **newpool,
00227                                           apr_pool_t *parent);
00228 #else
00229 #if APR_POOL_DEBUG
00230 #define apr_pool_create(newpool, parent) \
00231     apr_pool_create_ex_debug(newpool, parent, NULL, NULL, \
00232                              APR_POOL__FILE_LINE__)
00233 #else
00234 #define apr_pool_create(newpool, parent) \
00235     apr_pool_create_ex(newpool, parent, NULL, NULL)
00236 #endif
00237 #endif
00238 
00240 #if APR_POOL_DEBUG
00241 #define apr_pool_sub_make(newpool, parent, abort_fn) \
00242     (void)apr_pool_create_ex_debug(newpool, parent, abort_fn, \
00243                                    NULL, \
00244                                    APR_POOL__FILE_LINE__)
00245 #else
00246 #define apr_pool_sub_make(newpool, parent, abort_fn) \
00247     (void)apr_pool_create_ex(newpool, parent, abort_fn, NULL)
00248 #endif
00249 
00254 APR_DECLARE(apr_allocator_t *) apr_pool_allocator_get(apr_pool_t *pool);
00255 
00264 APR_DECLARE(void) apr_pool_clear(apr_pool_t *p);
00265 
00279 APR_DECLARE(void) apr_pool_clear_debug(apr_pool_t *p,
00280                                        const char *file_line);
00281 
00282 #if APR_POOL_DEBUG
00283 #define apr_pool_clear(p) \
00284     apr_pool_clear_debug(p, APR_POOL__FILE_LINE__)
00285 #endif
00286 
00293 APR_DECLARE(void) apr_pool_destroy(apr_pool_t *p);
00294 
00308 APR_DECLARE(void) apr_pool_destroy_debug(apr_pool_t *p,
00309                                          const char *file_line);
00310 
00311 #if APR_POOL_DEBUG
00312 #define apr_pool_destroy(p) \
00313     apr_pool_destroy_debug(p, APR_POOL__FILE_LINE__)
00314 #endif
00315 
00316 
00317 /*
00318  * Memory allocation
00319  */
00320 
00327 APR_DECLARE(void *) apr_palloc(apr_pool_t *p, apr_size_t size);
00328 
00337 APR_DECLARE(void *) apr_palloc_debug(apr_pool_t *p, apr_size_t size,
00338                                      const char *file_line);
00339 
00340 #if APR_POOL_DEBUG
00341 #define apr_palloc(p, size) \
00342     apr_palloc_debug(p, size, APR_POOL__FILE_LINE__)
00343 #endif
00344 
00351 #if defined(DOXYGEN)
00352 APR_DECLARE(void *) apr_pcalloc(apr_pool_t *p, apr_size_t size);
00353 #elif !APR_POOL_DEBUG
00354 #define apr_pcalloc(p, size) memset(apr_palloc(p, size), 0, size)
00355 #endif
00356 
00365 APR_DECLARE(void *) apr_pcalloc_debug(apr_pool_t *p, apr_size_t size,
00366                                       const char *file_line);
00367 
00368 #if APR_POOL_DEBUG
00369 #define apr_pcalloc(p, size) \
00370     apr_pcalloc_debug(p, size, APR_POOL__FILE_LINE__)
00371 #endif
00372 
00373 
00374 /*
00375  * Pool Properties
00376  */
00377 
00386 APR_DECLARE(void) apr_pool_abort_set(apr_abortfunc_t abortfunc,
00387                                      apr_pool_t *pool);
00388 
00390 APR_DECLARE(void) apr_pool_set_abort(apr_abortfunc_t abortfunc,
00391                                      apr_pool_t *pool);
00392 
00398 APR_DECLARE(apr_abortfunc_t) apr_pool_abort_get(apr_pool_t *pool);
00399 
00401 APR_DECLARE(apr_abortfunc_t) apr_pool_get_abort(apr_pool_t *pool);
00402 
00408 APR_DECLARE(apr_pool_t *) apr_pool_parent_get(apr_pool_t *pool);
00409 
00411 APR_DECLARE(apr_pool_t *) apr_pool_get_parent(apr_pool_t *pool);
00412 
00420 APR_DECLARE(int) apr_pool_is_ancestor(apr_pool_t *a, apr_pool_t *b);
00421 
00427 APR_DECLARE(void) apr_pool_tag(apr_pool_t *pool, const char *tag);
00428 
00429 
00430 /*
00431  * User data management
00432  */
00433 
00452 APR_DECLARE(apr_status_t) apr_pool_userdata_set(
00453     const void *data,
00454     const char *key,
00455     apr_status_t (*cleanup)(void *),
00456     apr_pool_t *pool);
00457 
00477 APR_DECLARE(apr_status_t) apr_pool_userdata_setn(
00478     const void *data,
00479     const char *key,
00480     apr_status_t (*cleanup)(void *),
00481     apr_pool_t *pool);
00482 
00489 APR_DECLARE(apr_status_t) apr_pool_userdata_get(void **data, const char *key,
00490                                                 apr_pool_t *pool);
00491 
00492 
00493 /*
00494  * Cleanup
00495  *
00496  * Cleanups are performed in the reverse order they were registered.  That is:
00497  * Last In, First Out.
00498  */
00499 
00509 APR_DECLARE(void) apr_pool_cleanup_register(
00510     apr_pool_t *p,
00511     const void *data,
00512     apr_status_t (*plain_cleanup)(void *),
00513     apr_status_t (*child_cleanup)(void *));
00514 
00523 APR_DECLARE(void) apr_pool_cleanup_kill(apr_pool_t *p, const void *data,
00524                                         apr_status_t (*cleanup)(void *));
00525 
00533 APR_DECLARE(void) apr_pool_child_cleanup_set(
00534     apr_pool_t *p,
00535     const void *data,
00536     apr_status_t (*plain_cleanup)(void *),
00537     apr_status_t (*child_cleanup)(void *));
00538 
00546 APR_DECLARE(apr_status_t) apr_pool_cleanup_run(
00547     apr_pool_t *p,
00548     void *data,
00549     apr_status_t (*cleanup)(void *));
00550 
00555 APR_DECLARE_NONSTD(apr_status_t) apr_pool_cleanup_null(void *data);
00556 
00557 /* Preparing for exec() --- close files, etc., but *don't* flush I/O
00558  * buffers, *don't* wait for subprocesses, and *don't* free any memory.
00559  */
00564 APR_DECLARE(void) apr_pool_cleanup_for_exec(void);
00565 
00566 
00611 #if APR_POOL_DEBUG || defined(DOXYGEN)
00612 
00617 APR_DECLARE(void) apr_pool_join(apr_pool_t *p, apr_pool_t *sub);
00618 
00624 APR_DECLARE(apr_pool_t *) apr_pool_find(const void *mem);
00625 
00632 APR_DECLARE(apr_size_t) apr_pool_num_bytes(apr_pool_t *p, int recurse);
00633 
00639 APR_DECLARE(void) apr_pool_lock(apr_pool_t *pool, int flag);
00640 
00641 /* @} */
00642 
00643 #else /* APR_POOL_DEBUG or DOXYGEN */
00644 
00645 #ifdef apr_pool_join
00646 #undef apr_pool_join
00647 #endif
00648 #define apr_pool_join(a,b)
00649 
00650 #ifdef apr_pool_lock
00651 #undef apr_pool_lock
00652 #endif
00653 #define apr_pool_lock(pool, lock)
00654 
00655 #endif /* APR_POOL_DEBUG or DOXYGEN */
00656 
00659 #ifdef __cplusplus
00660 }
00661 #endif
00662 
00663 #endif /* !APR_POOLS_H */

Generated on Wed Dec 8 10:14:03 2004 for Apache Portable Runtime by doxygen 1.3.6