From a309e49392ea6fb67f0aa45d75225a7de5d0c6c1 Mon Sep 17 00:00:00 2001 From: Cedric BAIL Date: Thu, 31 Jul 2008 17:00:56 +0000 Subject: [PATCH] Cleanup the mempool stuff. SVN revision: 35277 --- legacy/eina/configure.in | 31 ++++- legacy/eina/src/lib/eina_mempool.c | 61 ++++----- legacy/eina/src/modules/Makefile.am | 2 +- .../src/modules/mp/chained_pool/.cvsignore | 6 + .../modules/{ => mp}/chained_pool/Makefile.am | 0 .../chained_pool/eina_chained_mempool.c | 0 .../src/modules/mp/ememoa_fixed/.cvsignore | 6 + .../src/modules/mp/ememoa_fixed/Makefile.am | 17 +++ .../mp/ememoa_fixed/eina_ememoa_fixed.c | 124 ++++++++++++++++++ 9 files changed, 204 insertions(+), 43 deletions(-) create mode 100644 legacy/eina/src/modules/mp/chained_pool/.cvsignore rename legacy/eina/src/modules/{ => mp}/chained_pool/Makefile.am (100%) rename legacy/eina/src/modules/{ => mp}/chained_pool/eina_chained_mempool.c (100%) create mode 100644 legacy/eina/src/modules/mp/ememoa_fixed/.cvsignore create mode 100644 legacy/eina/src/modules/mp/ememoa_fixed/Makefile.am create mode 100644 legacy/eina/src/modules/mp/ememoa_fixed/eina_ememoa_fixed.c diff --git a/legacy/eina/configure.in b/legacy/eina/configure.in index 255276213b..265c8b0601 100644 --- a/legacy/eina/configure.in +++ b/legacy/eina/configure.in @@ -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" diff --git a/legacy/eina/src/lib/eina_mempool.c b/legacy/eina/src/lib/eina_mempool.c index 6a7681b99d..5eed0a01c3 100644 --- a/legacy/eina/src/lib/eina_mempool.c +++ b/legacy/eina/src/lib/eina_mempool.c @@ -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); } diff --git a/legacy/eina/src/modules/Makefile.am b/legacy/eina/src/modules/Makefile.am index 11355f640c..53e28b7bf9 100644 --- a/legacy/eina/src/modules/Makefile.am +++ b/legacy/eina/src/modules/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS = mm_policies chained_pool +SUBDIRS = mp MAINTAINERCLEANFILES = \ Makefile.in \ No newline at end of file diff --git a/legacy/eina/src/modules/mp/chained_pool/.cvsignore b/legacy/eina/src/modules/mp/chained_pool/.cvsignore new file mode 100644 index 0000000000..b9f26ab26b --- /dev/null +++ b/legacy/eina/src/modules/mp/chained_pool/.cvsignore @@ -0,0 +1,6 @@ +Makefile.in +Makefile +*.la +*.lo +.libs +.deps diff --git a/legacy/eina/src/modules/chained_pool/Makefile.am b/legacy/eina/src/modules/mp/chained_pool/Makefile.am similarity index 100% rename from legacy/eina/src/modules/chained_pool/Makefile.am rename to legacy/eina/src/modules/mp/chained_pool/Makefile.am diff --git a/legacy/eina/src/modules/chained_pool/eina_chained_mempool.c b/legacy/eina/src/modules/mp/chained_pool/eina_chained_mempool.c similarity index 100% rename from legacy/eina/src/modules/chained_pool/eina_chained_mempool.c rename to legacy/eina/src/modules/mp/chained_pool/eina_chained_mempool.c diff --git a/legacy/eina/src/modules/mp/ememoa_fixed/.cvsignore b/legacy/eina/src/modules/mp/ememoa_fixed/.cvsignore new file mode 100644 index 0000000000..b9f26ab26b --- /dev/null +++ b/legacy/eina/src/modules/mp/ememoa_fixed/.cvsignore @@ -0,0 +1,6 @@ +Makefile.in +Makefile +*.la +*.lo +.libs +.deps diff --git a/legacy/eina/src/modules/mp/ememoa_fixed/Makefile.am b/legacy/eina/src/modules/mp/ememoa_fixed/Makefile.am new file mode 100644 index 0000000000..bdb83e6cd6 --- /dev/null +++ b/legacy/eina/src/modules/mp/ememoa_fixed/Makefile.am @@ -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 diff --git a/legacy/eina/src/modules/mp/ememoa_fixed/eina_ememoa_fixed.c b/legacy/eina/src/modules/mp/ememoa_fixed/eina_ememoa_fixed.c new file mode 100644 index 0000000000..a0d76fdc6a --- /dev/null +++ b/legacy/eina/src/modules/mp/ememoa_fixed/eina_ememoa_fixed.c @@ -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 +#include +#include + +#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 +};