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 * ====================================================================
29 #include <apr_general.h>
30 #include <apr_pools.h>
31 #include <apr_thread_mutex.h>
33 #include "svn_pools.h"
37 /* file_line for the non-debug case. */
38 static const char SVN_FILE_LINE_UNDEFINED[] = "svn:<undefined>";
39 #endif /* APR_POOL_DEBUG */
43 /*-----------------------------------------------------------------*/
46 /* Pool allocation handler which just aborts, since we aren't generally
47 prepared to deal with out-of-memory errors.
50 abort_on_pool_failure(int retcode)
52 /* Don't translate this string! It requires memory allocation to do so!
53 And we don't have any of it... */
54 printf("Out of memory - terminating application.\n");
56 return 0; /* not reached */
61 #undef svn_pool_create_ex
62 #endif /* APR_POOL_DEBUG */
67 svn_pool_create_ex(apr_pool_t *parent_pool, apr_allocator_t *allocator)
70 apr_pool_create_ex(&pool, parent_pool, abort_on_pool_failure, allocator);
74 /* Wrapper that ensures binary compatibility */
76 svn_pool_create_ex_debug(apr_pool_t *pool, apr_allocator_t *allocator,
77 const char *file_line)
79 return svn_pool_create_ex(pool, allocator);
82 #else /* APR_POOL_DEBUG */
85 svn_pool_create_ex_debug(apr_pool_t *parent_pool, apr_allocator_t *allocator,
86 const char *file_line)
89 apr_pool_create_ex_debug(&pool, parent_pool, abort_on_pool_failure,
90 allocator, file_line);
94 /* Wrapper that ensures binary compatibility */
96 svn_pool_create_ex(apr_pool_t *pool, apr_allocator_t *allocator)
98 return svn_pool_create_ex_debug(pool, allocator, SVN_FILE_LINE_UNDEFINED);
101 #endif /* APR_POOL_DEBUG */
104 svn_pool_create_allocator(svn_boolean_t thread_safe)
106 apr_allocator_t *allocator;
109 /* create the allocator and limit it's internal free list to keep
110 * memory usage in check */
112 if (apr_allocator_create(&allocator))
113 abort_on_pool_failure(EXIT_FAILURE);
115 apr_allocator_max_free_set(allocator, SVN_ALLOCATOR_RECOMMENDED_MAX_FREE);
117 /* create the root pool */
119 pool = svn_pool_create_ex(NULL, allocator);
120 apr_allocator_owner_set(allocator, pool);
123 apr_pool_tag (pool, "svn root pool");
126 /* By default, allocators are *not* thread-safe. We must provide a mutex
127 * if we want thread-safety for that mutex. */
132 apr_thread_mutex_t *mutex;
133 apr_thread_mutex_create(&mutex, APR_THREAD_MUTEX_DEFAULT, pool);
134 apr_allocator_mutex_set(allocator, mutex);
138 /* better safe than sorry */
139 SVN_ERR_ASSERT_NO_RETURN(allocator != NULL);