Cleanup the mempool stuff.

SVN revision: 35277
This commit is contained in:
Cedric BAIL 2008-07-31 17:00:56 +00:00
parent 9321fbbfdc
commit a309e49392
9 changed files with 204 additions and 43 deletions

View File

@ -60,6 +60,21 @@ AC_ARG_ENABLE([coverage],
AC_MSG_CHECKING([whether to use profiling instrumentation])
AC_MSG_RESULT([$enable_coverage])
# Ememoa memory pool
AC_ARG_ENABLE([ememoa],
[AC_HELP_STRING([--enable-ememoa], [build ememoa memory pool module @<:@default=yes@:>@])],
[
if test "x${enableval}" = "xyes" ; then
enable_ememoa="yes"
else
enable_ememoa="no"
fi
],
[enable_ememoa="yes"]
)
AC_MSG_CHECKING([whether to use ememoa for memory pool])
AC_MSG_RESULT([$enable_ememoa])
### Checks for libraries
@ -72,9 +87,15 @@ if test "x${enable_tests}" = "xyes" ; then
[enable_tests="no"]
)
fi
AM_CONDITIONAL(EINA_ENABLE_TESTS, test "x${enable_tests}" = "xyes")
# Check ememoa memory pool library
PKG_CHECK_MODULES([EMEMOA],
[ememoa >= 0.0.26 ],
[enable_ememoa="yes"],
[enable_ememoa="no"]
)
AM_CONDITIONAL(EINA_ENABLE_EMEMOA, test "x${enable_ememoa}" = "xyes")
### Checks for header files
AC_HEADER_ASSERT
@ -152,8 +173,9 @@ src/Makefile
src/include/Makefile
src/lib/Makefile
src/modules/Makefile
src/modules/mm_policies/Makefile
src/modules/chained_pool/Makefile
src/modules/mp/Makefile
src/modules/mp/chained_pool/Makefile
src/modules/mp/ememoa_fixed/Makefile
])
AC_OUTPUT
@ -174,6 +196,9 @@ echo
echo " Tests................: ${enable_tests}"
echo " Coverage.............: ${enable_coverage}"
echo
echo "Memory pool:"
echo " Ememoa...............: ${enable_ememoa}"
echo
echo " Installation.........: make install"
echo
echo " prefix.............: $prefix"

View File

@ -17,11 +17,11 @@ struct _Eina_Mempool
Eina_Mempool_Backend *backend;
void *backend_data;
};
static Eina_Mempool * _new_from_buffer(const char *name, void *buffer,
unsigned int size, const char *options, va_list args)
static Eina_Mempool *
_new_from_buffer(const char *module, const char *context, const char *options, va_list args)
{
Eina_List *l;
/* load the module with filename == name */
for (l = _modules; l; l = eina_list_next(l))
{
@ -29,7 +29,7 @@ static Eina_Mempool * _new_from_buffer(const char *name, void *buffer,
m = eina_list_data(l);
/* check if the requested module name exists */
if (!strncmp(eina_module_name_get(m), name, strlen(name)))
if (!strncmp(eina_module_name_get(m), module, strlen(module) + 1))
{
Eina_Mempool *mp;
@ -37,7 +37,7 @@ static Eina_Mempool * _new_from_buffer(const char *name, void *buffer,
eina_module_load(m);
mp->module = m;
mp->backend = eina_module_symbol_get(m, "mp_backend");
mp->backend_data = mp->backend->init(buffer, size, options, args);
mp->backend_data = mp->backend->init(context, options, args);
return mp;
}
@ -50,7 +50,8 @@ static Eina_Mempool * _new_from_buffer(const char *name, void *buffer,
/**
*
*/
EAPI int eina_mempool_init(void)
EAPI int
eina_mempool_init(void)
{
if (!_init_count)
{
@ -62,7 +63,8 @@ EAPI int eina_mempool_init(void)
/**
*
*/
EAPI int eina_mempool_shutdown(void)
EAPI int
eina_mempool_shutdown(void)
{
if (!_init_count)
return _init_count;
@ -77,38 +79,18 @@ EAPI int eina_mempool_shutdown(void)
/**
*
*/
EAPI Eina_Mempool * eina_mempool_new_from_buffer(const char *name, void *buffer,
unsigned int size, const char *options, ...)
EAPI Eina_Mempool *
eina_mempool_new(const char *name, const char *context, const char *options, ...)
{
Eina_Mempool *mp;
va_list args;
assert(name);
assert(buffer);
va_start(args, options);
mp = _new_from_buffer(name, buffer, size, options, args);
mp = _new_from_buffer(name, context, options, args);
va_end(args);
return mp;
}
/**
*
*/
EAPI Eina_Mempool * eina_mempool_new(const char *name, unsigned int size, const char
*options, ...)
{
Eina_Mempool *mp;
void *buffer;
va_list args;
assert(name);
buffer = malloc(sizeof(char) * size);
va_start(args, options);
mp = _new_from_buffer(name, buffer, size, options, args);
va_end(args);
return mp;
}
/**
@ -116,10 +98,8 @@ EAPI Eina_Mempool * eina_mempool_new(const char *name, unsigned int size, const
*/
EAPI void eina_mempool_delete(Eina_Mempool *mp)
{
Eina_List *l;
assert(mp);
mp->backend->shutdown(mp->backend_data);
eina_module_unload(mp->module);
free(mp);
@ -129,7 +109,10 @@ EAPI void eina_mempool_delete(Eina_Mempool *mp)
*/
EAPI void * eina_mempool_realloc(Eina_Mempool *mp, void *element, unsigned int size)
{
assert(mp);
assert(mp->backend->realloc);
return mp->backend->realloc(mp->backend_data, element, size);
}
/**
*
@ -138,7 +121,7 @@ EAPI void * eina_mempool_alloc(Eina_Mempool *mp, unsigned int size)
{
assert(mp);
assert(mp->backend->alloc);
return mp->backend->alloc(mp->backend_data, size);
}
/**
@ -148,6 +131,6 @@ EAPI void eina_mempool_free(Eina_Mempool *mp, void *element)
{
assert(mp);
assert(mp->backend->free);
mp->backend->free(mp->backend_data, element);
}

View File

@ -1,4 +1,4 @@
SUBDIRS = mm_policies chained_pool
SUBDIRS = mp
MAINTAINERCLEANFILES = \
Makefile.in

View File

@ -0,0 +1,6 @@
Makefile.in
Makefile
*.la
*.lo
.libs
.deps

View File

@ -0,0 +1,6 @@
Makefile.in
Makefile
*.la
*.lo
.libs
.deps

View File

@ -0,0 +1,17 @@
MAINTAINERCLEANFILES = \
Makefile.in
AM_CPPFLAGS = \
-I. \
-I$(top_srcdir)/src/include \
@EMEMOA_CFLAGS@
controllerdir = $(libdir)/eina/chained_pool/
controller_LTLIBRARIES = eina_ememoa_fixed.la
eina_ememoa_fixed_la_SOURCES = \
eina_ememoa_fixed.c
eina_ememoa_fixed_la_LIBADD = $(top_builddir)/src/lib/libeina.la @EMEMOA_LIBS@
eina_ememoa_fixed_la_LDFLAGS = -no-undefined @lt_enable_auto_import@ -module -avoid-version
eina_ememoa_fixed_la_DEPENDENCIES = $(top_builddir)/src/lib/libeina.la

View File

@ -0,0 +1,124 @@
/*
* vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <stdlib.h>
#include <string.h>
#include <ememoa_mempool_fixed.h>
#include "eina_inlist.h"
#include "eina_error.h"
#include "eina_private.h"
typedef struct _Eina_Ememoa_Fixed_Mempool Eina_Ememoa_Fixed_Mempool;
struct _Eina_Ememoa_Fixed_Mempool
{
struct ememoa_mempool_desc_s *desc;
int pool;
};
static void *
eina_ememoa_fixed_malloc(void *data, __UNUSED__ unsigned int size)
{
Eina_Ememoa_Fixed_Mempool *efm = data;
return ememoa_mempool_fixed_pop_object(efm->pool);
}
static void
eina_ememoa_fixed_free(void *data, void *ptr)
{
Eina_Ememoa_Fixed_Mempool *efm = data;
ememoa_mempool_fixed_push_object(efm->pool, ptr);
}
static void*
eina_ememoa_fixed_realloc(__UNUSED__ void *data, __UNUSED__ void *element, __UNUSED__ unsigned int size)
{
return NULL;
}
static void
eina_ememoa_fixed_gc(void *data)
{
Eina_Ememoa_Fixed_Mempool *efm = data;
ememoa_mempool_fixed_garbage_collect(efm->pool);
}
static void
eina_ememoa_fixed_statistics(void *data)
{
Eina_Ememoa_Fixed_Mempool *efm = data;
ememoa_mempool_fixed_display_statistic(efm->pool);
}
static void*
eina_ememoa_fixed_init(const char *context, __UNUSED__ const char *option, va_list args)
{
struct ememoa_mempool_desc_s *desc = NULL;
Eina_Ememoa_Fixed_Mempool *efm;
Eina_Bool thread_protect;
int context_length;
int item_size;
int pool_size;
if (context)
{
context_length = strlen(context) + 1;
desc = calloc(1, sizeof (struct ememoa_mempool_desc_s) + context_length);
if (!desc) goto on_error;
desc->name = (char*) (desc + 1);
memcpy((char*) desc->name, context, context_length);
}
item_size = va_arg(args, int);
pool_size = va_arg(args, int);
thread_protect = va_arg(args, int);
efm = malloc(sizeof (Eina_Ememoa_Fixed_Mempool));
if (!efm) goto on_error;
efm->desc = desc;
efm->pool = ememoa_mempool_fixed_init(item_size,
pool_size,
thread_protect ? EMEMOA_THREAD_PROTECTION : 0,
efm->desc);
if (efm->pool < 0) goto on_error;
return efm;
on_error:
if (desc) free(desc);
if (efm) free(efm);
return NULL;
}
static void
eina_ememoa_fixed_shutdown(void *data)
{
Eina_Ememoa_Fixed_Mempool *efm = data;
if (efm->desc) free(efm->desc);
ememoa_mempool_fixed_clean(efm->pool);
free(efm);
}
Eina_Mempool_Backend mp_backend = {
.init = &eina_ememoa_fixed_init,
.shutdown = &eina_ememoa_fixed_shutdown,
.realloc = &eina_ememoa_fixed_realloc,
.alloc = &eina_ememoa_fixed_malloc,
.free = &eina_ememoa_fixed_free,
.garbage_collect = &eina_ememoa_fixed_gc,
.statistics = &eina_ememoa_fixed_statistics
};