gdsa: Include "dsa.h" for dsa_h2n.
[u/mdw/catacomb] / mparena.h
CommitLineData
d3409d5e 1/* -*-c-*-
2 *
b817bfc6 3 * $Id: mparena.h,v 1.4 2004/04/08 01:36:15 mdw Exp $
d3409d5e 4 *
5 * Allocation and freeing of MP buffers
6 *
7 * (c) 1999 Straylight/Edgeware
8 */
9
45c0fd36 10/*----- Licensing notice --------------------------------------------------*
d3409d5e 11 *
12 * This file is part of Catacomb.
13 *
14 * Catacomb is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU Library General Public License as
16 * published by the Free Software Foundation; either version 2 of the
17 * License, or (at your option) any later version.
45c0fd36 18 *
d3409d5e 19 * Catacomb is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Library General Public License for more details.
45c0fd36 23 *
d3409d5e 24 * You should have received a copy of the GNU Library General Public
25 * License along with Catacomb; if not, write to the Free
26 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
27 * MA 02111-1307, USA.
28 */
29
97d21728 30#ifndef CATACOMB_MPARENA_H
31#define CATACOMB_MPARENA_H
d3409d5e 32
33#ifdef __cplusplus
34 extern "C" {
35#endif
36
37/*----- Header files ------------------------------------------------------*/
38
d4745354 39#include <mLib/arena.h>
40
97d21728 41#ifndef CATACOMB_MPW_H
d3409d5e 42# include "mpw.h"
43#endif
44
45/*----- Data structures ---------------------------------------------------*/
46
47/* --- @mparena_node@ --- *
48 *
49 * For internal use by the MP arena manager. The free blocks are held in a
50 * binary tree by size, held in the first digit of each vector.
51 */
52
53typedef struct mparena_node {
54 struct mparena_node *left, *right;
55 mpw *v;
56} mparena_node;
57
58/* --- @mparena@ --- *
59 *
60 * The actual arena.
61 */
62
63typedef struct mparena {
64 mparena_node *root;
97d21728 65 unsigned n;
d4745354 66 arena *a;
d3409d5e 67} mparena;
68
d4745354 69/*----- Standard arenas ---------------------------------------------------*/
d3409d5e 70
d4745354 71extern mparena mparena_global;
72#define MPARENA_GLOBAL (&mparena_global)
d3409d5e 73
d4745354 74extern mparena mparena_secure;
75#define MPARENA_SECURE (&mparena_secure)
d3409d5e 76
77/*----- Functions provided ------------------------------------------------*/
78
79/* --- @mparena_create@ --- *
80 *
81 * Arguments: @mparena *a@ = pointer to arena block
82 *
83 * Returns: ---
84 *
85 * Use: Initializes an MP arena so that blocks can be allocated from
86 * it.
87 */
88
89extern void mparena_create(mparena */*a*/);
90
d4745354 91#define MPARENA_INIT { 0, 0, &arena_stdlib }
d3409d5e 92
d4745354 93/* --- @mparena_setarena@ --- *
d3409d5e 94 *
d4745354 95 * Arguments: @mparena *a@ = pointer to MP arena block
96 * @arena *aa@ = pointer to arena
d3409d5e 97 *
d4745354 98 * Returns: ---
d3409d5e 99 *
d4745354 100 * Use: Sets the underlying arena for an MP arena.
d3409d5e 101 */
102
d4745354 103extern void mparena_setarena(mparena */*a*/, arena */*aa*/);
d3409d5e 104
105/* --- @mparena_destroy@ --- *
106 *
107 * Arguments: @mparena *a@ = pointer to arena block
108 *
109 * Returns: ---
110 *
111 * Use: Frees an MP arena, and all the vectors held within it. The
112 * blocks which are currently allocated can be freed into some
d4745354 113 * other MP arena, as long as the underlying arenas are the
114 * same.
d3409d5e 115 */
116
117extern void mparena_destroy(mparena */*a*/);
118
97d21728 119/* --- @mparena_count@ --- *
120 *
121 * Arguments: @mparena *a@ = pointer to arena block
122 *
123 * Returns: Number of allocated blocks from this arena.
124 *
125 * Use: Reports the number of blocks allocated from the arena and not
126 * yet freed.
127 */
128
129extern unsigned mparena_count(mparena */*a*/);
130
d3409d5e 131/* --- @mpalloc@ --- *
132 *
133 * Arguments: @mparena *a@ = pointer to arena block
134 * @size_t sz@ = number of digits required
135 *
136 * Returns: Pointer to a suitably sized block.
137 *
138 * Use: Allocates a lump of data suitable for use as an array of MP
139 * digits.
140 */
141
142extern mpw *mpalloc(mparena */*a*/, size_t /*sz*/);
143
144/* --- @mpfree@ --- *
145 *
146 * Arguments: @mparena *a@ = pointer to arena block
147 * @mpw *v@ = pointer to allocated vector
148 *
149 * Returns: ---
150 *
97d21728 151 * Use: Returns an MP vector to an arena.
d3409d5e 152 */
153
154extern void mpfree(mparena */*a*/, mpw */*v*/);
155
156/*----- That's all, folks -------------------------------------------------*/
157
158#ifdef __cplusplus
159 }
160#endif
161
162#endif