mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-01-18 15:01:41 +00:00
Change the naming of ALLOC's free-list.
Rather than prefixing free_ to the supplied name, suffix _freelist to the supplied name. The biggest advantage of this is it allows the free-list to be a structure member. It also cleans up the name-space a little.
This commit is contained in:
parent
dbdfdb6d28
commit
ca0b03687f
16 changed files with 51 additions and 50 deletions
|
@ -42,51 +42,52 @@
|
|||
#ifndef DEBUG_QF_MEMORY
|
||||
/** High-tide structure allocator for use in linked lists.
|
||||
|
||||
Using a free-list with the name of \c free_NAME, return a single element.
|
||||
Using a free-list with the name of \c NAME_freelist, return a single
|
||||
element.
|
||||
The type of the element must be a structure with a field named \c next.
|
||||
When the free-list is empty, memory is claimed from the system in blocks.
|
||||
elements may be returned to the pool by linking them into the free-list.
|
||||
Elements may be returned to the pool by linking them into the free-list.
|
||||
|
||||
\param s The number of structures in the block.
|
||||
\param t The structure type.
|
||||
\param n The \c NAME portion of the \c free_NAME free-list.
|
||||
\param n The \c NAME portion of the \c NAME_freelist free-list.
|
||||
\param v The destination of the pointer to the allocated
|
||||
element. The contents of the allocated element will be
|
||||
memset to 0.
|
||||
|
||||
\hideinitializer
|
||||
*/
|
||||
#define ALLOC(s, t, n, v) \
|
||||
do { \
|
||||
if (!free_##n) { \
|
||||
int i; \
|
||||
free_##n = malloc ((s) * sizeof (t)); \
|
||||
for (i = 0; i < (s) - 1; i++) \
|
||||
free_##n[i].next = &free_##n[i + 1];\
|
||||
free_##n[i].next = 0; \
|
||||
} \
|
||||
v = free_##n; \
|
||||
free_##n = free_##n->next; \
|
||||
memset (v, 0, sizeof (*v)); \
|
||||
#define ALLOC(s, t, n, v) \
|
||||
do { \
|
||||
if (!n##_freelist) { \
|
||||
int i; \
|
||||
n##_freelist = malloc ((s) * sizeof (t)); \
|
||||
for (i = 0; i < (s) - 1; i++) \
|
||||
n##_freelist[i].next = &n##_freelist[i + 1];\
|
||||
n##_freelist[i].next = 0; \
|
||||
} \
|
||||
v = n##_freelist; \
|
||||
n##_freelist = n##_freelist->next; \
|
||||
memset (v, 0, sizeof (*v)); \
|
||||
} while (0)
|
||||
|
||||
/** Free a block allocated by #ALLOC
|
||||
|
||||
\param n The \c NAME portion of the \c free_NAME free-list.
|
||||
\param n The \c NAME portion of the \c NAME_freelist free-list.
|
||||
\param p The pointer to the block to be freed.
|
||||
|
||||
\hideinitializer
|
||||
*/
|
||||
#define FREE(n, p) \
|
||||
do { \
|
||||
p->next = free_##n; \
|
||||
free_##n = p; \
|
||||
#define FREE(n, p) \
|
||||
do { \
|
||||
p->next = n##_freelist; \
|
||||
n##_freelist = p; \
|
||||
} while (0)
|
||||
#else
|
||||
#define ALLOC(s, t, n, v) \
|
||||
do { \
|
||||
__attribute__((unused)) t **dummy = &free_##n; \
|
||||
v = (t *) calloc (1, sizeof (t)); \
|
||||
#define ALLOC(s, t, n, v) \
|
||||
do { \
|
||||
__attribute__((unused)) t **dummy = &n##_freelist; \
|
||||
v = (t *) calloc (1, sizeof (t)); \
|
||||
} while (0)
|
||||
|
||||
#define FREE(n, p) do { free (p); } while (0)
|
||||
|
|
|
@ -47,8 +47,8 @@
|
|||
|
||||
#define BITS (sizeof (((set_t *) 0)->map[0]) * 8)
|
||||
|
||||
set_t *free_sets;
|
||||
set_iter_t *free_set_iters;
|
||||
set_t *sets_freelist;
|
||||
set_iter_t *set_iters_freelist;
|
||||
|
||||
static set_iter_t *
|
||||
new_setiter (void)
|
||||
|
|
|
@ -58,9 +58,9 @@
|
|||
#include "type.h"
|
||||
#include "value.h"
|
||||
|
||||
static daglabel_t *free_labels;
|
||||
static dagnode_t *free_nodes;
|
||||
static dag_t *free_dags;
|
||||
static daglabel_t *labels_freelist;
|
||||
static dagnode_t *nodes_freelist;
|
||||
static dag_t *dags_freelist;
|
||||
|
||||
static daglabel_t *daglabel_chain;
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@
|
|||
|
||||
int lineno_base;
|
||||
|
||||
static srcline_t *free_srclines;
|
||||
static srcline_t *srclines_freelist;
|
||||
|
||||
static void
|
||||
push_source_file (void)
|
||||
|
|
|
@ -62,7 +62,7 @@
|
|||
#include "type.h"
|
||||
#include "value.h"
|
||||
|
||||
static def_t *free_defs;
|
||||
static def_t *defs_freelist;
|
||||
|
||||
static void
|
||||
set_storage_bits (def_t *def, storage_class_t storage)
|
||||
|
|
|
@ -60,8 +60,8 @@ typedef struct locref_s {
|
|||
int size;
|
||||
} locref_t;
|
||||
|
||||
static defspace_t *free_spaces;
|
||||
static locref_t *free_locrefs;
|
||||
static defspace_t *spaces_freelist;
|
||||
static locref_t *locrefs_freelist;
|
||||
|
||||
#define GROW 1024
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@
|
|||
#include "value.h"
|
||||
#include "qc-parse.h"
|
||||
|
||||
static expr_t *free_exprs;
|
||||
static expr_t *exprs_freelist;
|
||||
|
||||
type_t *ev_types[ev_type_count] = {
|
||||
&type_void,
|
||||
|
|
|
@ -57,10 +57,10 @@
|
|||
#include "symtab.h"
|
||||
#include "type.h"
|
||||
|
||||
static flowvar_t *free_vars;
|
||||
static flowloop_t *free_loops;
|
||||
static flownode_t *free_nodes;
|
||||
static flowgraph_t *free_graphs;
|
||||
static flowvar_t *vars_freelist;
|
||||
static flowloop_t *loops_freelist;
|
||||
static flownode_t *nodes_freelist;
|
||||
static flowgraph_t *graphs_freelist;
|
||||
|
||||
static struct {
|
||||
const char *name;
|
||||
|
|
|
@ -65,8 +65,8 @@
|
|||
#include "type.h"
|
||||
#include "value.h"
|
||||
|
||||
static param_t *free_params;
|
||||
static function_t *free_functions;
|
||||
static param_t *params_freelist;
|
||||
static function_t *functions_freelist;
|
||||
static hashtab_t *overloaded_functions;
|
||||
static hashtab_t *function_map;
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ typedef struct frame_s {
|
|||
int num;
|
||||
} frame_t;
|
||||
|
||||
static frame_t *free_frames;
|
||||
static frame_t *frames_freelist;
|
||||
static frame_t *frame_list;
|
||||
static frame_t **frame_tail = &frame_list;
|
||||
|
||||
|
|
|
@ -131,7 +131,7 @@ static builtin_sym_t builtin_symbols[] __attribute__ ((used)) = {
|
|||
static const int num_builtins = sizeof (builtin_symbols)
|
||||
/ sizeof (builtin_symbols[0]);
|
||||
|
||||
static defref_t *free_defrefs;
|
||||
static defref_t *defrefs_freelist;
|
||||
|
||||
static hashtab_t *extern_data_defs;
|
||||
static hashtab_t *defined_data_defs;
|
||||
|
|
|
@ -51,7 +51,7 @@
|
|||
#include "qfcc.h"
|
||||
#include "reloc.h"
|
||||
|
||||
static reloc_t *free_refs;
|
||||
static reloc_t *refs_freelist;
|
||||
|
||||
static const char *reloc_name[] = {
|
||||
"rel_none",
|
||||
|
|
|
@ -227,9 +227,9 @@ print_statement (statement_t *s)
|
|||
printf (")\n");
|
||||
}
|
||||
|
||||
static sblock_t *free_sblocks;
|
||||
static statement_t *free_statements;
|
||||
static operand_t *free_operands;
|
||||
static sblock_t *sblocks_freelist;
|
||||
static statement_t *statements_freelist;
|
||||
static operand_t *operands_freelist;
|
||||
|
||||
sblock_t *
|
||||
new_sblock (void)
|
||||
|
|
|
@ -48,8 +48,8 @@
|
|||
#include "symtab.h"
|
||||
#include "type.h"
|
||||
|
||||
static symtab_t *free_symtabs;
|
||||
static symbol_t *free_symbols;
|
||||
static symtab_t *symtabs_freelist;
|
||||
static symbol_t *symbols_freelist;
|
||||
|
||||
static const char *sy_type_names[] = {
|
||||
"sy_var",
|
||||
|
|
|
@ -88,7 +88,7 @@ type_t type_type_encodings = { ev_invalid, "@type_encodings", ty_struct };
|
|||
|
||||
type_t type_floatfield = { ev_field, ".float", ty_none, {{&type_float}} };
|
||||
|
||||
static type_t *free_types;
|
||||
static type_t *types_freelist;
|
||||
|
||||
etype_t
|
||||
low_level_type (type_t *type)
|
||||
|
|
|
@ -73,7 +73,7 @@ typedef struct {
|
|||
} immediate_t;
|
||||
|
||||
static hashtab_t *value_table;
|
||||
static ex_value_t *free_values;
|
||||
static ex_value_t *values_freelist;
|
||||
|
||||
static uintptr_t
|
||||
value_get_hash (const void *_val, void *unused)
|
||||
|
|
Loading…
Reference in a new issue