forked from enlightenment/efl
Avoid some dereferencing and provide inline for mempool alloc/free/realloc.
SVN revision: 36078
This commit is contained in:
parent
d4ae3fc7e1
commit
4423005ab4
|
@ -24,6 +24,7 @@ eina_convert.h \
|
|||
eina_rbtree.h \
|
||||
eina_benchmark.h \
|
||||
eina_inline_rbtree.x \
|
||||
eina_inline_mempool.x \
|
||||
eina_iterator.h
|
||||
|
||||
installed_mainheaderdir = $(prefix)/include/eina-@VMAJ@
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
/* EINA - EFL data type library
|
||||
* Copyright (C) 2008 Cedric Bail
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library;
|
||||
* if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef EINA_INLINE_MEMPOOL_X_
|
||||
#define EINA_INLINE_MEMPOOL_X_
|
||||
|
||||
/* Memory Pool */
|
||||
typedef struct _Eina_Mempool_Backend Eina_Mempool_Backend;
|
||||
struct _Eina_Mempool_Backend
|
||||
{
|
||||
void *(*init)(const char *context, const char *options, va_list args);
|
||||
void (*free)(void *data, void *element);
|
||||
void *(*alloc)(void *data, unsigned int size);
|
||||
void *(*realloc)(void *data, void *element, unsigned int size);
|
||||
void (*garbage_collect)(void *data);
|
||||
void (*statistics)(void *data);
|
||||
void (*shutdown)(void *data);
|
||||
};
|
||||
|
||||
struct _Eina_Mempool
|
||||
{
|
||||
Eina_Module *module;
|
||||
Eina_Mempool_Backend backend;
|
||||
void *backend_data;
|
||||
};
|
||||
|
||||
static inline void *
|
||||
eina_mempool_realloc(Eina_Mempool *mp, void *element, unsigned int size)
|
||||
{
|
||||
return mp->backend.realloc(mp->backend_data, element, size);
|
||||
}
|
||||
|
||||
static inline void *
|
||||
eina_mempool_alloc(Eina_Mempool *mp, unsigned int size)
|
||||
{
|
||||
return mp->backend.alloc(mp->backend_data, size);
|
||||
}
|
||||
|
||||
static inline void
|
||||
eina_mempool_free(Eina_Mempool *mp, void *element)
|
||||
{
|
||||
mp->backend.free(mp->backend_data, element);
|
||||
}
|
||||
|
||||
#endif
|
|
@ -38,13 +38,15 @@ EAPI Eina_Module_Group * eina_mempool_module_group_get(void);
|
|||
EAPI Eina_Mempool * eina_mempool_new(const char *module, const char *context, const char *options, ...);
|
||||
EAPI void eina_mempool_delete(Eina_Mempool *mp);
|
||||
|
||||
EAPI void * eina_mempool_realloc(Eina_Mempool *mp, void *element, unsigned int size);
|
||||
EAPI void * eina_mempool_alloc(Eina_Mempool *mp, unsigned int size);
|
||||
EAPI void eina_mempool_free(Eina_Mempool *mp, void *element);
|
||||
static inline void * eina_mempool_realloc(Eina_Mempool *mp, void *element, unsigned int size);
|
||||
static inline void * eina_mempool_alloc(Eina_Mempool *mp, unsigned int size);
|
||||
static inline void eina_mempool_free(Eina_Mempool *mp, void *element);
|
||||
|
||||
EAPI void eina_mempool_gc(Eina_Mempool *mp);
|
||||
EAPI void eina_mempool_statistics(Eina_Mempool *mp);
|
||||
|
||||
#include "eina_inline_mempool.x"
|
||||
|
||||
/** @} */
|
||||
|
||||
#endif /* EINA_MEMPOOL_H_ */
|
||||
|
|
|
@ -34,16 +34,6 @@
|
|||
static Eina_Module_Group *_group;
|
||||
static int _init_count = 0;
|
||||
|
||||
struct _Eina_Mempool
|
||||
{
|
||||
#ifdef DEBUG
|
||||
unsigned int magic;
|
||||
#endif
|
||||
Eina_Module *module;
|
||||
Eina_Mempool_Backend *backend;
|
||||
void *backend_data;
|
||||
};
|
||||
|
||||
static Eina_Mempool *
|
||||
_new_from_buffer(const char *module, const char *context, const char *options, va_list args)
|
||||
{
|
||||
|
@ -60,8 +50,8 @@ _new_from_buffer(const char *module, const char *context, const char *options, v
|
|||
mp = malloc(sizeof(Eina_Mempool));
|
||||
if (!mp) goto on_error;
|
||||
mp->module = m;
|
||||
mp->backend = eina_module_export_object_get(m);
|
||||
mp->backend_data = mp->backend->init(context, options, args);
|
||||
mp->backend = *(Eina_Mempool_Backend *)eina_module_export_object_get(m);
|
||||
mp->backend_data = mp->backend.init(context, options, args);
|
||||
|
||||
return mp;
|
||||
|
||||
|
@ -108,16 +98,14 @@ eina_mempool_init(void)
|
|||
EAPI int
|
||||
eina_mempool_shutdown(void)
|
||||
{
|
||||
if (!_init_count)
|
||||
return _init_count;
|
||||
_init_count--;
|
||||
if (!_init_count)
|
||||
{
|
||||
/* remove the list of modules */
|
||||
eina_module_group_delete(_group);
|
||||
eina_module_shutdown();
|
||||
}
|
||||
return _init_count;
|
||||
if (_init_count != 0) return _init_count;
|
||||
|
||||
/* remove the list of modules */
|
||||
eina_module_group_delete(_group);
|
||||
eina_module_shutdown();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
EAPI Eina_Module_Group *
|
||||
|
@ -135,7 +123,7 @@ eina_mempool_new(const char *name, const char *context, const char *options, ...
|
|||
Eina_Mempool *mp;
|
||||
va_list args;
|
||||
|
||||
assert(name);
|
||||
if (!name) return NULL;
|
||||
|
||||
va_start(args, options);
|
||||
mp = _new_from_buffer(name, context, options, args);
|
||||
|
@ -149,58 +137,25 @@ eina_mempool_new(const char *name, const char *context, const char *options, ...
|
|||
*/
|
||||
EAPI void eina_mempool_delete(Eina_Mempool *mp)
|
||||
{
|
||||
assert(mp);
|
||||
if (!mp) return ;
|
||||
|
||||
mp->backend->shutdown(mp->backend_data);
|
||||
mp->backend.shutdown(mp->backend_data);
|
||||
eina_module_unload(mp->module);
|
||||
free(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);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
EAPI void eina_mempool_free(Eina_Mempool *mp, void *element)
|
||||
{
|
||||
assert(mp);
|
||||
assert(mp->backend->free);
|
||||
|
||||
mp->backend->free(mp->backend_data, element);
|
||||
}
|
||||
|
||||
EAPI void eina_mempool_gc(Eina_Mempool *mp)
|
||||
{
|
||||
assert(mp);
|
||||
assert(mp->backend->garbage_collect);
|
||||
assert(mp->backend.garbage_collect);
|
||||
|
||||
mp->backend->garbage_collect(mp->backend_data);
|
||||
mp->backend.garbage_collect(mp->backend_data);
|
||||
}
|
||||
|
||||
EAPI void eina_mempool_statistics(Eina_Mempool *mp)
|
||||
{
|
||||
assert(mp);
|
||||
assert(mp->backend->statistics);
|
||||
assert(mp->backend.statistics);
|
||||
|
||||
mp->backend->statistics(mp->backend_data);
|
||||
mp->backend.statistics(mp->backend_data);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue