#ifndef restrack_h #define restrack_h /* Cesar project {{{ * * Copyright (C) 2007 Spidcom * * <<>> * * }}} */ /** * \file lib/restrack.h * \brief Resources tracker. * \ingroup lib * * The resources tracker is a debugging tool to trace resources allocations * and releases. * * It provides services to track resources references with two flavors. * * The first one and simpler one (lite) will record all the places where * allocations and releases are done during the whole resource life time. * This flavor can not determine current resource owner because it can not * associate the source line recorded with the owner. * * The second flavor (full) will request an extra argument for each allocation * and release. This argument is an owner of the resources. This flavor can * track much more errors as it can detect wrong releases and will bark if a * resources is freed while it still own other resources. * * At any time, the user can check for unbalanced resources allocations or * releases. * * Use CONFIG_RESTRACK to enable Resources tracker. * * Use CONFIG_RESTRACK_KEEP to keep records of destructed resources (not safe, * but may be useful for debug in some cases). */ #include "lib/blame.h" #include "config/restrack.h" #if CONFIG_RESTRACK BEGIN_DECLS /** * Create a resource reference counter. * \param owner owner of the resource, ignored for the lite flavor * \param resource resource referenced * \param function function name (__func__) * \param line source line * \param initial reference counter initial value */ void restrack_create (void *owner, void *resource, const char *function, int line, int initial); /** * Update a resource reference counter. * \param owner owner of the resource, ignored for the lite flavor * \param resource resource referenced * \param function function name (__func__) * \param line source line * \param change reference counter change */ void restrack_update (void *owner, void *resource, const char *function, int line, int change); /** * Destroy a resource reference counter. * \param owner owner of the resource, ignored for the lite flavor * \param resource resource referenced * \param function function name (__func__) * \param line source line * \param change reference counter change * * Will check if the counter reaches zero. */ void restrack_destroy (void *owner, void *resource, const char *function, int line, int change); /** * Check that the current state of resources allocations is balanced. * \return true if no unbalanced resource. * * Will output statistics for any unbalanced resources. */ bool restrack_check (void); /** * Free all memory used by the Resources Tracker. * * Useful for memory leaks analysis. Called automatically on exit. */ void restrack_uninit (void); END_DECLS #else /* !CONFIG_RESTRACK */ # define restrack_create(...) ((void) 0) # define restrack_update(...) ((void) 0) # define restrack_destroy(...) ((void) 0) # define restrack_check() true # define restrack_uninit() ((void) 0) #endif /* !CONFIG_RESTRACK */ #endif /* restrack_h */