X-Git-Url: http://git.squeep.com/?p=allocwithin;a=blobdiff_plain;f=allocwithin_int.h;fp=allocwithin_int.h;h=720164d78b7994f42b90cfe88028f2c584988fc3;hp=0000000000000000000000000000000000000000;hb=62af9ffd1e795491f74b07db73ad240079a0e5af;hpb=966b5d9bd5be10b5a6095aeb649d442cd6c7c901 diff --git a/allocwithin_int.h b/allocwithin_int.h new file mode 100644 index 0000000..720164d --- /dev/null +++ b/allocwithin_int.h @@ -0,0 +1,62 @@ +#ifndef __ALLOCWITHIN_INT_H__ +#define __ALLOCWITHIN_INT_H__ + +/** + * $Id$ +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_UNISTD_H +#include +#endif +#ifdef HAVE_SIGNAL_H +#include +#endif +#ifdef HAVE_LIBPTHREAD +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif +#ifdef STDC_HEADERS +#include +#include +#endif + +#include "allocwithin.h" + +#ifdef HAVE___ATTRIBUTE__ +#define UNUSED __attribute__((__unused__)) +#endif + +struct allocw_block_ +{ + size_t size; /* total bytes of this block, including this header struct */ + allocw_id_t next_off; /* byte-offset of next block, from start-of-region */ + allocw_id_t prev_off; /* byte-offset of prev block, from start-of-region */ + char data_[]; /* user data follows this header struct */ +}; + +struct allocw_region_ +{ + size_t size; /* total bytes of this region, including this header struct */ + allocw_id_t free_start; /* first free block */ + allocw_id_t free_end; /* last free block */ + pthread_mutex_t freelist_mutex; /* mutex for accessing freelist */ + unsigned int num_alloced; /* number of outstanding allocations */ + char data_[]; /* blocks follow this header struct */ +}; + +/* convert an id into a region to a pointer */ +#define BLOCK_PTR(__region, __id) ( (struct allocw_block_ *)((char *)(__region) + (__id)) ) + +/* convert a pointer to a block in a region to an id */ +#define BLOCK_OFF(__region, __block) ( (void *)(__block) - (void *)(__region) ) + +#endif /* __ALLOCWITHIN_INT_H__ */