0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-12-22 09:41:54 +00:00

Name cleanups as suggested by Pavel:

- cfg_strcpy() -> cfg_strdup()
- mempool -> linpool, mp_* -> lp_*  [to avoid confusion with memblock, mb_*]

Anyway, it might be better to stop ranting about names and do some *real* work.
This commit is contained in:
Martin Mares 1998-12-06 11:59:18 +00:00
parent 2d9290e973
commit b35d72ac66
6 changed files with 43 additions and 43 deletions

View File

@ -38,7 +38,7 @@ static int cf_hash(byte *c);
static struct symbol *cf_find_sym(byte *c, unsigned int h0); static struct symbol *cf_find_sym(byte *c, unsigned int h0);
pool *cfg_pool; pool *cfg_pool;
mempool *cfg_mem; linpool *cfg_mem;
int (*cf_read_hook)(byte *buf, unsigned int max); int (*cf_read_hook)(byte *buf, unsigned int max);
@ -232,11 +232,11 @@ cf_allocate(void)
if (cfg_pool) if (cfg_pool)
rfree(cfg_pool); rfree(cfg_pool);
cfg_pool = rp_new(&root_pool, "Config"); cfg_pool = rp_new(&root_pool, "Config");
cfg_mem = mp_new(cfg_pool, 1024); cfg_mem = lp_new(cfg_pool, 1024);
} }
char * char *
cfg_strcpy(char *c) cfg_strdup(char *c)
{ {
int l = strlen(c) + 1; int l = strlen(c) + 1;
char *z = cfg_allocu(l); char *z = cfg_allocu(l);

View File

@ -14,12 +14,12 @@
/* Pools */ /* Pools */
extern pool *cfg_pool; extern pool *cfg_pool;
extern mempool *cfg_mem; extern linpool *cfg_mem;
#define cfg_alloc(size) mp_alloc(cfg_mem, size) #define cfg_alloc(size) lp_alloc(cfg_mem, size)
#define cfg_allocu(size) mp_allocu(cfg_mem, size) #define cfg_allocu(size) lp_allocu(cfg_mem, size)
#define cfg_allocz(size) mp_allocz(cfg_mem, size) #define cfg_allocz(size) lp_allocz(cfg_mem, size)
char *cfg_strcpy(char *c); char *cfg_strdup(char *c);
/* Lexer */ /* Lexer */

View File

@ -12,32 +12,32 @@
#include "nest/bird.h" #include "nest/bird.h"
#include "lib/resource.h" #include "lib/resource.h"
struct mp_chunk { struct lp_chunk {
struct mp_chunk *next; struct lp_chunk *next;
byte data[0]; byte data[0];
}; };
struct mempool { struct linpool {
resource r; resource r;
byte *ptr, *end; byte *ptr, *end;
struct mp_chunk *first, **plast; struct lp_chunk *first, **plast;
unsigned chunk_size, threshold, total; unsigned chunk_size, threshold, total;
}; };
void mp_free(resource *); void lp_free(resource *);
void mp_dump(resource *); void lp_dump(resource *);
static struct resclass mp_class = { static struct resclass lp_class = {
"MemPool", "LinPool",
sizeof(struct mempool), sizeof(struct linpool),
mp_free, lp_free,
mp_dump lp_dump
}; };
mempool linpool
*mp_new(pool *p, unsigned blk) *lp_new(pool *p, unsigned blk)
{ {
mempool *m = ralloc(p, &mp_class); linpool *m = ralloc(p, &lp_class);
m->ptr = m->end = NULL; m->ptr = m->end = NULL;
m->first = NULL; m->first = NULL;
m->plast = &m->first; m->plast = &m->first;
@ -48,7 +48,7 @@ mempool
} }
void * void *
mp_alloc(mempool *m, unsigned size) lp_alloc(linpool *m, unsigned size)
{ {
byte *a = (byte *) ALIGN((unsigned long) m->ptr, CPU_STRUCT_ALIGN); byte *a = (byte *) ALIGN((unsigned long) m->ptr, CPU_STRUCT_ALIGN);
byte *e = a + size; byte *e = a + size;
@ -60,15 +60,15 @@ mp_alloc(mempool *m, unsigned size)
} }
else else
{ {
struct mp_chunk *c; struct lp_chunk *c;
if (size >= m->threshold) if (size >= m->threshold)
{ {
c = xmalloc(sizeof(struct mp_chunk) + size); c = xmalloc(sizeof(struct lp_chunk) + size);
m->total += size; m->total += size;
} }
else else
{ {
c = xmalloc(sizeof(struct mp_chunk) + m->chunk_size); c = xmalloc(sizeof(struct lp_chunk) + m->chunk_size);
m->ptr = c->data + size; m->ptr = c->data + size;
m->end = c->data + m->chunk_size; m->end = c->data + m->chunk_size;
m->total += m->chunk_size; m->total += m->chunk_size;
@ -81,7 +81,7 @@ mp_alloc(mempool *m, unsigned size)
} }
void * void *
mp_allocu(mempool *m, unsigned size) lp_allocu(linpool *m, unsigned size)
{ {
byte *a = m->ptr; byte *a = m->ptr;
byte *e = a + size; byte *e = a + size;
@ -91,23 +91,23 @@ mp_allocu(mempool *m, unsigned size)
m->ptr = e; m->ptr = e;
return a; return a;
} }
return mp_alloc(m, size); return lp_alloc(m, size);
} }
void * void *
mp_allocz(mempool *m, unsigned size) lp_allocz(linpool *m, unsigned size)
{ {
void *z = mp_alloc(m, size); void *z = lp_alloc(m, size);
bzero(z, size); bzero(z, size);
return z; return z;
} }
void void
mp_free(resource *r) lp_free(resource *r)
{ {
mempool *m = (mempool *) r; linpool *m = (linpool *) r;
struct mp_chunk *c, *d; struct lp_chunk *c, *d;
for(d=m->first; d; d = c) for(d=m->first; d; d = c)
{ {
@ -117,10 +117,10 @@ mp_free(resource *r)
} }
void void
mp_dump(resource *r) lp_dump(resource *r)
{ {
mempool *m = (mempool *) r; linpool *m = (linpool *) r;
struct mp_chunk *c; struct lp_chunk *c;
int cnt; int cnt;
for(cnt=0, c=m->first; c; c=c->next, cnt++) for(cnt=0, c=m->first; c; c=c->next, cnt++)

View File

@ -47,12 +47,12 @@ void mb_free(void *);
/* Memory pools with linear allocation */ /* Memory pools with linear allocation */
typedef struct mempool mempool; typedef struct linpool linpool;
mempool *mp_new(pool *, unsigned blk); linpool *lp_new(pool *, unsigned blk);
void *mp_alloc(mempool *, unsigned size); /* Aligned */ void *lp_alloc(linpool *, unsigned size); /* Aligned */
void *mp_allocu(mempool *, unsigned size); /* Unaligned */ void *lp_allocu(linpool *, unsigned size); /* Unaligned */
void *mp_allocz(mempool *, unsigned size); /* With clear */ void *lp_allocz(linpool *, unsigned size); /* With clear */
/* Slabs */ /* Slabs */

View File

@ -101,7 +101,7 @@ rt_dev_add_iface(char *n)
struct rt_dev_proto *p = (void *) this_proto; struct rt_dev_proto *p = (void *) this_proto;
struct iface_patt *k = cfg_alloc(sizeof(struct iface_patt)); struct iface_patt *k = cfg_alloc(sizeof(struct iface_patt));
k->pattern = cfg_strcpy(n); k->pattern = cfg_strdup(n);
add_tail(&p->iface_list, &k->n); add_tail(&p->iface_list, &k->n);
} }

View File

@ -64,7 +64,7 @@ rip_dev_add_iface(char *n)
{ {
struct iface_patt *k = cfg_alloc(sizeof(struct iface_patt)); struct iface_patt *k = cfg_alloc(sizeof(struct iface_patt));
k->pattern = cfg_strcpy(n); k->pattern = cfg_strdup(n);
add_tail(&THIS_PROTO->iface_list, &k->n); add_tail(&THIS_PROTO->iface_list, &k->n);
} }