mem.h revision 1425217e5c3a2cbab7f8344e600e0c16047289ff
138d22b316c7cd10eaa9df2ee0e3ec712a077153Bob Halley/*
69fe9aaafdd6a141610e86a777d325db75422070Mark Andrews * Copyright (C) 2004, 2005 Internet Systems Consortium, Inc. ("ISC")
499b34cea04a46823d003d4c0520c8b03e8513cbBrian Wellington * Copyright (C) 1997-2001 Internet Software Consortium.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence *
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.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence *
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * PERFORMANCE OF THIS SOFTWARE.
138d22b316c7cd10eaa9df2ee0e3ec712a077153Bob Halley */
138d22b316c7cd10eaa9df2ee0e3ec712a077153Bob Halley
1425217e5c3a2cbab7f8344e600e0c16047289ffMark Andrews/* $Id: mem.h,v 1.66 2005/10/26 04:35:55 marka Exp $ */
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence
4cafb28abcaa2a485c7aac1696213435538b92edBob Halley#ifndef ISC_MEM_H
4cafb28abcaa2a485c7aac1696213435538b92edBob Halley#define ISC_MEM_H 1
138d22b316c7cd10eaa9df2ee0e3ec712a077153Bob Halley
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*! \file */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
138d22b316c7cd10eaa9df2ee0e3ec712a077153Bob Halley#include <stdio.h>
138d22b316c7cd10eaa9df2ee0e3ec712a077153Bob Halley
50dfb7ee4ada4c9aa30bd18c1b5d9b04be765669Michael Graff#include <isc/lang.h>
50dfb7ee4ada4c9aa30bd18c1b5d9b04be765669Michael Graff#include <isc/mutex.h>
c4958494a98a59ce25e9fecad76a9ab0e36cc59fDanny Mayer#include <isc/platform.h>
50dfb7ee4ada4c9aa30bd18c1b5d9b04be765669Michael Graff#include <isc/types.h>
138d22b316c7cd10eaa9df2ee0e3ec712a077153Bob Halley
7aacbd685b2107670e4179689abec9cb82d972abBob HalleyISC_LANG_BEGINDECLS
7aacbd685b2107670e4179689abec9cb82d972abBob Halley
3a34b87c878990c6303358efd22265c2c5980c65Mark Andrews#define ISC_MEM_LOWATER 0
3a34b87c878990c6303358efd22265c2c5980c65Mark Andrews#define ISC_MEM_HIWATER 1
3a34b87c878990c6303358efd22265c2c5980c65Mark Andrewstypedef void (*isc_mem_water_t)(void *, int);
3a34b87c878990c6303358efd22265c2c5980c65Mark Andrews
ac70da9a2710aa9f343d2f720eb1bdd4191a79caBob Halleytypedef void * (*isc_memalloc_t)(void *, size_t);
ac70da9a2710aa9f343d2f720eb1bdd4191a79caBob Halleytypedef void (*isc_memfree_t)(void *, void *);
ac70da9a2710aa9f343d2f720eb1bdd4191a79caBob Halley
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%
18159f6f6053de21e433f2194ca4f89b96926c09Andreas Gustafsson * Define ISC_MEM_DEBUG=1 to make all functions that free memory
18159f6f6053de21e433f2194ca4f89b96926c09Andreas Gustafsson * set the pointer being freed to NULL after being freed.
18159f6f6053de21e433f2194ca4f89b96926c09Andreas Gustafsson * This is the default; set ISC_MEM_DEBUG=0 to disable it.
de88422aec961bcda8b383b4a4327180584ca993David Lawrence */
c52e5c8ed1e2a3a90b912d3e4cb5da9dc32d85f7Andreas Gustafsson#ifndef ISC_MEM_DEBUG
c52e5c8ed1e2a3a90b912d3e4cb5da9dc32d85f7Andreas Gustafsson#define ISC_MEM_DEBUG 1
de88422aec961bcda8b383b4a4327180584ca993David Lawrence#endif
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%
18159f6f6053de21e433f2194ca4f89b96926c09Andreas Gustafsson * Define ISC_MEM_TRACKLINES=1 to turn on detailed tracing of memory
18159f6f6053de21e433f2194ca4f89b96926c09Andreas Gustafsson * allocation and freeing by file and line number.
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff */
c52e5c8ed1e2a3a90b912d3e4cb5da9dc32d85f7Andreas Gustafsson#ifndef ISC_MEM_TRACKLINES
50a8312c9f682004e21ffb2d58ec2064a244a9c7Andreas Gustafsson#define ISC_MEM_TRACKLINES 1
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff#endif
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%
c52e5c8ed1e2a3a90b912d3e4cb5da9dc32d85f7Andreas Gustafsson * Define ISC_MEM_CHECKOVERRUN=1 to turn on checks for using memory outside
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff * the requested space. This will increase the size of each allocation.
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff */
c52e5c8ed1e2a3a90b912d3e4cb5da9dc32d85f7Andreas Gustafsson#ifndef ISC_MEM_CHECKOVERRUN
073bd4c4bcc2f2597521578dc6ae0f49a065626cMark Andrews#define ISC_MEM_CHECKOVERRUN 1
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff#endif
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%
18159f6f6053de21e433f2194ca4f89b96926c09Andreas Gustafsson * Define ISC_MEM_FILL=1 to fill each block of memory returned to the system
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff * with the byte string '0xbe'. This helps track down uninitialized pointers
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff * and the like. On freeing memory, the space is filled with '0xde' for
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff * the same reasons.
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff */
c52e5c8ed1e2a3a90b912d3e4cb5da9dc32d85f7Andreas Gustafsson#ifndef ISC_MEM_FILL
c52e5c8ed1e2a3a90b912d3e4cb5da9dc32d85f7Andreas Gustafsson#define ISC_MEM_FILL 1
c52e5c8ed1e2a3a90b912d3e4cb5da9dc32d85f7Andreas Gustafsson#endif
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%
18159f6f6053de21e433f2194ca4f89b96926c09Andreas Gustafsson * Define ISC_MEMPOOL_NAMES=1 to make memory pools store a symbolic
18159f6f6053de21e433f2194ca4f89b96926c09Andreas Gustafsson * name so that the leaking pool can be more readily identified in
18159f6f6053de21e433f2194ca4f89b96926c09Andreas Gustafsson * case of a memory leak.
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff */
c52e5c8ed1e2a3a90b912d3e4cb5da9dc32d85f7Andreas Gustafsson#ifndef ISC_MEMPOOL_NAMES
c52e5c8ed1e2a3a90b912d3e4cb5da9dc32d85f7Andreas Gustafsson#define ISC_MEMPOOL_NAMES 1
c52e5c8ed1e2a3a90b912d3e4cb5da9dc32d85f7Andreas Gustafsson#endif
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff
c4958494a98a59ce25e9fecad76a9ab0e36cc59fDanny MayerLIBISC_EXTERNAL_DATA extern unsigned int isc_mem_debugging;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*@{*/
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff#define ISC_MEM_DEBUGTRACE 0x00000001U
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff#define ISC_MEM_DEBUGRECORD 0x00000002U
950d71eee32cb7c6ef9f659154f77bbf5a2cdce6Mark Andrews#define ISC_MEM_DEBUGUSAGE 0x00000004U
d4d68515d23668cfe804ab2a174a7e427decedd8Mark Andrews#define ISC_MEM_DEBUGSIZE 0x00000008U
d4d68515d23668cfe804ab2a174a7e427decedd8Mark Andrews#define ISC_MEM_DEBUGCTX 0x00000010U
d4d68515d23668cfe804ab2a174a7e427decedd8Mark Andrews#define ISC_MEM_DEBUGALL 0x0000001FU
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*!<
6d858e75d4f411e89485ec702ce1e118e1ead53cAndreas Gustafsson * The variable isc_mem_debugging holds a set of flags for
6d858e75d4f411e89485ec702ce1e118e1ead53cAndreas Gustafsson * turning certain memory debugging options on or off at
6d858e75d4f411e89485ec702ce1e118e1ead53cAndreas Gustafsson * runtime. Its is intialized to the value ISC_MEM_DEGBUGGING,
6d858e75d4f411e89485ec702ce1e118e1ead53cAndreas Gustafsson * which is 0 by default but may be overridden at compile time.
6d858e75d4f411e89485ec702ce1e118e1ead53cAndreas Gustafsson * The following flags can be specified:
6d858e75d4f411e89485ec702ce1e118e1ead53cAndreas Gustafsson *
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * \li #ISC_MEM_DEBUGTRACE
6d858e75d4f411e89485ec702ce1e118e1ead53cAndreas Gustafsson * Log each allocation and free to isc_lctx.
6d858e75d4f411e89485ec702ce1e118e1ead53cAndreas Gustafsson *
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * \li #ISC_MEM_DEBUGRECORD
6d858e75d4f411e89485ec702ce1e118e1ead53cAndreas Gustafsson * Remember each allocation, and match them up on free.
6d858e75d4f411e89485ec702ce1e118e1ead53cAndreas Gustafsson * Crash if a free doesn't match an allocation.
6d858e75d4f411e89485ec702ce1e118e1ead53cAndreas Gustafsson *
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * \li #ISC_MEM_DEBUGUSAGE
6d858e75d4f411e89485ec702ce1e118e1ead53cAndreas Gustafsson * If a hi_water mark is set, print the maximium inuse memory
6d858e75d4f411e89485ec702ce1e118e1ead53cAndreas Gustafsson * every time it is raised once it exceeds the hi_water mark.
d4d68515d23668cfe804ab2a174a7e427decedd8Mark Andrews *
d4d68515d23668cfe804ab2a174a7e427decedd8Mark Andrews * \li #ISC_MEM_DEBUGSIZE
1425217e5c3a2cbab7f8344e600e0c16047289ffMark Andrews * Check the size argument being passed to isc_mem_put() matches
d4d68515d23668cfe804ab2a174a7e427decedd8Mark Andrews * that passed to isc_mem_get().
d4d68515d23668cfe804ab2a174a7e427decedd8Mark Andrews *
d4d68515d23668cfe804ab2a174a7e427decedd8Mark Andrews * \li #ISC_MEM_DEBUGCTX
1425217e5c3a2cbab7f8344e600e0c16047289ffMark Andrews * Check the mctx argument being passed to isc_mem_put() matches
d4d68515d23668cfe804ab2a174a7e427decedd8Mark Andrews * that passed to isc_mem_get().
6d858e75d4f411e89485ec702ce1e118e1ead53cAndreas Gustafsson */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*@}*/
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff
c52e5c8ed1e2a3a90b912d3e4cb5da9dc32d85f7Andreas Gustafsson#if ISC_MEM_TRACKLINES
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff#define _ISC_MEM_FILELINE , __FILE__, __LINE__
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff#define _ISC_MEM_FLARG , const char *, int
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff#else
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff#define _ISC_MEM_FILELINE
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff#define _ISC_MEM_FLARG
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff#endif
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff
016c0a82f1ce3fe4d362d7c9cf8de4377ffaf5a9Mark Andrews/*!
016c0a82f1ce3fe4d362d7c9cf8de4377ffaf5a9Mark Andrews * Define ISC_MEM_USE_INTERNAL_MALLOC=1 to use the internal malloc()
016c0a82f1ce3fe4d362d7c9cf8de4377ffaf5a9Mark Andrews * implementation in preference to the system one. The internal malloc()
016c0a82f1ce3fe4d362d7c9cf8de4377ffaf5a9Mark Andrews * is very space-efficient, and quite fast on uniprocessor systems. It
016c0a82f1ce3fe4d362d7c9cf8de4377ffaf5a9Mark Andrews * performs poorly on multiprocessor machines.
016c0a82f1ce3fe4d362d7c9cf8de4377ffaf5a9Mark Andrews * JT: we can overcome the performance issue on multiprocessor machines
016c0a82f1ce3fe4d362d7c9cf8de4377ffaf5a9Mark Andrews * by carefully separating memory contexts.
016c0a82f1ce3fe4d362d7c9cf8de4377ffaf5a9Mark Andrews */
016c0a82f1ce3fe4d362d7c9cf8de4377ffaf5a9Mark Andrews
016c0a82f1ce3fe4d362d7c9cf8de4377ffaf5a9Mark Andrews#ifndef ISC_MEM_USE_INTERNAL_MALLOC
016c0a82f1ce3fe4d362d7c9cf8de4377ffaf5a9Mark Andrews#define ISC_MEM_USE_INTERNAL_MALLOC 1
016c0a82f1ce3fe4d362d7c9cf8de4377ffaf5a9Mark Andrews#endif
016c0a82f1ce3fe4d362d7c9cf8de4377ffaf5a9Mark Andrews
5597be9bb88de138dfec9fa9176708443813925eTatuya JINMEI 神明達哉/*
5597be9bb88de138dfec9fa9176708443813925eTatuya JINMEI 神明達哉 * Flags for isc_mem_create2()calls.
5597be9bb88de138dfec9fa9176708443813925eTatuya JINMEI 神明達哉 */
5597be9bb88de138dfec9fa9176708443813925eTatuya JINMEI 神明達哉#define ISC_MEMFLAG_NOLOCK 0x00000001 /* no lock is necessary */
016c0a82f1ce3fe4d362d7c9cf8de4377ffaf5a9Mark Andrews#define ISC_MEMFLAG_INTERNAL 0x00000002 /* use internal malloc */
016c0a82f1ce3fe4d362d7c9cf8de4377ffaf5a9Mark Andrews#if ISC_MEM_USE_INTERNAL_MALLOC
016c0a82f1ce3fe4d362d7c9cf8de4377ffaf5a9Mark Andrews#define ISC_MEMFLAG_DEFAULT ISC_MEMFLAG_INTERNAL
016c0a82f1ce3fe4d362d7c9cf8de4377ffaf5a9Mark Andrews#else
016c0a82f1ce3fe4d362d7c9cf8de4377ffaf5a9Mark Andrews#define ISC_MEMFLAG_DEFAULT 0
016c0a82f1ce3fe4d362d7c9cf8de4377ffaf5a9Mark Andrews#endif
016c0a82f1ce3fe4d362d7c9cf8de4377ffaf5a9Mark Andrews
5597be9bb88de138dfec9fa9176708443813925eTatuya JINMEI 神明達哉
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff#define isc_mem_get(c, s) isc__mem_get((c), (s) _ISC_MEM_FILELINE)
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff#define isc_mem_allocate(c, s) isc__mem_allocate((c), (s) _ISC_MEM_FILELINE)
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff#define isc_mem_strdup(c, p) isc__mem_strdup((c), (p) _ISC_MEM_FILELINE)
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff#define isc_mempool_get(c) isc__mempool_get((c) _ISC_MEM_FILELINE)
54ef500660da1f4e8d4e14e737fa81c4c881ac0aBrian Wellington
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%
6c6bed90cb5b51a90530b7d488b2696626a8fafcMark Andrews * isc_mem_putanddetach() is a convienence function for use where you
6c6bed90cb5b51a90530b7d488b2696626a8fafcMark Andrews * have a structure with an attached memory context.
6c6bed90cb5b51a90530b7d488b2696626a8fafcMark Andrews *
6c6bed90cb5b51a90530b7d488b2696626a8fafcMark Andrews * Given:
6c6bed90cb5b51a90530b7d488b2696626a8fafcMark Andrews *
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * \code
6c6bed90cb5b51a90530b7d488b2696626a8fafcMark Andrews * struct {
6c6bed90cb5b51a90530b7d488b2696626a8fafcMark Andrews * ...
6c6bed90cb5b51a90530b7d488b2696626a8fafcMark Andrews * isc_mem_t *mctx;
6c6bed90cb5b51a90530b7d488b2696626a8fafcMark Andrews * ...
6c6bed90cb5b51a90530b7d488b2696626a8fafcMark Andrews * } *ptr;
6c6bed90cb5b51a90530b7d488b2696626a8fafcMark Andrews *
6c6bed90cb5b51a90530b7d488b2696626a8fafcMark Andrews * isc_mem_t *mctx;
6c6bed90cb5b51a90530b7d488b2696626a8fafcMark Andrews *
6c6bed90cb5b51a90530b7d488b2696626a8fafcMark Andrews * isc_mem_putanddetach(&ptr->mctx, ptr, sizeof(*ptr));
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * \endcode
6c6bed90cb5b51a90530b7d488b2696626a8fafcMark Andrews *
6c6bed90cb5b51a90530b7d488b2696626a8fafcMark Andrews * is the equivalent of:
6c6bed90cb5b51a90530b7d488b2696626a8fafcMark Andrews *
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * \code
6c6bed90cb5b51a90530b7d488b2696626a8fafcMark Andrews * mctx = NULL;
6c6bed90cb5b51a90530b7d488b2696626a8fafcMark Andrews * isc_mem_attach(ptr->mctx, &mctx);
6c6bed90cb5b51a90530b7d488b2696626a8fafcMark Andrews * isc_mem_detach(&ptr->mctx);
6c6bed90cb5b51a90530b7d488b2696626a8fafcMark Andrews * isc_mem_put(mctx, ptr, sizeof(*ptr));
6c6bed90cb5b51a90530b7d488b2696626a8fafcMark Andrews * isc_mem_detach(&mctx);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * \endcode
6c6bed90cb5b51a90530b7d488b2696626a8fafcMark Andrews */
6c6bed90cb5b51a90530b7d488b2696626a8fafcMark Andrews
c52e5c8ed1e2a3a90b912d3e4cb5da9dc32d85f7Andreas Gustafsson#if ISC_MEM_DEBUG
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff#define isc_mem_put(c, p, s) \
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff do { \
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff isc__mem_put((c), (p), (s) _ISC_MEM_FILELINE); \
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff (p) = NULL; \
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff } while (0)
1162a4e02a6594dbb4f57fd288a5d20ab467e4d7Mark Andrews#define isc_mem_putanddetach(c, p, s) \
1162a4e02a6594dbb4f57fd288a5d20ab467e4d7Mark Andrews do { \
1162a4e02a6594dbb4f57fd288a5d20ab467e4d7Mark Andrews isc__mem_putanddetach((c), (p), (s) _ISC_MEM_FILELINE); \
1162a4e02a6594dbb4f57fd288a5d20ab467e4d7Mark Andrews (p) = NULL; \
1162a4e02a6594dbb4f57fd288a5d20ab467e4d7Mark Andrews } while (0)
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff#define isc_mem_free(c, p) \
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff do { \
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff isc__mem_free((c), (p) _ISC_MEM_FILELINE); \
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff (p) = NULL; \
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff } while (0)
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff#define isc_mempool_put(c, p) \
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff do { \
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff isc__mempool_put((c), (p) _ISC_MEM_FILELINE); \
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff (p) = NULL; \
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff } while (0)
138d22b316c7cd10eaa9df2ee0e3ec712a077153Bob Halley#else
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff#define isc_mem_put(c, p, s) isc__mem_put((c), (p), (s) _ISC_MEM_FILELINE)
1162a4e02a6594dbb4f57fd288a5d20ab467e4d7Mark Andrews#define isc_mem_putanddetach(c, p, s) \
1162a4e02a6594dbb4f57fd288a5d20ab467e4d7Mark Andrews isc__mem_putanddetach((c), (p), (s) _ISC_MEM_FILELINE)
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff#define isc_mem_free(c, p) isc__mem_free((c), (p) _ISC_MEM_FILELINE)
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff#define isc_mempool_put(c, p) isc__mempool_put((c), (p) _ISC_MEM_FILELINE)
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff#endif
138d22b316c7cd10eaa9df2ee0e3ec712a077153Bob Halley
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*@{*/
8096fe1df5abfef957b934a1d1c5e97eaa246434Danny Mayerisc_result_t
8096fe1df5abfef957b934a1d1c5e97eaa246434Danny Mayerisc_mem_create(size_t max_size, size_t target_size,
6d858e75d4f411e89485ec702ce1e118e1ead53cAndreas Gustafsson isc_mem_t **mctxp);
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson
5597be9bb88de138dfec9fa9176708443813925eTatuya JINMEI 神明達哉isc_result_t
5597be9bb88de138dfec9fa9176708443813925eTatuya JINMEI 神明達哉isc_mem_create2(size_t max_size, size_t target_size,
5597be9bb88de138dfec9fa9176708443813925eTatuya JINMEI 神明達哉 isc_mem_t **mctxp, unsigned int flags);
5597be9bb88de138dfec9fa9176708443813925eTatuya JINMEI 神明達哉
8096fe1df5abfef957b934a1d1c5e97eaa246434Danny Mayerisc_result_t
8096fe1df5abfef957b934a1d1c5e97eaa246434Danny Mayerisc_mem_createx(size_t max_size, size_t target_size,
6d858e75d4f411e89485ec702ce1e118e1ead53cAndreas Gustafsson isc_memalloc_t memalloc, isc_memfree_t memfree,
6d858e75d4f411e89485ec702ce1e118e1ead53cAndreas Gustafsson void *arg, isc_mem_t **mctxp);
5597be9bb88de138dfec9fa9176708443813925eTatuya JINMEI 神明達哉
5597be9bb88de138dfec9fa9176708443813925eTatuya JINMEI 神明達哉isc_result_t
5597be9bb88de138dfec9fa9176708443813925eTatuya JINMEI 神明達哉isc_mem_createx2(size_t max_size, size_t target_size,
5597be9bb88de138dfec9fa9176708443813925eTatuya JINMEI 神明達哉 isc_memalloc_t memalloc, isc_memfree_t memfree,
5597be9bb88de138dfec9fa9176708443813925eTatuya JINMEI 神明達哉 void *arg, isc_mem_t **mctxp, unsigned int flags);
5597be9bb88de138dfec9fa9176708443813925eTatuya JINMEI 神明達哉
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*!<
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * \brief Create a memory context.
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson *
1d625775ee265ec4d5237ae3a315789ad0957bd5Andreas Gustafsson * 'max_size' and 'target_size' are tuning parameters. When
016c0a82f1ce3fe4d362d7c9cf8de4377ffaf5a9Mark Andrews * ISC_MEMFLAG_INTERNAL is set, allocations smaller than 'max_size'
016c0a82f1ce3fe4d362d7c9cf8de4377ffaf5a9Mark Andrews * will be satisfied by getting blocks of size 'target_size' from the
016c0a82f1ce3fe4d362d7c9cf8de4377ffaf5a9Mark Andrews * system allocator and breaking them up into pieces; larger allocations
016c0a82f1ce3fe4d362d7c9cf8de4377ffaf5a9Mark Andrews * will use the system allocator directly. If 'max_size' and/or
016c0a82f1ce3fe4d362d7c9cf8de4377ffaf5a9Mark Andrews * 'target_size' are zero, default values will be * used. When
016c0a82f1ce3fe4d362d7c9cf8de4377ffaf5a9Mark Andrews * ISC_MEMFLAG_INTERNAL is not set, 'target_size' is ignored.
e0806ab5eda9add79044ccf17e55c49bae35d2e2Mark Andrews *
e0806ab5eda9add79044ccf17e55c49bae35d2e2Mark Andrews * 'max_size' is also used to size the statistics arrays and the array
e0806ab5eda9add79044ccf17e55c49bae35d2e2Mark Andrews * used to record active memory when ISC_MEM_DEBUGRECORD is set. Settin
e0806ab5eda9add79044ccf17e55c49bae35d2e2Mark Andrews * 'max_size' too low can have detrimental effects on performance.
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson *
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson * A memory context created using isc_mem_createx() will obtain
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson * memory from the system by calling 'memalloc' and 'memfree',
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson * passing them the argument 'arg'. A memory context created
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson * using isc_mem_create() will use the standard library malloc()
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson * and free().
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson *
5597be9bb88de138dfec9fa9176708443813925eTatuya JINMEI 神明達哉 * If ISC_MEMFLAG_NOLOCK is set in 'flags', the corresponding memory context
5597be9bb88de138dfec9fa9176708443813925eTatuya JINMEI 神明達哉 * will be accessed without locking. The user who creates the context must
5597be9bb88de138dfec9fa9176708443813925eTatuya JINMEI 神明達哉 * ensure there be no race. Since this can be a source of bug, it is generally
5597be9bb88de138dfec9fa9176708443813925eTatuya JINMEI 神明達哉 * inadvisable to use this flag unless the user is very sure about the race
5597be9bb88de138dfec9fa9176708443813925eTatuya JINMEI 神明達哉 * condition and the access to the object is highly performance sensitive.
5597be9bb88de138dfec9fa9176708443813925eTatuya JINMEI 神明達哉 *
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson * Requires:
1d625775ee265ec4d5237ae3a315789ad0957bd5Andreas Gustafsson * mctxp != NULL && *mctxp == NULL */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*@}*/
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*@{*/
8096fe1df5abfef957b934a1d1c5e97eaa246434Danny Mayervoid
8096fe1df5abfef957b934a1d1c5e97eaa246434Danny Mayerisc_mem_attach(isc_mem_t *, isc_mem_t **);
8096fe1df5abfef957b934a1d1c5e97eaa246434Danny Mayervoid
8096fe1df5abfef957b934a1d1c5e97eaa246434Danny Mayerisc_mem_detach(isc_mem_t **);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*!<
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * \brief Attach to / detach from a memory context.
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson *
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson * This is intended for applications that use multiple memory contexts
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson * in such a way that it is not obvious when the last allocations from
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson * a given context has been freed and destroying the context is safe.
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson *
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson * Most applications do not need to call these functions as they can
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson * simply create a single memory context at the beginning of main()
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson * and destroy it at the end of main(), thereby guaranteeing that it
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson * is not destroyed while there are outstanding allocations.
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*@}*/
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson
8096fe1df5abfef957b934a1d1c5e97eaa246434Danny Mayervoid
8096fe1df5abfef957b934a1d1c5e97eaa246434Danny Mayerisc_mem_destroy(isc_mem_t **);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%<
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson * Destroy a memory context.
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson */
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson
8096fe1df5abfef957b934a1d1c5e97eaa246434Danny Mayerisc_result_t
8096fe1df5abfef957b934a1d1c5e97eaa246434Danny Mayerisc_mem_ondestroy(isc_mem_t *ctx,
6d858e75d4f411e89485ec702ce1e118e1ead53cAndreas Gustafsson isc_task_t *task,
6d858e75d4f411e89485ec702ce1e118e1ead53cAndreas Gustafsson isc_event_t **event);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%<
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson * Request to be notified with an event when a memory context has
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson * been successfully destroyed.
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson */
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson
8096fe1df5abfef957b934a1d1c5e97eaa246434Danny Mayervoid
8096fe1df5abfef957b934a1d1c5e97eaa246434Danny Mayerisc_mem_stats(isc_mem_t *mctx, FILE *out);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%<
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson * Print memory usage statistics for 'mctx' on the stream 'out'.
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson */
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson
8096fe1df5abfef957b934a1d1c5e97eaa246434Danny Mayervoid
8096fe1df5abfef957b934a1d1c5e97eaa246434Danny Mayerisc_mem_setdestroycheck(isc_mem_t *mctx,
6d858e75d4f411e89485ec702ce1e118e1ead53cAndreas Gustafsson isc_boolean_t on);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%<
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * If 'on' is ISC_TRUE, 'mctx' will check for memory leaks when
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson * destroyed and abort the program if any are present.
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson */
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*@{*/
8096fe1df5abfef957b934a1d1c5e97eaa246434Danny Mayervoid
8096fe1df5abfef957b934a1d1c5e97eaa246434Danny Mayerisc_mem_setquota(isc_mem_t *, size_t);
8096fe1df5abfef957b934a1d1c5e97eaa246434Danny Mayersize_t
8096fe1df5abfef957b934a1d1c5e97eaa246434Danny Mayerisc_mem_getquota(isc_mem_t *);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%<
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson * Set/get the memory quota of 'mctx'. This is a hard limit
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson * on the amount of memory that may be allocated from mctx;
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson * if it is exceeded, allocations will fail.
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*@}*/
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson
8096fe1df5abfef957b934a1d1c5e97eaa246434Danny Mayersize_t
8096fe1df5abfef957b934a1d1c5e97eaa246434Danny Mayerisc_mem_inuse(isc_mem_t *mctx);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%<
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson * Get an estimate of the number of memory in use in 'mctx', in bytes.
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson * This includes quantization overhead, but does not include memory
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson * allocated from the system but not yet used.
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson */
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson
3a34b87c878990c6303358efd22265c2c5980c65Mark Andrewsvoid
3a34b87c878990c6303358efd22265c2c5980c65Mark Andrewsisc_mem_setwater(isc_mem_t *mctx, isc_mem_water_t water, void *water_arg,
3a34b87c878990c6303358efd22265c2c5980c65Mark Andrews size_t hiwater, size_t lowater);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%<
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * Set high and low water marks for this memory context.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * When the memory
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * usage of 'mctx' exceeds 'hiwater', '(water)(water_arg, #ISC_MEM_HIWATER)'
3a34b87c878990c6303358efd22265c2c5980c65Mark Andrews * will be called. When the usage drops below 'lowater', 'water' will
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * again be called, this time with #ISC_MEM_LOWATER.
3a34b87c878990c6303358efd22265c2c5980c65Mark Andrews *
65640f401a22971de16c01e9a9547d95c55ed45eDavid Lawrence * If 'water' is NULL then 'water_arg', 'hi_water' and 'lo_water' are
65640f401a22971de16c01e9a9547d95c55ed45eDavid Lawrence * ignored and the state is reset.
65640f401a22971de16c01e9a9547d95c55ed45eDavid Lawrence *
3a34b87c878990c6303358efd22265c2c5980c65Mark Andrews * Requires:
50a3152b7088546418c8edc0c89eeaf48560b035Andreas Gustafsson *
65640f401a22971de16c01e9a9547d95c55ed45eDavid Lawrence * 'water' is not NULL.
65640f401a22971de16c01e9a9547d95c55ed45eDavid Lawrence * hi_water >= lo_water
3a34b87c878990c6303358efd22265c2c5980c65Mark Andrews */
3a34b87c878990c6303358efd22265c2c5980c65Mark Andrews
eb7ef395d27b1104f684e21836f200c052736d07Michael Graff/*
eb7ef395d27b1104f684e21836f200c052736d07Michael Graff * Memory pools
eb7ef395d27b1104f684e21836f200c052736d07Michael Graff */
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff
50dfb7ee4ada4c9aa30bd18c1b5d9b04be765669Michael Graffisc_result_t
50dfb7ee4ada4c9aa30bd18c1b5d9b04be765669Michael Graffisc_mempool_create(isc_mem_t *mctx, size_t size, isc_mempool_t **mpctxp);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%<
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * Create a memory pool.
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff *
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * Requires:
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li mctx is a valid memory context.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li size > 0
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li mpctxp != NULL and *mpctxp == NULL
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff *
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * Defaults:
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li maxalloc = UINT_MAX
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li freemax = 1
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li fillcount = 1
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff *
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * Returns:
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li #ISC_R_NOMEMORY -- not enough memory to create pool
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li #ISC_R_SUCCESS -- all is well.
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff */
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff
50dfb7ee4ada4c9aa30bd18c1b5d9b04be765669Michael Graffvoid
50dfb7ee4ada4c9aa30bd18c1b5d9b04be765669Michael Graffisc_mempool_destroy(isc_mempool_t **mpctxp);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%<
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * Destroy a memory pool.
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff *
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * Requires:
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li mpctxp != NULL && *mpctxp is a valid pool.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li The pool has no un"put" allocations outstanding
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff */
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff
78b2f25c9afee0d16f2e75882d9763abcb0872e5Michael Graffvoid
87cafc5e70f79f2586d067fbdd64f61bbab069d2David Lawrenceisc_mempool_setname(isc_mempool_t *mpctx, const char *name);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%<
78b2f25c9afee0d16f2e75882d9763abcb0872e5Michael Graff * Associate a name with a memory pool. At most 15 characters may be used.
78b2f25c9afee0d16f2e75882d9763abcb0872e5Michael Graff *
78b2f25c9afee0d16f2e75882d9763abcb0872e5Michael Graff * Requires:
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li mpctx is a valid pool.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li name != NULL;
78b2f25c9afee0d16f2e75882d9763abcb0872e5Michael Graff */
78b2f25c9afee0d16f2e75882d9763abcb0872e5Michael Graff
50dfb7ee4ada4c9aa30bd18c1b5d9b04be765669Michael Graffvoid
50dfb7ee4ada4c9aa30bd18c1b5d9b04be765669Michael Graffisc_mempool_associatelock(isc_mempool_t *mpctx, isc_mutex_t *lock);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%<
50dfb7ee4ada4c9aa30bd18c1b5d9b04be765669Michael Graff * Associate a lock with this memory pool.
50dfb7ee4ada4c9aa30bd18c1b5d9b04be765669Michael Graff *
50dfb7ee4ada4c9aa30bd18c1b5d9b04be765669Michael Graff * This lock is used when getting or putting items using this memory pool,
50dfb7ee4ada4c9aa30bd18c1b5d9b04be765669Michael Graff * and it is also used to set or get internal state via the isc_mempool_get*()
50dfb7ee4ada4c9aa30bd18c1b5d9b04be765669Michael Graff * and isc_mempool_set*() set of functions.
50dfb7ee4ada4c9aa30bd18c1b5d9b04be765669Michael Graff *
50dfb7ee4ada4c9aa30bd18c1b5d9b04be765669Michael Graff * Mutiple pools can each share a single lock. For instance, if "manager"
50dfb7ee4ada4c9aa30bd18c1b5d9b04be765669Michael Graff * type object contained pools for various sizes of events, and each of
50dfb7ee4ada4c9aa30bd18c1b5d9b04be765669Michael Graff * these pools used a common lock. Note that this lock must NEVER be used
50dfb7ee4ada4c9aa30bd18c1b5d9b04be765669Michael Graff * by other than mempool routines once it is given to a pool, since that can
50dfb7ee4ada4c9aa30bd18c1b5d9b04be765669Michael Graff * easily cause double locking.
50dfb7ee4ada4c9aa30bd18c1b5d9b04be765669Michael Graff *
50dfb7ee4ada4c9aa30bd18c1b5d9b04be765669Michael Graff * Requires:
50dfb7ee4ada4c9aa30bd18c1b5d9b04be765669Michael Graff *
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li mpctpx is a valid pool.
50dfb7ee4ada4c9aa30bd18c1b5d9b04be765669Michael Graff *
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li lock != NULL.
50dfb7ee4ada4c9aa30bd18c1b5d9b04be765669Michael Graff *
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li No previous lock is assigned to this pool.
50dfb7ee4ada4c9aa30bd18c1b5d9b04be765669Michael Graff *
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li The lock is initialized before calling this function via the normal
50dfb7ee4ada4c9aa30bd18c1b5d9b04be765669Michael Graff * means of doing that.
50dfb7ee4ada4c9aa30bd18c1b5d9b04be765669Michael Graff */
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff/*
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 *
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * Also note that the quota limits will not always take immediate effect.
0fd03d2a66102f8d9bd7acea4e7db73ecaa0cb52Michael Graff * For instance, setting "maxalloc" to a number smaller 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 *
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * All functions require (in addition to other requirements):
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * mpctx is a valid memory pool
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff */
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff
c7f22f83aac9e61dafee191cad040e9c42652cc8David Lawrenceunsigned int
c7f22f83aac9e61dafee191cad040e9c42652cc8David Lawrenceisc_mempool_getfreemax(isc_mempool_t *mpctx);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%<
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * Returns the maximum allowed size of the free list.
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff */
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff
c7f22f83aac9e61dafee191cad040e9c42652cc8David Lawrencevoid
c7f22f83aac9e61dafee191cad040e9c42652cc8David Lawrenceisc_mempool_setfreemax(isc_mempool_t *mpctx, unsigned int limit);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%<
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * Sets the maximum allowed size of the free list.
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff */
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff
c7f22f83aac9e61dafee191cad040e9c42652cc8David Lawrenceunsigned int
c7f22f83aac9e61dafee191cad040e9c42652cc8David Lawrenceisc_mempool_getfreecount(isc_mempool_t *mpctx);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%<
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * Returns current size of the free list.
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff */
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff
c7f22f83aac9e61dafee191cad040e9c42652cc8David Lawrenceunsigned int
c7f22f83aac9e61dafee191cad040e9c42652cc8David Lawrenceisc_mempool_getmaxalloc(isc_mempool_t *mpctx);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*!<
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * Returns the maximum allowed number of allocations.
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff */
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff
c7f22f83aac9e61dafee191cad040e9c42652cc8David Lawrencevoid
c7f22f83aac9e61dafee191cad040e9c42652cc8David Lawrenceisc_mempool_setmaxalloc(isc_mempool_t *mpctx, unsigned int limit);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%<
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * Sets the maximum allowed number of allocations.
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff *
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * Additional requirements:
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li limit > 0
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff */
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff
c7f22f83aac9e61dafee191cad040e9c42652cc8David Lawrenceunsigned int
c7f22f83aac9e61dafee191cad040e9c42652cc8David Lawrenceisc_mempool_getallocated(isc_mempool_t *mpctx);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%<
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * Returns the number of items allocated from this pool.
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff */
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff
c7f22f83aac9e61dafee191cad040e9c42652cc8David Lawrenceunsigned int
c7f22f83aac9e61dafee191cad040e9c42652cc8David Lawrenceisc_mempool_getfillcount(isc_mempool_t *mpctx);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%<
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 Graff */
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff
c7f22f83aac9e61dafee191cad040e9c42652cc8David Lawrencevoid
c7f22f83aac9e61dafee191cad040e9c42652cc8David Lawrenceisc_mempool_setfillcount(isc_mempool_t *mpctx, unsigned int limit);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%<
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * Sets the fillcount.
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff *
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * Additional requirements:
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li limit > 0
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff */
eb7ef395d27b1104f684e21836f200c052736d07Michael Graff
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson/*
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson * Pseudo-private functions for use via macros. Do not call directly.
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson */
8096fe1df5abfef957b934a1d1c5e97eaa246434Danny Mayervoid *
8096fe1df5abfef957b934a1d1c5e97eaa246434Danny Mayerisc__mem_get(isc_mem_t *, size_t _ISC_MEM_FLARG);
8096fe1df5abfef957b934a1d1c5e97eaa246434Danny Mayervoid
8096fe1df5abfef957b934a1d1c5e97eaa246434Danny Mayerisc__mem_putanddetach(isc_mem_t **, void *,
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson size_t _ISC_MEM_FLARG);
8096fe1df5abfef957b934a1d1c5e97eaa246434Danny Mayervoid
8096fe1df5abfef957b934a1d1c5e97eaa246434Danny Mayerisc__mem_put(isc_mem_t *, void *, size_t _ISC_MEM_FLARG);
8096fe1df5abfef957b934a1d1c5e97eaa246434Danny Mayervoid *
8096fe1df5abfef957b934a1d1c5e97eaa246434Danny Mayerisc__mem_allocate(isc_mem_t *, size_t _ISC_MEM_FLARG);
8096fe1df5abfef957b934a1d1c5e97eaa246434Danny Mayervoid
8096fe1df5abfef957b934a1d1c5e97eaa246434Danny Mayerisc__mem_free(isc_mem_t *, void * _ISC_MEM_FLARG);
8096fe1df5abfef957b934a1d1c5e97eaa246434Danny Mayerchar *
8096fe1df5abfef957b934a1d1c5e97eaa246434Danny Mayerisc__mem_strdup(isc_mem_t *, const char *_ISC_MEM_FLARG);
8096fe1df5abfef957b934a1d1c5e97eaa246434Danny Mayervoid *
8096fe1df5abfef957b934a1d1c5e97eaa246434Danny Mayerisc__mempool_get(isc_mempool_t * _ISC_MEM_FLARG);
8096fe1df5abfef957b934a1d1c5e97eaa246434Danny Mayervoid
8096fe1df5abfef957b934a1d1c5e97eaa246434Danny Mayerisc__mempool_put(isc_mempool_t *, void * _ISC_MEM_FLARG);
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson
7aacbd685b2107670e4179689abec9cb82d972abBob HalleyISC_LANG_ENDDECLS
7aacbd685b2107670e4179689abec9cb82d972abBob Halley
54a2e7e8a21ee765f41bd995101995613bff9e8cDavid Lawrence#endif /* ISC_MEM_H */