summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/balloc.h82
-rw-r--r--include/mempool.h99
2 files changed, 99 insertions, 82 deletions
diff --git a/include/balloc.h b/include/balloc.h
deleted file mode 100644
index 7e99788..0000000
--- a/include/balloc.h
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
- *
- * Copyright (C) 2002 by the past and present ircd coders, and others.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- * USA
- */
-
-/*! \file balloc.h
- * \brief A block allocator
- * \version $Id$
- * \todo Get rid of all typedefs in this file
- */
-
-#ifndef INCLUDED_balloc_h
-#define INCLUDED_balloc_h
-
-#include "config.h"
-#include "client.h"
-#include "ircd_defs.h"
-
-
-/*! \brief Block contains status information for
- * an allocated block in our heap.
- */
-struct Block
-{
- int freeElems; /*!< Number of available elems */
- size_t alloc_size; /*!< Size of data space for each block */
- struct Block* next; /*!< Next in our chain of blocks */
- void* elems; /*!< Points to allocated memory */
- dlink_list free_list; /*!< Chain of free memory blocks */
-};
-
-typedef struct Block Block;
-
-struct MemBlock
-{
- dlink_node self; /*!< Node for linking into free_list */
- Block *block; /*!< Which block we belong to */
-};
-
-typedef struct MemBlock MemBlock;
-
-/*! \brief BlockHeap contains the information for the root node of the
- * memory heap.
- */
-struct BlockHeap
-{
- size_t elemSize; /*!< Size of each element to be stored */
- int elemsPerBlock; /*!< Number of elements per block */
- int blocksAllocated; /*!< Number of blocks allocated */
- int freeElems; /*!< Number of free elements */
- Block* base; /*!< Pointer to first block */
- const char *name; /*!< Name of the heap */
- struct BlockHeap *next; /*!< Pointer to next heap */
-};
-
-typedef struct BlockHeap BlockHeap;
-
-
-extern int BlockHeapFree(BlockHeap *, void *);
-extern void * BlockHeapAlloc(BlockHeap *);
-
-extern BlockHeap* BlockHeapCreate(const char *const, size_t, int);
-extern int BlockHeapDestroy(BlockHeap *);
-extern void initBlockHeap(void);
-extern void block_heap_report_stats(struct Client *);
-#endif /* INCLUDED_balloc_h */
diff --git a/include/mempool.h b/include/mempool.h
new file mode 100644
index 0000000..82bc747
--- /dev/null
+++ b/include/mempool.h
@@ -0,0 +1,99 @@
+/*
+ * Copyright (c) 2007-2012, The Tor Project, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * * Neither the names of the copyright owners nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*! \file mempool.h
+ * \brief Pooling allocator
+ * \version $Id: mempool.h 1652 2012-11-13 20:28:53Z michael $
+ */
+
+#ifndef TOR_MEMPOOL_H
+#define TOR_MEMPOOL_H
+
+/** A memory pool is a context in which a large number of fixed-sized
+* objects can be allocated efficiently. See mempool.c for implementation
+* details. */
+typedef struct mp_pool_t mp_pool_t;
+
+extern void mp_pool_init(void);
+extern void *mp_pool_get(mp_pool_t *);
+extern void mp_pool_release(void *);
+extern mp_pool_t *mp_pool_new(size_t, size_t);
+extern void mp_pool_clean(mp_pool_t *, int, int);
+extern void mp_pool_destroy(mp_pool_t *);
+extern void mp_pool_assert_ok(mp_pool_t *);
+extern void mp_pool_log_status(mp_pool_t *);
+extern void mp_pool_garbage_collect(void *);
+
+#define MEMPOOL_STATS
+
+struct mp_pool_t {
+ /** Next pool. A pool is usually linked into the mp_allocated_pools list. */
+ mp_pool_t *next;
+
+ /** Doubly-linked list of chunks in which no items have been allocated.
+ * The front of the list is the most recently emptied chunk. */
+ struct mp_chunk_t *empty_chunks;
+
+ /** Doubly-linked list of chunks in which some items have been allocated,
+ * but which are not yet full. The front of the list is the chunk that has
+ * most recently been modified. */
+ struct mp_chunk_t *used_chunks;
+
+ /** Doubly-linked list of chunks in which no more items can be allocated.
+ * The front of the list is the chunk that has most recently become full. */
+ struct mp_chunk_t *full_chunks;
+
+ /** Length of <b>empty_chunks</b>. */
+ int n_empty_chunks;
+
+ /** Lowest value of <b>empty_chunks</b> since last call to
+ * mp_pool_clean(-1). */
+ int min_empty_chunks;
+
+ /** Size of each chunk (in items). */
+ int new_chunk_capacity;
+
+ /** Size to allocate for each item, including overhead and alignment
+ * padding. */
+ size_t item_alloc_size;
+#ifdef MEMPOOL_STATS
+ /** Total number of items allocated ever. */
+ uint64_t total_items_allocated;
+
+ /** Total number of chunks allocated ever. */
+ uint64_t total_chunks_allocated;
+
+ /** Total number of chunks freed ever. */
+ uint64_t total_chunks_freed;
+#endif
+};
+#endif