gwion-util
utilities for the Gwion project
Loading...
Searching...
No Matches
Data Structures | Typedefs | Functions
symbol.h File Reference

Symbol table. More...

#include "gwion_thread.h"

Go to the source code of this file.

Data Structures

struct  Symbol_
 
struct  SymTable_
 

Typedefs

typedef struct Symbol_Symbol
 
typedef struct SymTable_ SymTable
 

Functions

ANN SymTablenew_symbol_table (MemPool p, const size_t sz)
 
ANN Symbol insert_symbol (SymTable *const, const m_str) __attribute__((pure))
 
 __attribute__ ((pure)) ANN static inline m_str s_name(const Symbol s)
 
ANN void free_symbols (SymTable *const)
 

Detailed Description

Symbol table.

Definition in file symbol.h.

Typedef Documentation

◆ Symbol

typedef struct Symbol_* Symbol

Definition at line 8 of file symbol.h.

◆ SymTable

typedef struct SymTable_ SymTable

Function Documentation

◆ __attribute__()

__attribute__ ( (pure) ) const

Definition at line 23 of file symbol.h.

23 {
24 return s->name;
25};

◆ 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
#define mp_free2(p, sz, a)
Definition mpool.h:28
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
static ANN void free_symbol(MemPool p, const Symbol s)
Definition symbol.c:13
#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)
Symbol next
Definition symbol.h:10
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

◆ 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}
#define mp_malloc2(p, sz)
Definition mpool.h:30
static ANN int gwt_lock_ini(gwtlock_t *lock)
Definition threadpool.h:89