/src/dovecot/src/lib/mempool.c
Line | Count | Source |
1 | | /* Copyright (c) 2005-2018 Dovecot authors, see the included COPYING file */ |
2 | | |
3 | | #include "lib.h" |
4 | | #include "array.h" |
5 | | |
6 | | /* The various implementations of pools API assume that they'll never be |
7 | | asked for more than SSIZE_T_MAX bytes. This is a sanity check to make |
8 | | sure nobody accidentally bumped the define beyond what's expected. */ |
9 | | #if POOL_MAX_ALLOC_SIZE > SSIZE_T_MAX |
10 | | #error "POOL_MAX_ALLOC_SIZE is too large" |
11 | | #endif |
12 | | |
13 | | size_t pool_get_exp_grown_size(pool_t pool, size_t old_size, size_t min_size) |
14 | 79.9k | { |
15 | 79.9k | size_t exp_size, easy_size; |
16 | | |
17 | 79.9k | i_assert(old_size < min_size); |
18 | | |
19 | 79.9k | exp_size = nearest_power(min_size); |
20 | 79.9k | easy_size = old_size + p_get_max_easy_alloc_size(pool); |
21 | | |
22 | 79.9k | if (easy_size < exp_size && easy_size >= min_size) |
23 | 4.22k | exp_size = easy_size; |
24 | 79.9k | i_assert(exp_size >= min_size); |
25 | 79.9k | return exp_size; |
26 | 79.9k | } |
27 | | |
28 | | void pool_add_external_ref(pool_t pool, pool_t ref_pool) |
29 | 0 | { |
30 | 0 | i_assert(pool != system_pool); |
31 | 0 | i_assert(ref_pool != system_pool); |
32 | 0 | i_assert(!pool->datastack_pool); |
33 | 0 | i_assert(!ref_pool->datastack_pool); |
34 | | |
35 | 0 | if (!array_is_created(&pool->external_refs)) |
36 | 0 | i_array_init(&pool->external_refs, 1); |
37 | 0 | array_push_back(&pool->external_refs, &ref_pool); |
38 | 0 | pool_ref(ref_pool); |
39 | 0 | } |
40 | | |
41 | | void pool_external_refs_unref(pool_t pool) |
42 | 10.0k | { |
43 | 10.0k | if (array_is_created(&pool->external_refs)) { |
44 | 0 | pool_t external_pool; |
45 | 0 | array_foreach_elem(&pool->external_refs, external_pool) |
46 | 0 | pool_unref(&external_pool); |
47 | 0 | array_free(&pool->external_refs); |
48 | 0 | } |
49 | 10.0k | } |