1N/A/*
1N/A * Copyright (c) 2000-2001, 2003 Sendmail, Inc. and its suppliers.
1N/A * All rights reserved.
1N/A *
1N/A * By using this file, you agree to the terms and conditions set
1N/A * forth in the LICENSE file which can be found at the top level of
1N/A * the sendmail distribution.
1N/A *
1N/A * $Id: rpool.h,v 1.16 2003/09/05 23:07:49 ca Exp $
1N/A */
1N/A
1N/A#pragma ident "%Z%%M% %I% %E% SMI"
1N/A
1N/A/*
1N/A** libsm resource pools
1N/A** See libsm/rpool.html for documentation.
1N/A*/
1N/A
1N/A#ifndef SM_RPOOL_H
1N/A# define SM_RPOOL_H
1N/A
1N/A# include <sm/gen.h>
1N/A# include <sm/heap.h>
1N/A# include <sm/string.h>
1N/A
1N/A/*
1N/A** Each memory pool object consists of an SM_POOLLINK_T,
1N/A** followed by a platform specific amount of padding,
1N/A** followed by 'poolsize' bytes of pool data,
1N/A** where 'poolsize' is the value of rpool->sm_poolsize at the time
1N/A** the pool is allocated.
1N/A*/
1N/A
1N/Atypedef struct sm_poollink SM_POOLLINK_T;
1N/Astruct sm_poollink
1N/A{
1N/A SM_POOLLINK_T *sm_pnext;
1N/A};
1N/A
1N/Atypedef void (*SM_RPOOL_RFREE_T) __P((void *_rcontext));
1N/A
1N/Atypedef SM_RPOOL_RFREE_T *SM_RPOOL_ATTACH_T;
1N/A
1N/Atypedef struct sm_resource SM_RESOURCE_T;
1N/Astruct sm_resource
1N/A{
1N/A /*
1N/A ** Function for freeing this resource. It may be NULL,
1N/A ** meaning that this resource has already been freed.
1N/A */
1N/A
1N/A SM_RPOOL_RFREE_T sm_rfree;
1N/A void *sm_rcontext; /* resource data */
1N/A};
1N/A
1N/A# define SM_RLIST_MAX 511
1N/A
1N/Atypedef struct sm_rlist SM_RLIST_T;
1N/Astruct sm_rlist
1N/A{
1N/A SM_RESOURCE_T sm_rvec[SM_RLIST_MAX];
1N/A SM_RLIST_T *sm_rnext;
1N/A};
1N/A
1N/Atypedef struct
1N/A{
1N/A /* Points to SmRpoolMagic, or is NULL if rpool is freed. */
1N/A const char *sm_magic;
1N/A
1N/A /*
1N/A ** If this rpool object has no parent, then sm_parentlink
1N/A ** is NULL. Otherwise, we set *sm_parentlink = NULL
1N/A ** when this rpool is freed, so that it isn't freed a
1N/A ** second time when the parent is freed.
1N/A */
1N/A
1N/A SM_RPOOL_RFREE_T *sm_parentlink;
1N/A
1N/A /*
1N/A ** Memory pools
1N/A */
1N/A
1N/A /* Size of the next pool to be allocated, not including the header. */
1N/A size_t sm_poolsize;
1N/A
1N/A /*
1N/A ** If an sm_rpool_malloc_x request is too big to fit
1N/A ** in the current pool, and the request size > bigobjectsize,
1N/A ** then the object will be given its own malloc'ed block.
1N/A ** sm_bigobjectsize <= sm_poolsize. The maximum wasted space
1N/A ** at the end of a pool is maxpooledobjectsize - 1.
1N/A */
1N/A
1N/A size_t sm_bigobjectsize;
1N/A
1N/A /* Points to next free byte in the current pool. */
1N/A char *sm_poolptr;
1N/A
1N/A /*
1N/A ** Number of bytes available in the current pool.
1N/A ** Initially 0. Set to 0 by sm_rpool_free.
1N/A */
1N/A
1N/A size_t sm_poolavail;
1N/A
1N/A /* Linked list of memory pools. Initially NULL. */
1N/A SM_POOLLINK_T *sm_pools;
1N/A
1N/A /*
1N/A ** Resource lists
1N/A */
1N/A
1N/A SM_RESOURCE_T *sm_rptr; /* Points to next free resource slot. */
1N/A
1N/A /*
1N/A ** Number of available resource slots in current list.
1N/A ** Initially 0. Set to 0 by sm_rpool_free.
1N/A */
1N/A
1N/A size_t sm_ravail;
1N/A
1N/A /* Linked list of resource lists. Initially NULL. */
1N/A SM_RLIST_T *sm_rlists;
1N/A
1N/A#if _FFR_PERF_RPOOL
1N/A int sm_nbigblocks;
1N/A int sm_npools;
1N/A#endif /* _FFR_PERF_RPOOL */
1N/A
1N/A} SM_RPOOL_T;
1N/A
1N/Aextern SM_RPOOL_T *
1N/Asm_rpool_new_x __P((
1N/A SM_RPOOL_T *_parent));
1N/A
1N/Aextern void
1N/Asm_rpool_free __P((
1N/A SM_RPOOL_T *_rpool));
1N/A
1N/A# if SM_HEAP_CHECK
1N/Aextern void *
1N/Asm_rpool_malloc_tagged_x __P((
1N/A SM_RPOOL_T *_rpool,
1N/A size_t _size,
1N/A char *_file,
1N/A int _line,
1N/A int _group));
1N/A# define sm_rpool_malloc_x(rpool, size) \
1N/A sm_rpool_malloc_tagged_x(rpool, size, __FILE__, __LINE__, SmHeapGroup)
1N/Aextern void *
1N/Asm_rpool_malloc_tagged __P((
1N/A SM_RPOOL_T *_rpool,
1N/A size_t _size,
1N/A char *_file,
1N/A int _line,
1N/A int _group));
1N/A# define sm_rpool_malloc(rpool, size) \
1N/A sm_rpool_malloc_tagged(rpool, size, __FILE__, __LINE__, SmHeapGroup)
1N/A# else /* SM_HEAP_CHECK */
1N/Aextern void *
1N/Asm_rpool_malloc_x __P((
1N/A SM_RPOOL_T *_rpool,
1N/A size_t _size));
1N/Aextern void *
1N/Asm_rpool_malloc __P((
1N/A SM_RPOOL_T *_rpool,
1N/A size_t _size));
1N/A# endif /* SM_HEAP_CHECK */
1N/A
1N/A#if DO_NOT_USE_STRCPY
1N/Aextern char *sm_rpool_strdup_x __P((SM_RPOOL_T *rpool, const char *s));
1N/A#else /* DO_NOT_USE_STRCPY */
1N/A# define sm_rpool_strdup_x(rpool, str) \
1N/A strcpy(sm_rpool_malloc_x(rpool, strlen(str) + 1), str)
1N/A#endif /* DO_NOT_USE_STRCPY */
1N/A
1N/Aextern SM_RPOOL_ATTACH_T
1N/Asm_rpool_attach_x __P((
1N/A SM_RPOOL_T *_rpool,
1N/A SM_RPOOL_RFREE_T _rfree,
1N/A void *_rcontext));
1N/A
1N/A# define sm_rpool_detach(a) ((void)(*(a) = NULL))
1N/A
1N/Aextern void
1N/Asm_rpool_setsizes __P((
1N/A SM_RPOOL_T *_rpool,
1N/A size_t _poolsize,
1N/A size_t _bigobjectsize));
1N/A
1N/A#endif /* ! SM_RPOOL_H */