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:
Bill Currie 2013-03-08 22:16:31 +09:00
parent dbdfdb6d28
commit ca0b03687f
16 changed files with 51 additions and 50 deletions

View file

@ -42,14 +42,15 @@
#ifndef DEBUG_QF_MEMORY #ifndef DEBUG_QF_MEMORY
/** High-tide structure allocator for use in linked lists. /** 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. 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. 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 s The number of structures in the block.
\param t The structure type. \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 \param v The destination of the pointer to the allocated
element. The contents of the allocated element will be element. The contents of the allocated element will be
memset to 0. memset to 0.
@ -58,34 +59,34 @@
*/ */
#define ALLOC(s, t, n, v) \ #define ALLOC(s, t, n, v) \
do { \ do { \
if (!free_##n) { \ if (!n##_freelist) { \
int i; \ int i; \
free_##n = malloc ((s) * sizeof (t)); \ n##_freelist = malloc ((s) * sizeof (t)); \
for (i = 0; i < (s) - 1; i++) \ for (i = 0; i < (s) - 1; i++) \
free_##n[i].next = &free_##n[i + 1];\ n##_freelist[i].next = &n##_freelist[i + 1];\
free_##n[i].next = 0; \ n##_freelist[i].next = 0; \
} \ } \
v = free_##n; \ v = n##_freelist; \
free_##n = free_##n->next; \ n##_freelist = n##_freelist->next; \
memset (v, 0, sizeof (*v)); \ memset (v, 0, sizeof (*v)); \
} while (0) } while (0)
/** Free a block allocated by #ALLOC /** 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. \param p The pointer to the block to be freed.
\hideinitializer \hideinitializer
*/ */
#define FREE(n, p) \ #define FREE(n, p) \
do { \ do { \
p->next = free_##n; \ p->next = n##_freelist; \
free_##n = p; \ n##_freelist = p; \
} while (0) } while (0)
#else #else
#define ALLOC(s, t, n, v) \ #define ALLOC(s, t, n, v) \
do { \ do { \
__attribute__((unused)) t **dummy = &free_##n; \ __attribute__((unused)) t **dummy = &n##_freelist; \
v = (t *) calloc (1, sizeof (t)); \ v = (t *) calloc (1, sizeof (t)); \
} while (0) } while (0)

View file

@ -47,8 +47,8 @@
#define BITS (sizeof (((set_t *) 0)->map[0]) * 8) #define BITS (sizeof (((set_t *) 0)->map[0]) * 8)
set_t *free_sets; set_t *sets_freelist;
set_iter_t *free_set_iters; set_iter_t *set_iters_freelist;
static set_iter_t * static set_iter_t *
new_setiter (void) new_setiter (void)

View file

@ -58,9 +58,9 @@
#include "type.h" #include "type.h"
#include "value.h" #include "value.h"
static daglabel_t *free_labels; static daglabel_t *labels_freelist;
static dagnode_t *free_nodes; static dagnode_t *nodes_freelist;
static dag_t *free_dags; static dag_t *dags_freelist;
static daglabel_t *daglabel_chain; static daglabel_t *daglabel_chain;

View file

@ -52,7 +52,7 @@
int lineno_base; int lineno_base;
static srcline_t *free_srclines; static srcline_t *srclines_freelist;
static void static void
push_source_file (void) push_source_file (void)

View file

@ -62,7 +62,7 @@
#include "type.h" #include "type.h"
#include "value.h" #include "value.h"
static def_t *free_defs; static def_t *defs_freelist;
static void static void
set_storage_bits (def_t *def, storage_class_t storage) set_storage_bits (def_t *def, storage_class_t storage)

View file

@ -60,8 +60,8 @@ typedef struct locref_s {
int size; int size;
} locref_t; } locref_t;
static defspace_t *free_spaces; static defspace_t *spaces_freelist;
static locref_t *free_locrefs; static locref_t *locrefs_freelist;
#define GROW 1024 #define GROW 1024

View file

@ -65,7 +65,7 @@
#include "value.h" #include "value.h"
#include "qc-parse.h" #include "qc-parse.h"
static expr_t *free_exprs; static expr_t *exprs_freelist;
type_t *ev_types[ev_type_count] = { type_t *ev_types[ev_type_count] = {
&type_void, &type_void,

View file

@ -57,10 +57,10 @@
#include "symtab.h" #include "symtab.h"
#include "type.h" #include "type.h"
static flowvar_t *free_vars; static flowvar_t *vars_freelist;
static flowloop_t *free_loops; static flowloop_t *loops_freelist;
static flownode_t *free_nodes; static flownode_t *nodes_freelist;
static flowgraph_t *free_graphs; static flowgraph_t *graphs_freelist;
static struct { static struct {
const char *name; const char *name;

View file

@ -65,8 +65,8 @@
#include "type.h" #include "type.h"
#include "value.h" #include "value.h"
static param_t *free_params; static param_t *params_freelist;
static function_t *free_functions; static function_t *functions_freelist;
static hashtab_t *overloaded_functions; static hashtab_t *overloaded_functions;
static hashtab_t *function_map; static hashtab_t *function_map;

View file

@ -64,7 +64,7 @@ typedef struct frame_s {
int num; int num;
} frame_t; } frame_t;
static frame_t *free_frames; static frame_t *frames_freelist;
static frame_t *frame_list; static frame_t *frame_list;
static frame_t **frame_tail = &frame_list; static frame_t **frame_tail = &frame_list;

View file

@ -131,7 +131,7 @@ static builtin_sym_t builtin_symbols[] __attribute__ ((used)) = {
static const int num_builtins = sizeof (builtin_symbols) static const int num_builtins = sizeof (builtin_symbols)
/ sizeof (builtin_symbols[0]); / sizeof (builtin_symbols[0]);
static defref_t *free_defrefs; static defref_t *defrefs_freelist;
static hashtab_t *extern_data_defs; static hashtab_t *extern_data_defs;
static hashtab_t *defined_data_defs; static hashtab_t *defined_data_defs;

View file

@ -51,7 +51,7 @@
#include "qfcc.h" #include "qfcc.h"
#include "reloc.h" #include "reloc.h"
static reloc_t *free_refs; static reloc_t *refs_freelist;
static const char *reloc_name[] = { static const char *reloc_name[] = {
"rel_none", "rel_none",

View file

@ -227,9 +227,9 @@ print_statement (statement_t *s)
printf (")\n"); printf (")\n");
} }
static sblock_t *free_sblocks; static sblock_t *sblocks_freelist;
static statement_t *free_statements; static statement_t *statements_freelist;
static operand_t *free_operands; static operand_t *operands_freelist;
sblock_t * sblock_t *
new_sblock (void) new_sblock (void)

View file

@ -48,8 +48,8 @@
#include "symtab.h" #include "symtab.h"
#include "type.h" #include "type.h"
static symtab_t *free_symtabs; static symtab_t *symtabs_freelist;
static symbol_t *free_symbols; static symbol_t *symbols_freelist;
static const char *sy_type_names[] = { static const char *sy_type_names[] = {
"sy_var", "sy_var",

View file

@ -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}} }; type_t type_floatfield = { ev_field, ".float", ty_none, {{&type_float}} };
static type_t *free_types; static type_t *types_freelist;
etype_t etype_t
low_level_type (type_t *type) low_level_type (type_t *type)

View file

@ -73,7 +73,7 @@ typedef struct {
} immediate_t; } immediate_t;
static hashtab_t *value_table; static hashtab_t *value_table;
static ex_value_t *free_values; static ex_value_t *values_freelist;
static uintptr_t static uintptr_t
value_get_hash (const void *_val, void *unused) value_get_hash (const void *_val, void *unused)