--- libaitio/inc/aitio.h 2012/02/02 15:53:40 1.13.2.13 +++ libaitio/inc/aitio.h 2012/02/23 17:09:16 1.14.2.1 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: aitio.h,v 1.13.2.13 2012/02/02 15:53:40 misho Exp $ +* $Id: aitio.h,v 1.14.2.1 2012/02/23 17:09:16 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -77,6 +77,41 @@ typedef struct _tagArray { int arr_num; void **arr_data; } array_t; + +/* Memory pool */ + +struct tagAlloc { + char *alloc_name; + unsigned int *alloc_mem; + SLIST_ENTRY(tagAlloc) alloc_node; +}; +typedef SLIST_HEAD(, tagAlloc) mpool_bucket_t; +#define io_memory(x, _type) (assert((x)), (_type) ((x)->alloc_mem ? ((x)->alloc_mem + 2) : NULL)) +#define io_memorySize(x) (assert((x)), (x)->alloc_mem ? *(x)->alloc_mem : 0) +#define io_memoryZero(x) do { assert((x)); \ + if ((x)->alloc_mem) \ + memset((void*) ((x)->alloc_mem + 2), 0, *(x)->alloc_mem); \ + } while (0) + +typedef struct _tagMPool { + pthread_mutex_t pool_mtx; + + struct { + unsigned long alloc; + unsigned long free; + } pool_calls; + struct { + unsigned long alloc; + unsigned long free; + } pool_bytes; + struct { + unsigned int max; + unsigned int curr; + } pool_res; + + /* pool buckets start from 4k block == 0 position in array */ + mpool_bucket_t pool_bucks[20]; +} mpool_t; /* URL staff ... */