ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-8/include/balloc.h
Revision: 670
Committed: Mon Jun 12 12:20:55 2006 UTC (19 years, 2 months ago) by michael
Content type: text/x-chdr
Original Path: ircd-hybrid-7.2/include/balloc.h
File size: 3006 byte(s)
Log Message:
- balloc.(c|h): backported r544 (Killed Block::used_list)
- Update RELNOTES

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 *
4 * Copyright (C) 2002 by the past and present ircd coders, and others.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19 * USA
20 */
21
22 /*! \file balloc.h
23 * \brief A block allocator
24 * \version $Id$
25 * \todo Get rid of all typedefs in this file
26 */
27
28 #ifndef INCLUDED_balloc_h
29 #define INCLUDED_balloc_h
30
31 #include "setup.h"
32
33 #ifndef NOBALLOC
34 #include "client.h"
35 #include "tools.h"
36 #include "memory.h"
37 #include "ircd_defs.h"
38
39
40 /*! \brief Block contains status information for
41 * an allocated block in our heap.
42 */
43 struct Block {
44 int freeElems; /*!< Number of available elems */
45 size_t alloc_size; /*!< Size of data space for each block */
46 struct Block* next; /*!< Next in our chain of blocks */
47 void* elems; /*!< Points to allocated memory */
48 dlink_list free_list; /*!< Chain of free memory blocks */
49 };
50
51 typedef struct Block Block;
52
53 struct MemBlock {
54 dlink_node self; /*!< Node for linking into free_list or used_list */
55 Block *block; /*!< Which block we belong to */
56 };
57 typedef struct MemBlock MemBlock;
58
59 /*! \brief BlockHeap contains the information for the root node of the
60 * memory heap.
61 */
62 struct BlockHeap {
63 size_t elemSize; /*!< Size of each element to be stored */
64 int elemsPerBlock; /*!< Number of elements per block */
65 int blocksAllocated; /*!< Number of blocks allocated */
66 int freeElems; /*!< Number of free elements */
67 Block* base; /*!< Pointer to first block */
68 const char *name; /*!< Name of the heap */
69 struct BlockHeap *next; /*!< Pointer to next heap */
70 };
71
72 typedef struct BlockHeap BlockHeap;
73
74
75 extern int BlockHeapFree(BlockHeap *, void *);
76 extern void * BlockHeapAlloc(BlockHeap *);
77
78 extern BlockHeap* BlockHeapCreate(const char *const, size_t, int);
79 extern int BlockHeapDestroy(BlockHeap *);
80 extern void initBlockHeap(void);
81 extern void block_heap_report_stats(struct Client *);
82 #else /* NOBALLOC */
83
84 typedef struct BlockHeap BlockHeap;
85 /* This is really kludgy, passing ints as pointers is always bad. */
86 #define BlockHeapCreate(blah, es, epb) ((BlockHeap*)(es))
87 #define BlockHeapAlloc(x) MyMalloc((int)x)
88 #define BlockHeapFree(x,y) MyFree(y)
89 #endif /* NOBALLOC */
90 #endif /* INCLUDED_balloc_h */

Properties

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