--- libelwix/inc/elwix/ampool.h 2013/01/17 10:05:35 1.1.1.1 +++ libelwix/inc/elwix/ampool.h 2022/10/23 23:46:01 1.5.68.1 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: ampool.h,v 1.1.1.1 2013/01/17 10:05:35 misho Exp $ +* $Id: ampool.h,v 1.5.68.1 2022/10/23 23:46:01 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -12,7 +12,7 @@ terms: All of the documentation and software included in the ELWIX and AITNET Releases is copyrighted by ELWIX - Sofia/Bulgaria -Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 +Copyright 2004 - 2022 by Michael Pounov . All rights reserved. Redistribution and use in source and binary forms, with or without @@ -79,6 +79,7 @@ typedef struct _tagMPool { } pool_bytes; struct { unsigned long max; + unsigned long real; unsigned long curr; } pool_quota; @@ -89,7 +90,8 @@ typedef struct _tagMPool { #define mpool_lock(x) (assert((x)), pthread_mutex_lock(&(x)->pool_mtx)) #define mpool_unlock(x) (assert((x)), pthread_mutex_unlock(&(x)->pool_mtx)) -typedef void (*mpool_stat_cb)(unsigned int, unsigned int, unsigned int); +typedef int (*mpool_stat_cb)(unsigned int, unsigned int, unsigned int, + void *, unsigned int); /* mpool functions */ @@ -171,21 +173,21 @@ char *mpool_strdup(mpool_t * __restrict mp, const char * @memname = Memory name * return: NULL error or not found and !=NULL allocated memory */ -inline struct tagAlloc *mpool_getmembynam(mpool_t * __restrict mp, unsigned int size, const char *memname); +struct tagAlloc *mpool_getmembynam(mpool_t * __restrict mp, unsigned int size, const char *memname); /* * mpool_getsizebyaddr() - Get size of allocated memory block by address * * @data = allocated memory from mpool_malloc() * return: usable size of allocated memory block */ -inline unsigned int mpool_getsizebyaddr(void * __restrict data); +unsigned int mpool_getsizebyaddr(void * __restrict data); /* * mpool_chkaddr() - Check validity of given address * * @data = allocated memory from mpool_malloc() * return: -1 bad address, 1 corrupted address or 0 ok */ -inline int mpool_chkaddr(void * __restrict data); +int mpool_chkaddr(void * __restrict data); /* * mpool_setquota() - Change maximum memory quota * @@ -193,25 +195,27 @@ inline int mpool_chkaddr(void * __restrict data); * @maxmem = New max quota size * return: old maximum memory quota size */ -inline unsigned long mpool_setquota(mpool_t * __restrict mp, unsigned long maxmem); +unsigned long mpool_setquota(mpool_t * __restrict mp, unsigned long maxmem); /* * mpool_getquota() - Get memory quota * * @mp = Memory pool - * @currmem = Return current memory + * @currmem = Return current memory usage + * @realmem = Return current real memory usage * @maxmem = Return max quota size * return: none */ -inline void mpool_getquota(mpool_t * __restrict mp, unsigned long *currmem, - unsigned long *maxmem); +void mpool_getquota(mpool_t * __restrict mp, unsigned long *currmem, + unsigned long *realmem, unsigned long *maxmem); /* * mpool_statistics() - Dump statistics from memory pool buckets * * @mp = Memory pool * @cb = Export statistics to callback - * return: none + * return: -1 error or >0 bytes in data buffer */ -void mpool_statistics(mpool_t * __restrict mp, mpool_stat_cb cb); +int mpool_statistics(mpool_t * __restrict mp, mpool_stat_cb cb, + void *data, unsigned int datlen); /* Wrappers */ @@ -253,6 +257,33 @@ void mpool_xfree(void * __restrict data); * return: =NULL error or !=NULL new allocated string */ char *mpool_xstrdup(const char *str); +/* + * mpool_xstatistics() - elwix default memory pool statistics wrapper + * + * @cb = Export statistics to callback + * @data = data buffer + * @datlen = data buffer length + * return: -1 error or >0 bytes in data buffer + */ +int mpool_xstatistics(mpool_stat_cb cb, void *data, unsigned int datlen); +/* + * mpool_dump() - Dump elwix memory pool statistics + * + * @mp = memory pool, if =NULL dump elwix default memory pool + * @fmt = prefix info format string + * @... = argument(s) + * return: none + */ +void mpool_dump(mpool_t * __restrict mp, const char *fmt, ...); +/* + * mpool_dump2() - Dump elwix memory pool statistics to string + * + * @mp = memory pool, if =NULL dump elwix default memory pool + * @str = string buffer + * @strlen = string buffer length + * return: >0 data in string buffer + */ +int mpool_dump2(mpool_t * __restrict mp, char *str, int strlen); #endif