diff options
Diffstat (limited to 'subversion/libsvn_subr/pool.c')
-rw-r--r-- | subversion/libsvn_subr/pool.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/subversion/libsvn_subr/pool.c b/subversion/libsvn_subr/pool.c index 4b7b3f6..179ef79 100644 --- a/subversion/libsvn_subr/pool.c +++ b/subversion/libsvn_subr/pool.c @@ -28,6 +28,7 @@ #include <apr_general.h> #include <apr_pools.h> +#include <apr_thread_mutex.h> #include "svn_pools.h" @@ -52,6 +53,7 @@ abort_on_pool_failure(int retcode) And we don't have any of it... */ printf("Out of memory - terminating application.\n"); abort(); + return 0; /* not reached */ } @@ -97,3 +99,44 @@ svn_pool_create_ex(apr_pool_t *pool, apr_allocator_t *allocator) } #endif /* APR_POOL_DEBUG */ + +apr_allocator_t * +svn_pool_create_allocator(svn_boolean_t thread_safe) +{ + apr_allocator_t *allocator; + apr_pool_t *pool; + + /* create the allocator and limit it's internal free list to keep + * memory usage in check */ + + if (apr_allocator_create(&allocator)) + abort_on_pool_failure(EXIT_FAILURE); + + apr_allocator_max_free_set(allocator, SVN_ALLOCATOR_RECOMMENDED_MAX_FREE); + + /* create the root pool */ + + pool = svn_pool_create_ex(NULL, allocator); + apr_allocator_owner_set(allocator, pool); + +#if APR_POOL_DEBUG + apr_pool_tag (pool, "svn root pool"); +#endif + + /* By default, allocators are *not* thread-safe. We must provide a mutex + * if we want thread-safety for that mutex. */ + +#if APR_HAS_THREADS + if (thread_safe) + { + apr_thread_mutex_t *mutex; + apr_thread_mutex_create(&mutex, APR_THREAD_MUTEX_DEFAULT, pool); + apr_allocator_mutex_set(allocator, mutex); + } +#endif + + /* better safe than sorry */ + SVN_ERR_ASSERT_NO_RETURN(allocator != NULL); + + return allocator; +} |