mem.h revision f28a94af2179ff7592d732e409d006582e9af7c3
7aacbd685b2107670e4179689abec9cb82d972abBob Halley * Copyright (C) 1997, 1998, 1999 Internet Software Consortium.
138d22b316c7cd10eaa9df2ee0e3ec712a077153Bob Halley * Permission to use, copy, modify, and distribute this software for any
138d22b316c7cd10eaa9df2ee0e3ec712a077153Bob Halley * purpose with or without fee is hereby granted, provided that the above
138d22b316c7cd10eaa9df2ee0e3ec712a077153Bob Halley * copyright notice and this permission notice appear in all copies.
138d22b316c7cd10eaa9df2ee0e3ec712a077153Bob Halley * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
138d22b316c7cd10eaa9df2ee0e3ec712a077153Bob Halley * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
138d22b316c7cd10eaa9df2ee0e3ec712a077153Bob Halley * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
138d22b316c7cd10eaa9df2ee0e3ec712a077153Bob Halley * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
138d22b316c7cd10eaa9df2ee0e3ec712a077153Bob Halley * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
138d22b316c7cd10eaa9df2ee0e3ec712a077153Bob Halley * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
138d22b316c7cd10eaa9df2ee0e3ec712a077153Bob Halley * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
4cafb28abcaa2a485c7aac1696213435538b92edBob Halley#define isc_mem_get(c, s) __isc_mem_getdebug(c, s, __FILE__, __LINE__)
4cafb28abcaa2a485c7aac1696213435538b92edBob Halley#define isc_mem_put(c, p, s) __isc_mem_putdebug(c, p, s, __FILE__, __LINE__)
eb7ef395d27b1104f684e21836f200c052736d07Michael Graff#define isc_mempool_get(c) __isc_mempool_getdebug(c, __FILE__, __LINE__)
eb7ef395d27b1104f684e21836f200c052736d07Michael Graff#define isc_mempool_put(c, p) __isc_mempool_putdebug(c, p, s, \
4cafb28abcaa2a485c7aac1696213435538b92edBob Halley#endif /* ISC_MEM_DEBUG */
4cafb28abcaa2a485c7aac1696213435538b92edBob Halleyisc_result_t isc_mem_create(size_t, size_t, isc_mem_t **);
de9282a1eaa50764fdc2e88046f8ff3522e3092eBob Halley const char *, int);
4cafb28abcaa2a485c7aac1696213435538b92edBob Halley size_t, const char *, int);
138d22b316c7cd10eaa9df2ee0e3ec712a077153Bob Halley#define memget(s) __memget_debug(s, __FILE__, __LINE__)
138d22b316c7cd10eaa9df2ee0e3ec712a077153Bob Halley#define memput(p, s) __memput_debug(p, s, __FILE__, __LINE__)
de9282a1eaa50764fdc2e88046f8ff3522e3092eBob Halley#endif /* ISC_MEMCLUSTER_LEGACY */
eb7ef395d27b1104f684e21836f200c052736d07Michael Graff * Memory pools
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * Internal (but public) functions. Don't call these from application
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * code. Use isc_mempool_get() and isc_mempool_put() instead.
eb7ef395d27b1104f684e21836f200c052736d07Michael Graffvoid __isc_mempool_put(isc_mempool_t *, void *);
eb7ef395d27b1104f684e21836f200c052736d07Michael Graffvoid * __isc_mempool_getdebug(isc_mempool_t *, const char *, int);
eb7ef395d27b1104f684e21836f200c052736d07Michael Graffvoid __isc_mempool_putdebug(isc_mempool_t *, void *,
eb7ef395d27b1104f684e21836f200c052736d07Michael Graff const char *, int);
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graffisc_result_t isc_mempool_create(isc_mem_t *mctx, size_t size,
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * Create a memory pool.
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * mctx is a valid memory context.
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * mpctxp != NULL and *mpctxp == NULL
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * maxalloc = UINT_MAX
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * freemax = 1
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * fillcount = 1
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * ISC_R_NOMEMORY -- not enough memory to create pool
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * ISC_R_SUCCESS -- all is well.
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graffvoid isc_mempool_destroy(isc_mempool_t **mpctxp);
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * Destroy a memory pool.
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * mpctxp is a valid pool.
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * The pool has no un"put" allocations outstanding
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * The following functions get/set various parameters. Note that due to
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * the unlocked nature of pools these are potentially random values unless
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * the imposed externally provided locking protocols are followed.
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * Also note that the quota limits will not always take immediate effect.
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * For instance, setting "maxalloc" to a number larger than the currently
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * allocated count is permitted. New allocations will be refused until
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * the count drops below this threshold.
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * All functions require (in addition to other requirements):
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * mpctx is a valid memory pool
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graffunsigned int isc_mempool_getfreemax(isc_mempool_t *mpctx);
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * Returns the maximum allowed size of the free list.
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graffvoid isc_mempool_setfreemax(isc_mempool_t *mpctx,
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff unsigned int limit);
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * Sets the maximum allowed size of the free list.
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graffunsigned int isc_mempool_getfreecount(isc_mempool_t *mpctx);
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * Returns current size of the free list.
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graffunsigned int isc_mempool_getmaxalloc(isc_mempool_t *mpctx);
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * Returns the maximum allowed number of allocations.
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graffvoid isc_mempool_setmaxalloc(isc_mempool_t *mpctx,
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff unsigned int limit);
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * Sets the maximum allowed number of allocations.
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * Additional requirements:
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graffunsigned int isc_mempool_getallocated(isc_mempool_t *mpctx);
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * Returns the number of items allocated from this pool.
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graffunsigned int isc_mempool_getfillcount(isc_mempool_t *mpctx);
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * Returns the number of items allocated as a block from the parent memory
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * context when the free list is empty.
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graffvoid isc_mempool_setfillcount(isc_mempool_t *mpctx,
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff unsigned int limit);
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * Sets the fillcount.
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * Additional requirements:
4cafb28abcaa2a485c7aac1696213435538b92edBob Halley#endif /* MEM_H */