diff options
author | Nick Mathewson <nickm@torproject.org> | 2007-04-11 00:30:22 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2007-04-11 00:30:22 +0000 |
commit | d7359eb996218f4492a5583c34ab8ee7d9315e7d (patch) | |
tree | ee45fedecacdfd83bea07a57bbf89cd8fa2c1463 /src/common/mempool.h | |
parent | f95d232483a0e9fd78563bfdc061016baab6ef97 (diff) | |
download | tor-d7359eb996218f4492a5583c34ab8ee7d9315e7d.tar tor-d7359eb996218f4492a5583c34ab8ee7d9315e7d.tar.gz |
r12335@catbus: nickm | 2007-04-10 16:53:48 -0400
Initial version of memory pool logic. Needs unit tests. Made to be easily separable from Tor.
svn:r9937
Diffstat (limited to 'src/common/mempool.h')
-rw-r--r-- | src/common/mempool.h | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/common/mempool.h b/src/common/mempool.h new file mode 100644 index 000000000..45e364681 --- /dev/null +++ b/src/common/mempool.h @@ -0,0 +1,51 @@ +/* Copyright 2007 Nick Mathewson */ +/* See LICENSE for licensing information */ +/* $Id: /tor/trunk/src/common/util.c 12153 2007-03-12T03:11:12.797278Z nickm $ */ + +/** + * \file util.h + * \brief Headers for mempool.c + **/ + +#ifndef MEMPOOL_H +#define MEMPOOL_H + +typedef struct mp_pool_t mp_pool_t; + +void *mp_pool_get(mp_pool_t *pool); +void mp_pool_release(void *item); +mp_pool_t *mp_pool_new(size_t item_size, unsigned int n_per_chunk); +void mp_pool_clean(mp_pool_t *pool); +void mp_pool_destroy(mp_pool_t *pool); + +#ifdef MEMPOOL_PRIVATE +typedef struct mp_allocated_t mp_allocated_t; +typedef struct mp_chunk_t mp_chunk_t; + +/** DOCDOC */ +struct mp_chunk_t { + unsigned long magic; + mp_chunk_t *next; + mp_chunk_t *prev; + mp_pool_t *pool; + mp_allocated_t *first_free; + int n_allocated; + int capacity; + size_t mem_size; + char *next_mem; + char mem[1]; +}; + +/** DOCDOC */ +struct mp_pool_t { + mp_chunk_t *empty_chunks; + mp_chunk_t *used_chunks; + mp_chunk_t *full_chunks; + int n_empty_chunks; + size_t new_chunk_capacity; + size_t item_alloc_size; +}; +#endif + +#endif + |