2
* root-pools-test.c -- test the 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 <apr_pools.h>
25
#include <apr_thread_proc.h>
26
#include <apr_thread_cond.h>
28
#include "private/svn_atomic.h"
29
#include "private/svn_subr_private.h"
31
#include "../svn_test.h"
33
/* do a few allocations of various sizes from POOL */
35
do_some_allocations(apr_pool_t *pool)
38
apr_size_t fib = 1, fib1 = 0, fib2 = 0;
39
for (i = 0; i < 25; ++i) /* fib(25) = 75025 */
41
apr_pcalloc(pool, fib1);
48
/* allocate, use and recycle a pool from POOLs a few times */
50
use_root_pool(svn_root_pools__t *pools)
53
for (i = 0; i < 1000; ++i)
55
apr_pool_t *pool = svn_root_pools__acquire_pool(pools);
56
do_some_allocations(pool);
57
svn_root_pools__release_pool(pool, pools);
63
APR_THREAD_FUNC thread_func(apr_thread_t *tid, void *data)
65
/* give all threads a good chance to get started by the scheduler */
69
apr_thread_exit(tid, APR_SUCCESS);
76
test_root_pool(apr_pool_t *pool)
78
svn_root_pools__t *pools;
79
SVN_ERR(svn_root_pools__create(&pools));
85
#define APR_ERR(expr) \
87
apr_status_t status = (expr); \
89
return svn_error_wrap_apr(status, NULL); \
93
test_root_pool_concurrency(apr_pool_t *pool)
96
/* The svn_root_pools__t container is supposed to be thread-safe.
97
Do some multi-threaded access and hope that there are no segfaults.
99
enum { THREAD_COUNT = 10 };
100
svn_root_pools__t *pools;
101
apr_thread_t *threads[THREAD_COUNT];
104
SVN_ERR(svn_root_pools__create(&pools));
106
for (i = 0; i < THREAD_COUNT; ++i)
107
APR_ERR(apr_thread_create(&threads[i], NULL, thread_func, pools, pool));
109
/* wait for the threads to finish */
110
for (i = 0; i < THREAD_COUNT; ++i)
113
APR_ERR(apr_thread_join(&retval, threads[i]));
122
/* The test table. */
124
static int max_threads = 1;
126
static struct svn_test_descriptor_t test_funcs[] =
129
SVN_TEST_PASS2(test_root_pool,
130
"test root pool recycling"),
131
SVN_TEST_SKIP2(test_root_pool_concurrency,
133
"test concurrent root pool recycling"),