X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=lib%2Fpools.h;h=6058c5eefc9549de214660e3df2c7eea22805fb6;hb=1b0a16240bdcc069979452f56fbbf2299625be78;hp=3129c6a7a7bda97bf4ebbbbe4ba5e6382d15f3e5;hpb=9d5027b958e0ed7d2fa2c804fd255d686e8da5a7;p=libucw.git diff --git a/lib/pools.h b/lib/pools.h index 3129c6a7..6058c5ee 100644 --- a/lib/pools.h +++ b/lib/pools.h @@ -1,39 +1,73 @@ /* * Sherlock Library -- Memory Pools * - * (c) 1997 Martin Mares, + * (c) 1997--2004 Martin Mares + * + * This software may be freely distributed and used according to the terms + * of the GNU Lesser General Public License. */ +#ifndef _SHERLOCK_POOLS_H +#define _SHERLOCK_POOLS_H + #ifndef POOL_ALIGN #define POOL_ALIGN CPU_STRUCT_ALIGN #endif struct mempool { - struct memchunk *chunks; byte *free, *last; + struct memchunk *first, *current, **plast; + struct memchunk *first_large; uns chunk_size, threshold; }; -struct mempool *new_pool(uns); -void free_pool(struct mempool *); -void *pool_alloc(struct mempool *, uns); +struct mempool *mp_new(uns); +void mp_delete(struct mempool *); +void mp_flush(struct mempool *); +void *mp_alloc(struct mempool *, uns); +void *mp_alloc_zero(struct mempool *, uns); -extern inline void *fast_alloc(struct mempool *p, uns l) +static inline void *mp_alloc_fast(struct mempool *p, uns l) { - void *f = (void *) (((uns) p->free + POOL_ALIGN - 1) & ~(POOL_ALIGN - 1)); + byte *f = (void *) (((uns) p->free + POOL_ALIGN - 1) & ~(POOL_ALIGN - 1)); byte *ee = f + l; if (ee > p->last) - return pool_alloc(p, l); + return mp_alloc(p, l); p->free = ee; return f; } -extern inline void *fast_alloc_noalign(struct mempool *p, uns l) +static inline void *mp_alloc_fast_noalign(struct mempool *p, uns l) { - void *f = p->free; + byte *f = p->free; byte *ee = f + l; if (ee > p->last) - return pool_alloc(p, l); + return mp_alloc(p, l); p->free = ee; return f; } + +static inline void * +mp_start_string(struct mempool *p, uns l) +{ + ASSERT(l <= p->chunk_size); + return mp_alloc(p, l); +} + +static inline void +mp_end_string(struct mempool *p, void *stop) +{ + p->free = stop; +} + +/* pool-str.c */ + +char *mp_strdup(struct mempool *, char *); +char *mp_multicat(struct mempool *, ...); +static inline char * +mp_strcat(struct mempool *mp, char *x, char *y) +{ + return mp_multicat(mp, x, y, NULL); +} + +#endif