#ifndef SM_RPOOL_H
# define SM_RPOOL_H
# include <sm/gen.h>
# include <sm/heap.h>
# include <sm/string.h>
typedef struct sm_poollink SM_POOLLINK_T;
struct sm_poollink
{
SM_POOLLINK_T *sm_pnext;
};
typedef void (*SM_RPOOL_RFREE_T) __P((void *_rcontext));
typedef SM_RPOOL_RFREE_T *SM_RPOOL_ATTACH_T;
typedef struct sm_resource SM_RESOURCE_T;
struct sm_resource
{
SM_RPOOL_RFREE_T sm_rfree;
void *sm_rcontext;
};
# define SM_RLIST_MAX 511
typedef struct sm_rlist SM_RLIST_T;
struct sm_rlist
{
SM_RESOURCE_T sm_rvec[SM_RLIST_MAX];
SM_RLIST_T *sm_rnext;
};
typedef struct
{
const char *sm_magic;
SM_RPOOL_RFREE_T *sm_parentlink;
size_t sm_poolsize;
size_t sm_bigobjectsize;
char *sm_poolptr;
size_t sm_poolavail;
SM_POOLLINK_T *sm_pools;
SM_RESOURCE_T *sm_rptr;
size_t sm_ravail;
SM_RLIST_T *sm_rlists;
#if _FFR_PERF_RPOOL
int sm_nbigblocks;
int sm_npools;
#endif
} SM_RPOOL_T;
extern SM_RPOOL_T *
sm_rpool_new_x __P((
SM_RPOOL_T *_parent));
extern void
sm_rpool_free __P((
SM_RPOOL_T *_rpool));
# if SM_HEAP_CHECK
extern void *
sm_rpool_malloc_tagged_x __P((
SM_RPOOL_T *_rpool,
size_t _size,
char *_file,
int _line,
int _group));
# define sm_rpool_malloc_x(rpool, size) \
sm_rpool_malloc_tagged_x(rpool, size, __FILE__, __LINE__, SmHeapGroup)
extern void *
sm_rpool_malloc_tagged __P((
SM_RPOOL_T *_rpool,
size_t _size,
char *_file,
int _line,
int _group));
# define sm_rpool_malloc(rpool, size) \
sm_rpool_malloc_tagged(rpool, size, __FILE__, __LINE__, SmHeapGroup)
# else
extern void *
sm_rpool_malloc_x __P((
SM_RPOOL_T *_rpool,
size_t _size));
extern void *
sm_rpool_malloc __P((
SM_RPOOL_T *_rpool,
size_t _size));
# endif
#if DO_NOT_USE_STRCPY
extern char *sm_rpool_strdup_x __P((SM_RPOOL_T *rpool, const char *s));
#else
# define sm_rpool_strdup_x(rpool, str) \
strcpy(sm_rpool_malloc_x(rpool, strlen(str) + 1), str)
#endif
extern SM_RPOOL_ATTACH_T
sm_rpool_attach_x __P((
SM_RPOOL_T *_rpool,
SM_RPOOL_RFREE_T _rfree,
void *_rcontext));
# define sm_rpool_detach(a) ((void)(*(a) = NULL))
extern void
sm_rpool_setsizes __P((
SM_RPOOL_T *_rpool,
size_t _poolsize,
size_t _bigobjectsize));
#endif