ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/include/mempool.h
Revision: 7006
Committed: Fri Jan 1 00:07:54 2016 UTC (9 years, 7 months ago) by michael
Content type: text/x-chdr
File size: 3767 byte(s)
Log Message:
- Update copyright years

File Contents

# Content
1 /*
2 * Copyright (c) 2007-2012, The Tor Project, Inc.
3 * Copyright (c) 2012-2016 ircd-hybrid development team
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * * Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following disclaimer
14 * in the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * * Neither the names of the copyright owners nor the names of its
18 * contributors may be used to endorse or promote products derived from
19 * this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34 /*! \file mempool.h
35 * \brief Pooling allocator
36 * \version $Id$
37 */
38
39 #ifndef INCLUDED_mempool_h
40 #define INCLUDED_mempool_h
41
42 /** A memory pool is a context in which a large number of fixed-sized
43 * objects can be allocated efficiently. See mempool.c for implementation
44 * details. */
45 typedef struct mp_pool_t mp_pool_t;
46
47 extern void mp_pool_init(void);
48 extern void *mp_pool_get(mp_pool_t *);
49 extern void mp_pool_release(void *);
50 extern mp_pool_t *mp_pool_new(size_t, size_t);
51 extern void mp_pool_clean(mp_pool_t *, int, int);
52 extern void mp_pool_destroy(mp_pool_t *);
53 extern void mp_pool_assert_ok(mp_pool_t *);
54 extern void mp_pool_log_status(mp_pool_t *);
55 extern void mp_pool_garbage_collect(void *);
56
57 #define MEMPOOL_STATS
58
59 struct mp_pool_t
60 {
61 /** Next pool. A pool is usually linked into the mp_allocated_pools list. */
62 mp_pool_t *next;
63
64 /** Doubly-linked list of chunks in which no items have been allocated.
65 * The front of the list is the most recently emptied chunk. */
66 struct mp_chunk_t *empty_chunks;
67
68 /** Doubly-linked list of chunks in which some items have been allocated,
69 * but which are not yet full. The front of the list is the chunk that has
70 * most recently been modified. */
71 struct mp_chunk_t *used_chunks;
72
73 /** Doubly-linked list of chunks in which no more items can be allocated.
74 * The front of the list is the chunk that has most recently become full. */
75 struct mp_chunk_t *full_chunks;
76
77 /** Length of <b>empty_chunks</b>. */
78 int n_empty_chunks;
79
80 /** Lowest value of <b>empty_chunks</b> since last call to
81 * mp_pool_clean(-1). */
82 int min_empty_chunks;
83
84 /** Size of each chunk (in items). */
85 int new_chunk_capacity;
86
87 /** Size of each item */
88 size_t item_size;
89
90 /** Size to allocate for each item, including overhead and alignment
91 * padding. */
92 size_t item_alloc_size;
93 #ifdef MEMPOOL_STATS
94 /** Total number of items allocated ever. */
95 uint64_t total_items_allocated;
96
97 /** Total number of chunks allocated ever. */
98 uint64_t total_chunks_allocated;
99
100 /** Total number of chunks freed ever. */
101 uint64_t total_chunks_freed;
102 #endif
103 };
104 #endif

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision