hook mpool into the resourcecollector and using safeclib allocations
This commit is contained in:
parent
9feb01e4fe
commit
d103346482
3 changed files with 74 additions and 2 deletions
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
#include "include/logging.h"
|
||||
#include "lib/safeclib.h"
|
||||
#include "lib/mpool.h"
|
||||
|
||||
#include "backend/backend.h"
|
||||
#include "common/config.h"
|
||||
|
|
@ -51,8 +52,20 @@
|
|||
//NOBUG_DECLARE_FLAG (mmapcache);
|
||||
|
||||
|
||||
|
||||
static enum lumiera_resource_try
|
||||
lumiera_backend_mpool_purge (enum lumiera_resource_try itr, void* data, void* context);
|
||||
|
||||
static void
|
||||
lumiera_backend_resourcecollector_register_mpool (MPool self);
|
||||
|
||||
static void
|
||||
lumiera_backend_resourcecollector_unregister_mpool (MPool self);
|
||||
|
||||
|
||||
size_t lumiera_backend_pagesize;
|
||||
|
||||
|
||||
int
|
||||
lumiera_backend_init (void)
|
||||
{
|
||||
|
|
@ -66,12 +79,19 @@ lumiera_backend_init (void)
|
|||
//NOBUG_INIT_FLAG (mmapcache);
|
||||
|
||||
TRACE (backend_dbg);
|
||||
|
||||
lumiera_mutex_init (&lumiera_filecreate_mutex, "fileaccess", &NOBUG_FLAG (mutex_dbg), NOBUG_CONTEXT);
|
||||
|
||||
lumiera_resourcecollector_init ();
|
||||
|
||||
/* hook the resourcecollector into the mpool*/
|
||||
mpool_malloc_hook = lumiera_malloc;
|
||||
mpool_free_hook = lumiera_free;
|
||||
mpool_init_hook = lumiera_backend_resourcecollector_register_mpool;
|
||||
mpool_destroy_hook = lumiera_backend_resourcecollector_unregister_mpool;
|
||||
|
||||
|
||||
lumiera_threadpool_init ();
|
||||
PLANNED ("hook threadpool into the resourcecollector (maybe in threadpool_init() instead here");
|
||||
|
||||
lumiera_filedescriptorregistry_init ();
|
||||
|
||||
|
|
@ -79,7 +99,6 @@ lumiera_backend_init (void)
|
|||
|
||||
TODO ("add config options to override following defaults");
|
||||
|
||||
|
||||
const char* filehandles = lumiera_tmpbuf_snprintf (SIZE_MAX,
|
||||
"backend.file.max_handles = %d",
|
||||
/* roughly 2/3 of all availables filehandles are managed by the backend */
|
||||
|
|
@ -130,3 +149,36 @@ lumiera_backend_destroy (void)
|
|||
lumiera_mutex_destroy (&lumiera_filecreate_mutex, &NOBUG_FLAG (mutex_dbg), NOBUG_CONTEXT);
|
||||
}
|
||||
|
||||
|
||||
static enum lumiera_resource_try
|
||||
lumiera_backend_mpool_purge (enum lumiera_resource_try itr, void* data, void* context)
|
||||
{
|
||||
(void) context;
|
||||
(void) data;
|
||||
(void) itr;
|
||||
TODO("mpool_purge ((MPool) data)");
|
||||
return LUMIERA_RESOURCE_NONE;
|
||||
}
|
||||
|
||||
static void
|
||||
lumiera_backend_resourcecollector_register_mpool (MPool self)
|
||||
{
|
||||
self->udata =
|
||||
lumiera_resourcecollector_register_handler (LUMIERA_RESOURCE_MEMORY, lumiera_backend_mpool_purge, self);
|
||||
}
|
||||
|
||||
static void
|
||||
lumiera_backend_resourcecollector_unregister_mpool (MPool self)
|
||||
{
|
||||
lumiera_resourcehandler_unregister ((LumieraResourcehandler) self->udata);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
// Local Variables:
|
||||
// mode: C
|
||||
// c-file-style: "gnu"
|
||||
// indent-tabs-mode: nil
|
||||
// End:
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -43,6 +43,11 @@
|
|||
void *(*mpool_malloc_hook)(size_t size) = malloc;
|
||||
void (*mpool_free_hook)(void *ptr) = free;
|
||||
|
||||
/** called after a mpool got initialized */
|
||||
void (*mpool_init_hook) (MPool self) = NULL;
|
||||
/** called before a mpool gets destroyed */
|
||||
void (*mpool_destroy_hook) (MPool self) = NULL;
|
||||
|
||||
/*
|
||||
Cluster and node structures are private
|
||||
*/
|
||||
|
|
@ -102,6 +107,9 @@ mpool_init (MPool self, size_t elem_size, unsigned elements_per_cluster, mpool_d
|
|||
|
||||
self->malloc_hook = mpool_malloc_hook;
|
||||
self->free_hook = mpool_free_hook;
|
||||
|
||||
if (mpool_init_hook)
|
||||
mpool_init_hook (self);
|
||||
}
|
||||
|
||||
return self;
|
||||
|
|
@ -137,6 +145,9 @@ mpool_destroy (MPool self)
|
|||
TRACE (mpool_dbg, "%p", self);
|
||||
if (self)
|
||||
{
|
||||
if (mpool_destroy_hook)
|
||||
mpool_destroy_hook (self);
|
||||
|
||||
LLIST_WHILE_TAIL(&self->clusters, cluster)
|
||||
{
|
||||
if (self->destroy)
|
||||
|
|
|
|||
|
|
@ -79,9 +79,18 @@ struct mpool_struct
|
|||
mpool_destroy_fn destroy;
|
||||
void *(*malloc_hook)(size_t);
|
||||
void (*free_hook)(void *);
|
||||
void* udata; /* free to use by the user, resourcecollector stuff in lumiera*/
|
||||
};
|
||||
|
||||
|
||||
extern void *(*mpool_malloc_hook)(size_t size);
|
||||
extern void (*mpool_free_hook)(void *ptr);
|
||||
|
||||
/** called after a mpool got initialized */
|
||||
extern void (*mpool_init_hook) (MPool self);
|
||||
/** called before a mpool gets destroyed */
|
||||
extern void (*mpool_destroy_hook) (MPool self);
|
||||
|
||||
/*
|
||||
//index.mpool_init xref:mpool_init[mpool_init()]:: initialize a new memory pool
|
||||
//mpool [[mpool_init]]
|
||||
|
|
|
|||
Loading…
Reference in a new issue