gwion-util
utilities for the Gwion project
Loading...
Searching...
No Matches
Macros | Functions
symbol.c File Reference
#include "gwion_util.h"

Go to the source code of this file.

Macros

#define TABLE_SZ(sz)   (sizeof(struct SymTable_) + sz * SZ_INT)
 

Functions

ANN SymTablenew_symbol_table (MemPool p, const size_t sz)
 
static ANN void free_symbol (MemPool p, const Symbol s)
 
ANN void free_symbols (SymTable *const ht)
 
static Symbol mksymbol (MemPool p, const m_str name, const Symbol next)
 
ANN Symbol insert_symbol (SymTable *const ht, const m_str name)
 

Macro Definition Documentation

◆ TABLE_SZ

#define TABLE_SZ ( sz)    (sizeof(struct SymTable_) + sz * SZ_INT)

Definition at line 3 of file symbol.c.

Function Documentation

◆ free_symbol()

static ANN void free_symbol ( MemPool p,
const Symbol s )
static

Definition at line 13 of file symbol.c.

13 {
14 const Symbol next = s->next;
15 mp_free2(p, sizeof(struct Symbol_ *) + strlen(s->name) + 1, s);
16 if (next) free_symbol(p, next);
17}
#define mp_free2(p, sz, a)
Definition mpool.h:28
char name[]
Definition symbol.h:11
Symbol next
Definition symbol.h:10
static ANN void free_symbol(MemPool p, const Symbol s)
Definition symbol.c:13

◆ free_symbols()

ANN void free_symbols ( SymTable *const ht)

Definition at line 19 of file symbol.c.

19 {
21 for (uint i = ht->sz + 1; --i;) {
22 const Symbol s = ht->sym[i - 1];
23 if (s) free_symbol(ht->p, s);
24 }
25 gwt_lock_end(&ht->mutex);
26 mp_free2(ht->p, TABLE_SZ(ht->sz), ht);
27}
unsigned int uint
Definition defs.h:63
#define LOOP_OPTIM
Definition defs.h:34
size_t sz
Definition symbol.h:16
MemPool p
Definition symbol.h:15
gwtlock_t mutex
Definition symbol.h:14
Symbol sym[]
Definition symbol.h:17
#define TABLE_SZ(sz)
Definition symbol.c:3
static ANN void gwt_lock_end(gwtlock_t *lock)
Definition threadpool.h:95

◆ insert_symbol()

ANN Symbol insert_symbol ( SymTable *const ht,
const m_str name )

Definition at line 39 of file symbol.c.

39 {
40 const uint index = hash(name) % ht->sz;
41 const Symbol syms = ht->sym[index];
42 Symbol *const addr = &ht->sym[index];
44 for (Symbol sym = syms; sym; sym = sym->next)
45 if (!strcmp(sym->name, name)) return sym;
46 gwt_lock(&ht->mutex);
47 *addr = mksymbol(ht->p, name, syms);
48 gwt_unlock(&ht->mutex);
49 return ht->sym[index];
50}
ANN unsigned int hash(const m_str s0)
static Symbol mksymbol(MemPool p, const m_str name, const Symbol next)
Definition symbol.c:32
static ANN int gwt_unlock(gwtlock_t *lock)
Definition threadpool.h:74
static ANN int gwt_lock(gwtlock_t *lock)
Definition threadpool.h:71

◆ mksymbol()

static Symbol mksymbol ( MemPool p,
const m_str name,
const Symbol next )
inlinestatic

Definition at line 32 of file symbol.c.

32 {
33 const Symbol s = mp_malloc2(p, sizeof(struct Symbol_ *) + strlen(name) + 1);
34 s->next = next;
35 strcpy(s->name, name);
36 return s;
37}
#define mp_malloc2(p, sz)
Definition mpool.h:30

◆ new_symbol_table()

ANN SymTable * new_symbol_table ( MemPool p,
const size_t sz )

Definition at line 5 of file symbol.c.

5 {
6 SymTable *const st = mp_malloc2(p, TABLE_SZ(sz));
7 st->sz = sz;
9 st->p = p;
10 return st;
11}
static ANN int gwt_lock_ini(gwtlock_t *lock)
Definition threadpool.h:89