1 /* Copyright (c) 2007-2010, The Tor Project, Inc. */
2 /* See LICENSE for licensing information */
6 * \brief Headers for mempool.c
10 #define _TOR_MEMPOOL_H
12 /** A memory pool is a context in which a large number of fixed-sized
13 * objects can be allocated efficiently. See mempool.c for implementation
15 typedef struct mp_pool_t mp_pool_t
;
17 void *mp_pool_get(mp_pool_t
*pool
);
18 void mp_pool_release(void *item
);
19 mp_pool_t
*mp_pool_new(size_t item_size
, size_t chunk_capacity
);
20 void mp_pool_clean(mp_pool_t
*pool
, int n_to_keep
, int keep_recently_used
);
21 void mp_pool_destroy(mp_pool_t
*pool
);
22 void mp_pool_assert_ok(mp_pool_t
*pool
);
23 void mp_pool_log_status(mp_pool_t
*pool
, int severity
);
27 #ifdef MEMPOOL_PRIVATE
28 /* These declarations are only used by mempool.c and test.c */
31 /** Doubly-linked list of chunks in which no items have been allocated.
32 * The front of the list is the most recently emptied chunk. */
33 struct mp_chunk_t
*empty_chunks
;
34 /** Doubly-linked list of chunks in which some items have been allocated,
35 * but which are not yet full. The front of the list is the chunk that has
36 * most recently been modified. */
37 struct mp_chunk_t
*used_chunks
;
38 /** Doubly-linked list of chunks in which no more items can be allocated.
39 * The front of the list is the chunk that has most recently become full. */
40 struct mp_chunk_t
*full_chunks
;
41 /** Length of <b>empty_chunks</b>. */
43 /** Lowest value of <b>empty_chunks</b> since last call to
44 * mp_pool_clean(-1). */
46 /** Size of each chunk (in items). */
47 int new_chunk_capacity
;
48 /** Size to allocate for each item, including overhead and alignment
50 size_t item_alloc_size
;
52 /** Total number of items allocated ever. */
53 uint64_t total_items_allocated
;
54 /** Total number of chunks allocated ever. */
55 uint64_t total_chunks_allocated
;
56 /** Total number of chunks freed ever. */
57 uint64_t total_chunks_freed
;