2 * root_pools.c : Implement svn_root_pools__* API
4 * ====================================================================
5 * Licensed to the Apache Software Foundation (ASF) under one
6 * or more contributor license agreements. See the NOTICE file
7 * distributed with this work for additional information
8 * regarding copyright ownership. The ASF licenses this file
9 * to you under the Apache License, Version 2.0 (the
10 * "License"); you may not use this file except in compliance
11 * with the License. You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing,
16 * software distributed under the License is distributed on an
17 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18 * KIND, either express or implied. See the License for the
19 * specific language governing permissions and limitations
21 * ====================================================================
24 #include "svn_pools.h"
26 #include "private/svn_subr_private.h"
27 #include "private/svn_mutex.h"
29 struct svn_root_pools__t
32 * Use MUTEX to serialize access to this collection.
34 apr_array_header_t *unused_pools;
36 /* Mutex to serialize access to UNUSED_POOLS */
42 svn_root_pools__create(svn_root_pools__t **pools)
44 /* the collection of root pools must be managed independently from
47 = apr_allocator_owner_get(svn_pool_create_allocator(FALSE));
49 /* construct result object */
50 svn_root_pools__t *result = apr_pcalloc(pool, sizeof(*result));
51 SVN_ERR(svn_mutex__init(&result->mutex, TRUE, pool));
52 result->unused_pools = apr_array_make(pool, 16, sizeof(apr_pool_t *));
60 /* Return a currently unused connection pool in *POOL. If no such pool
61 * exists, create a new root pool and return that in *POOL.
64 acquire_pool_internal(apr_pool_t **pool,
65 svn_root_pools__t *pools)
67 SVN_ERR(svn_mutex__lock(pools->mutex));
68 *pool = pools->unused_pools->nelts
69 ? *(apr_pool_t **)apr_array_pop(pools->unused_pools)
70 : apr_allocator_owner_get(svn_pool_create_allocator(FALSE));
71 SVN_ERR(svn_mutex__unlock(pools->mutex, SVN_NO_ERROR));
77 svn_root_pools__acquire_pool(svn_root_pools__t *pools)
80 svn_error_t *err = acquire_pool_internal(&pool, pools);
83 /* Mutex failure?! Well, try to continue with unrecycled data. */
85 pool = apr_allocator_owner_get(svn_pool_create_allocator(FALSE));
92 svn_root_pools__release_pool(apr_pool_t *pool,
93 svn_root_pools__t *pools)
99 err = svn_mutex__lock(pools->mutex);
102 svn_error_clear(err);
103 svn_pool_destroy(pool);
107 APR_ARRAY_PUSH(pools->unused_pools, apr_pool_t *) = pool;
108 svn_error_clear(svn_mutex__unlock(pools->mutex, SVN_NO_ERROR));