--- libaitio/inc/aitio.h 2012/02/02 15:32:02 1.13.2.12 +++ 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.12 2012/02/02 15:32:02 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 @@ -78,6 +78,41 @@ typedef struct _tagArray { 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 ... */ typedef struct _tagURLItem { @@ -1021,6 +1056,23 @@ FILE *io_fmemopen(void ** __restrict base, off_t bases * return: NULL error or !=NULL Opened file resource */ FILE *io_fmapopen(const char *csFile, int mode, int perm, int prot, int flags, off_t offset); +/* + * io_fd2buf() Convert open file handle to buffered file I/O + * + * @fd = File handle + * @mode = Permissions for new buffered file I/O + * return: NULL error or open buffered file + */ +inline FILE *io_fd2buf(int fd, const char *mode); +/* + * io_dumbFile() Create empry or dumb file with fixed size + * + * @csFile = Filename for create + * @mode = File access permissions + * @size = File size + * return: -1 error or open file handle + */ +int io_dumbFile(const char *csFile, int mode, off_t size); #endif