1 /* pool.c: pool wrappers for Subversion
3 * ====================================================================
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
20 * ====================================================================
30 #include <apr_version.h>
31 #include <apr_general.h>
32 #include <apr_pools.h>
34 #include "svn_pools.h"
39 /* file_line for the non-debug case. */
40 static const char SVN_FILE_LINE_UNDEFINED[] = "svn:<undefined>";
41 #endif /* APR_POOL_DEBUG */
45 /*-----------------------------------------------------------------*/
48 /* Pool allocation handler which just aborts, since we aren't generally
49 prepared to deal with out-of-memory errors.
52 abort_on_pool_failure(int retcode)
54 /* Don't translate this string! It requires memory allocation to do so!
55 And we don't have any of it... */
56 printf("libsvn: Out of memory - terminating application.\n");
59 /* Provide a way to distinguish the out-of-memory error from abort(). */
60 if (retcode == APR_ENOMEM)
61 RaiseException(STATUS_NO_MEMORY, EXCEPTION_NONCONTINUABLE, 0, NULL);
65 return 0; /* not reached */
70 #undef svn_pool_create_ex
71 #endif /* APR_POOL_DEBUG */
76 svn_pool_create_ex(apr_pool_t *parent_pool, apr_allocator_t *allocator)
79 apr_pool_create_ex(&pool, parent_pool, abort_on_pool_failure, allocator);
83 /* Wrapper that ensures binary compatibility */
85 svn_pool_create_ex_debug(apr_pool_t *pool, apr_allocator_t *allocator,
86 const char *file_line)
88 return svn_pool_create_ex(pool, allocator);
91 #else /* APR_POOL_DEBUG */
94 svn_pool_create_ex_debug(apr_pool_t *parent_pool, apr_allocator_t *allocator,
95 const char *file_line)
98 apr_pool_create_ex_debug(&pool, parent_pool, abort_on_pool_failure,
99 allocator, file_line);
103 /* Wrapper that ensures binary compatibility */
105 svn_pool_create_ex(apr_pool_t *pool, apr_allocator_t *allocator)
107 return svn_pool_create_ex_debug(pool, allocator, SVN_FILE_LINE_UNDEFINED);
110 #endif /* APR_POOL_DEBUG */
113 svn_pool_create_allocator(svn_boolean_t thread_safe)
115 apr_allocator_t *allocator;
118 /* create the allocator and limit it's internal free list to keep
119 * memory usage in check */
121 if (apr_allocator_create(&allocator))
122 abort_on_pool_failure(EXIT_FAILURE);
124 apr_allocator_max_free_set(allocator, SVN_ALLOCATOR_RECOMMENDED_MAX_FREE);
126 /* create the root pool */
128 pool = svn_pool_create_ex(NULL, allocator);
129 apr_allocator_owner_set(allocator, pool);
132 apr_pool_tag (pool, "svn root pool");
135 /* By default, allocators are *not* thread-safe. We must provide a mutex
136 * if we want thread-safety for that pool. */
141 apr_thread_mutex_t *mutex;
142 apr_thread_mutex_create(&mutex, APR_THREAD_MUTEX_DEFAULT, pool);
143 apr_allocator_mutex_set(allocator, mutex);
147 /* better safe than sorry */
148 SVN_ERR_ASSERT_NO_RETURN(allocator != NULL);
154 /* Private function that creates an unmanaged pool. */
156 svn_pool__create_unmanaged(svn_boolean_t thread_safe)
159 apr_pool_create_unmanaged_ex(&pool, abort_on_pool_failure,
160 svn_pool_create_allocator(thread_safe));