comparison interps/cfunge/cfunge-src/lib/libghthash/cfunge_mempool.h @ 996:859f9b4339e6

<Gregor> tar xf egobot.tar.xz
author HackBot
date Sun, 09 Dec 2012 19:30:08 +0000
parents
children
comparison
equal deleted inserted replaced
995:6883f5911eb7 996:859f9b4339e6
1 /* -*- mode: C; coding: utf-8; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*-
2 *
3 * cfunge - A standard-conforming Befunge93/98/109 interpreter in C.
4 * Copyright (C) 2008 Arvid Norlander <anmaster AT tele2 DOT se>
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 3 of the License, or
9 * (at the proxy's option) any later version. Arvid Norlander is a
10 * proxy who can decide which future versions of the GNU General Public
11 * License can be used.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22 // This file does not come from libght, however this code is for libght
23 // exclusively.
24
25
26 /**
27 * @file
28 * Mempools are used for allocating Funge-space s_hash_entry.
29 * Since cfunge is single-threaded they are static, and have no locking.
30 *
31 * For implementation details see comments in cfunge_mempool.c.
32 */
33
34 #ifndef FUNGE_HAD_LIB_CFUNGE_MEMPOOL_H
35 #define FUNGE_HAD_LIB_CFUNGE_MEMPOOL_H
36
37 #include "../../src/global.h"
38 #include "../../src/funge-space/funge-space.h"
39
40 #include "ght_hash_table.h"
41
42 #define CF_MEMPOOL_FUNCPROT(m_variant, m_rettype, m_funcname, m_args, m_attrs) \
43 m_attrs m_rettype cf_mempool_ ## m_variant ## _ ## m_funcname m_args
44
45 #define CF_MEMPOOL_DECLARE_FUNCS(m_variant, m_datatype) \
46 CF_MEMPOOL_FUNCPROT(m_variant, bool, setup, (void), FUNGE_ATTR_FAST); \
47 CF_MEMPOOL_FUNCPROT(m_variant, void, teardown, (void), FUNGE_ATTR_FAST); \
48 CF_MEMPOOL_FUNCPROT(m_variant, m_datatype *, alloc, (void), FUNGE_ATTR_FAST FUNGE_ATTR_WARN_UNUSED FUNGE_ATTR_MALLOC); \
49 CF_MEMPOOL_FUNCPROT(m_variant, void, free, (m_datatype *ptr), FUNGE_ATTR_FAST);
50
51
52 #include <stdbool.h>
53
54 #if 0
55 typedef struct s_hash_entry memorypool_data;
56
57 /**
58 * Set up the memory pools. Used at program start.
59 * @return True if successful, otherwise false.
60 */
61 FUNGE_ATTR_FAST
62 bool mempool_setup(void);
63
64 /**
65 * Tear down the memory pools. Used at program exit.
66 */
67 FUNGE_ATTR_FAST
68 void mempool_teardown(void);
69
70 /**
71 * Get a memorypool_data block from the memory pool.
72 * @return A pointer to a memorypool_data, or NULL if allocation failed.
73 */
74 FUNGE_ATTR_FAST FUNGE_ATTR_WARN_UNUSED FUNGE_ATTR_MALLOC
75 memorypool_data *mempool_alloc(void);
76
77 /**
78 * Free a block, returning it to the memory pool.
79 * @param ptr Pointer to memory block allocated with mempool_alloc.
80 */
81 FUNGE_ATTR_FAST
82 void mempool_free(memorypool_data *ptr);
83 #endif
84
85 CF_MEMPOOL_DECLARE_FUNCS(fspace, struct s_fspace_hash_entry)
86 #ifdef CFUN_EXACT_BOUNDS
87 CF_MEMPOOL_DECLARE_FUNCS(fspacecount, struct s_fspacecount_hash_entry)
88 #endif
89
90 #undef CF_MEMPOOL_FUNCPROT
91 #undef CF_MEMPOOL_DECLARE_FUNCS
92
93 #ifdef CF_GHT_INTERNAL
94 # define CF_MEMPOOL_FUNC_INTERN(m_variant, m_funcname) \
95 cf_mempool_ ## m_variant ## _ ## m_funcname
96 # define CF_MEMPOOL_FUNC(m_variant, m_funcname) \
97 CF_MEMPOOL_FUNC_INTERN(m_variant, m_funcname)
98 #endif
99
100 #endif