ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/include/mempool.h
Revision: 2865
Committed: Sun Jan 19 14:35:22 2014 UTC (11 years, 7 months ago) by michael
Content type: text/x-chdr
File size: 3653 byte(s)
Log Message:
- Clean up all files in include/ (fixed indentation, removed whitespaces/tabs)
- Fixed copyright years

File Contents

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

Properties

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