1251881Speter/**
2251881Speter * @copyright
3251881Speter * ====================================================================
4251881Speter *    Licensed to the Apache Software Foundation (ASF) under one
5251881Speter *    or more contributor license agreements.  See the NOTICE file
6251881Speter *    distributed with this work for additional information
7251881Speter *    regarding copyright ownership.  The ASF licenses this file
8251881Speter *    to you under the Apache License, Version 2.0 (the
9251881Speter *    "License"); you may not use this file except in compliance
10251881Speter *    with the License.  You may obtain a copy of the License at
11251881Speter *
12251881Speter *      http://www.apache.org/licenses/LICENSE-2.0
13251881Speter *
14251881Speter *    Unless required by applicable law or agreed to in writing,
15251881Speter *    software distributed under the License is distributed on an
16251881Speter *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17251881Speter *    KIND, either express or implied.  See the License for the
18251881Speter *    specific language governing permissions and limitations
19251881Speter *    under the License.
20251881Speter * ====================================================================
21251881Speter * @endcopyright
22251881Speter *
23251881Speter * @file svn_pools.h
24251881Speter * @brief APR pool management for Subversion
25251881Speter */
26251881Speter
27251881Speter
28251881Speter
29251881Speter
30251881Speter#ifndef SVN_POOLS_H
31251881Speter#define SVN_POOLS_H
32251881Speter
33251881Speter#include "svn_types.h"
34251881Speter
35251881Speter#ifdef __cplusplus
36251881Speterextern "C" {
37251881Speter#endif /* __cplusplus */
38251881Speter
39251881Speter
40251881Speter
41251881Speter/* Wrappers around APR pools, so we get debugging. */
42251881Speter
43251881Speter/** The recommended maximum amount of memory (4MB) to keep in an APR
44251881Speter * allocator on the free list, conveniently defined here to share
45251881Speter * between all our applications.
46251881Speter */
47251881Speter#define SVN_ALLOCATOR_RECOMMENDED_MAX_FREE (4096 * 1024)
48251881Speter
49251881Speter
50251881Speter/** Wrapper around apr_pool_create_ex(), with a simpler interface.
51251881Speter * The return pool will have an abort function set, which will call
52251881Speter * abort() on OOM.
53251881Speter */
54251881Speterapr_pool_t *
55251881Spetersvn_pool_create_ex(apr_pool_t *parent_pool,
56251881Speter                   apr_allocator_t *allocator);
57251881Speter
58251881Speter#ifndef DOXYGEN_SHOULD_SKIP_THIS
59251881Speterapr_pool_t *
60251881Spetersvn_pool_create_ex_debug(apr_pool_t *parent_pool,
61251881Speter                         apr_allocator_t *allocator,
62251881Speter                         const char *file_line);
63251881Speter
64251881Speter#if APR_POOL_DEBUG
65251881Speter#define svn_pool_create_ex(pool, allocator) \
66251881Spetersvn_pool_create_ex_debug(pool, allocator, APR_POOL__FILE_LINE__)
67251881Speter
68251881Speter#endif /* APR_POOL_DEBUG */
69251881Speter#endif /* DOXYGEN_SHOULD_SKIP_THIS */
70251881Speter
71251881Speter
72251881Speter/** Create a pool as a subpool of @a parent_pool */
73251881Speter#define svn_pool_create(parent_pool) svn_pool_create_ex(parent_pool, NULL)
74251881Speter
75251881Speter/** Clear a @a pool destroying its children.
76251881Speter *
77251881Speter * This define for @c svn_pool_clear exists for completeness.
78251881Speter */
79251881Speter#define svn_pool_clear apr_pool_clear
80251881Speter
81251881Speter
82251881Speter/** Destroy a @a pool and all of its children.
83251881Speter *
84251881Speter * This define for @c svn_pool_destroy exists for symmetry and
85251881Speter * completeness.
86251881Speter */
87251881Speter#define svn_pool_destroy apr_pool_destroy
88251881Speter
89251881Speter/** Return a new allocator.  This function limits the unused memory in the
90251881Speter * new allocator to #SVN_ALLOCATOR_RECOMMENDED_MAX_FREE and ensures
91251881Speter * proper synchronization if the allocator is used by multiple threads.
92251881Speter *
93251881Speter * If your application uses multiple threads, creating a separate
94251881Speter * allocator for each of these threads may not be feasible.  Set the
95251881Speter * @a thread_safe parameter to @c TRUE in that case; otherwise, set @a
96251881Speter * thread_safe to @c FALSE to maximize performance.
97251881Speter *
98251881Speter * @note Even if @a thread_safe is @c TRUE, pools themselves will
99251881Speter * still not be thread-safe and their access may require explicit
100251881Speter * serialization.
101251881Speter *
102251881Speter * To access the owner pool, which can also serve as the root pool for
103251881Speter * your sub-pools, call @c apr_allocator_get_owner().
104251881Speter *
105251881Speter * @since: New in 1.8
106251881Speter */
107251881Speterapr_allocator_t *
108251881Spetersvn_pool_create_allocator(svn_boolean_t thread_safe);
109251881Speter
110251881Speter#ifdef __cplusplus
111251881Speter}
112251881Speter#endif /* __cplusplus */
113251881Speter
114251881Speter#endif /* SVN_POOLS_H */
115