summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkira TAGOH <akira@tagoh.org>2006-09-04 12:07:52 +0000
committerAkira TAGOH <akira@tagoh.org>2006-09-04 12:07:52 +0000
commit87798d45bbb473b63f8415cd06f5d1afd5fb5451 (patch)
tree755ff4bb6b76818d8394298cb58fbac7da65f4d0
parentfc6356e512fcc09fc05848d77e3be87684d0c56d (diff)
* hieroglyph/hgallocator-libc.[ch]: removed.
-rw-r--r--ChangeLog2
-rw-r--r--hieroglyph/Makefile.am6
-rw-r--r--hieroglyph/hgallocator-bfit.c84
-rw-r--r--hieroglyph/hgallocator-libc.c224
-rw-r--r--hieroglyph/hgallocator-libc.h35
-rw-r--r--hieroglyph/version.h.in2
6 files changed, 44 insertions, 309 deletions
diff --git a/ChangeLog b/ChangeLog
index ff4e68f..4f0bfa4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,7 @@
2006-09-04 Akira TAGOH <at@gclab.org>
+ * hieroglyph/hgallocator-libc.[ch]: removed.
+
* hieroglyph/hgallocator-bfit.c: use HgList instead of GSList.
(_hg_allocator_bfit_btree_traverse_in_destroy): removed.
(_hg_allocator_bfit_real_initialize): libc pool is no longer needed.
diff --git a/hieroglyph/Makefile.am b/hieroglyph/Makefile.am
index c40a739..75840f5 100644
--- a/hieroglyph/Makefile.am
+++ b/hieroglyph/Makefile.am
@@ -37,7 +37,6 @@ hgincludedir = $(includedir)/hieroglyph
hginclude_HEADERS = \
$(built_headers) \
hgallocator-bfit.h \
- hgallocator-libc.h \
hgarray.h \
hgbtree.h \
hgdebug.h \
@@ -75,8 +74,11 @@ lib_LTLIBRARIES = \
$(NULL)
libhieroglyph_la_SOURCES = \
+ ibtree.c \
+ ibtree.h \
+ ilist.c \
+ ilist.h \
hgallocator-bfit.c \
- hgallocator-libc.c \
hgarray.c \
hgbtree.c \
hgdebug.c \
diff --git a/hieroglyph/hgallocator-bfit.c b/hieroglyph/hgallocator-bfit.c
index 6321e38..fb89e67 100644
--- a/hieroglyph/hgallocator-bfit.c
+++ b/hieroglyph/hgallocator-bfit.c
@@ -28,10 +28,10 @@
#include <string.h>
#include <setjmp.h>
#include "hgallocator-bfit.h"
-#include "hgallocator-libc.h"
#include "hgallocator-private.h"
#include "hgmem.h"
-#include "hgbtree.h"
+#include "ibtree.h"
+#include "ilist.h"
#include "hgstring.h"
@@ -47,8 +47,6 @@ struct _HieroGlyphAllocatorBFitPrivate {
GPtrArray *heap2block_array;
HgBTree *obj2block_tree;
gint age_of_snapshot;
- HgAllocator *libc_allocator;
- HgMemPool *libc_pool;
};
struct _HieroGlyphMemBFitBlock {
@@ -153,7 +151,7 @@ _hg_allocator_bfit_remove_block(HgAllocatorBFitPrivate *priv,
HgMemBFitBlock *block)
{
gsize aligned;
- GSList *l, *tmp = NULL;
+ HgList *l;
_hg_allocator_get_minimum_aligned_size__inline(block->length,
HG_MEM_ALIGNMENT,
@@ -162,11 +160,13 @@ _hg_allocator_bfit_remove_block(HgAllocatorBFitPrivate *priv,
g_warning("[BUG] there are no memory chunks sized %" G_GSIZE_FORMAT " (aligned size: %" G_GSIZE_FORMAT ".\n",
block->length, aligned);
} else {
- if ((tmp = g_slist_find(l, block)) == NULL) {
+ HgListIter iter = hg_list_find_iter(l, block);
+
+ if (iter == NULL) {
g_warning("[BUG] can't find a memory block %p (size: %" G_GSIZE_FORMAT ", aligned size: %" G_GSIZE_FORMAT ".\n",
block, block->length, aligned);
} else {
- l = g_slist_delete_link(l, tmp);
+ l = hg_list_iter_delete_link(iter);
if (l == NULL) {
/* remove node from tree */
hg_btree_remove(priv->free_block_tree,
@@ -175,6 +175,7 @@ _hg_allocator_bfit_remove_block(HgAllocatorBFitPrivate *priv,
hg_btree_replace(priv->free_block_tree,
GSIZE_TO_POINTER (aligned), l);
}
+ hg_list_iter_free(iter);
}
}
}
@@ -184,7 +185,7 @@ _hg_allocator_bfit_add_free_block(HgAllocatorBFitPrivate *priv,
HgMemBFitBlock *block)
{
gsize aligned;
- GSList *l;
+ HgList *l;
block->in_use = 0;
/* clear data to avoid incomplete header detection */
@@ -231,12 +232,11 @@ _hg_allocator_bfit_add_free_block(HgAllocatorBFitPrivate *priv,
HG_MEM_ALIGNMENT,
aligned);
if ((l = hg_btree_find(priv->free_block_tree, GSIZE_TO_POINTER (aligned))) == NULL) {
- l = g_slist_alloc();
- l->data = block;
- l->next = NULL;
+ l = _hg_list_new();
+ l = hg_list_append(l, block);
hg_btree_add(priv->free_block_tree, GSIZE_TO_POINTER (aligned), l);
} else {
- l = g_slist_prepend(l, block);
+ l = hg_list_prepend(l, block);
hg_btree_replace(priv->free_block_tree, GSIZE_TO_POINTER (aligned), l);
}
}
@@ -247,7 +247,8 @@ _hg_allocator_bfit_get_free_block(HgMemPool *pool,
gsize size)
{
gsize aligned, real_aligned;
- GSList *l;
+ HgList *l;
+ HgListIter iter;
HgMemBFitBlock *retval = NULL;
g_return_val_if_fail (size % HG_MEM_ALIGNMENT == 0, NULL);
@@ -255,11 +256,15 @@ _hg_allocator_bfit_get_free_block(HgMemPool *pool,
_hg_allocator_get_minimum_aligned_size__inline(size, HG_MEM_ALIGNMENT, aligned);
if ((l = hg_btree_find_near(priv->free_block_tree, GSIZE_TO_POINTER (aligned))) == NULL)
return NULL;
- retval = l->data;
+ iter = hg_list_iter_new(l);
+ if (iter == NULL)
+ return NULL;
+ retval = hg_list_iter_get_data(iter);
_hg_allocator_get_minimum_aligned_size__inline(retval->length,
HG_MEM_ALIGNMENT,
real_aligned);
- l = g_slist_delete_link(l, l);
+ l = hg_list_iter_delete_link(iter);
+ hg_list_iter_free(iter);
if (l == NULL) {
hg_btree_remove(priv->free_block_tree,
GSIZE_TO_POINTER (real_aligned));
@@ -297,16 +302,6 @@ _hg_allocator_bfit_get_free_block(HgMemPool *pool,
return retval;
}
-static gboolean
-_hg_allocator_bfit_btree_traverse_in_destroy(gpointer key,
- gpointer val,
- gpointer data)
-{
- g_slist_free(val);
-
- return TRUE;
-}
-
static void
_hg_allocator_bfit_relocate(HgMemPool *pool,
HgMemRelocateInfo *info)
@@ -408,24 +403,9 @@ _hg_allocator_bfit_real_initialize(HgMemPool *pool,
return FALSE;
}
- priv->libc_allocator = hg_allocator_new(hg_allocator_libc_get_vtable());
- priv->libc_pool = hg_mem_pool_new(priv->libc_allocator, "libc", 256, FALSE);
- if (priv->libc_pool == NULL) {
- hg_heap_free(heap);
- hg_allocator_destroy(priv->libc_allocator);
- g_free(priv);
-
- return FALSE;
- }
- hg_mem_pool_allow_resize(priv->libc_pool, FALSE);
- hg_mem_pool_use_periodical_gc(priv->libc_pool, FALSE);
- hg_mem_pool_use_garbage_collection(priv->libc_pool, FALSE);
-
- priv->free_block_tree = hg_btree_new(priv->libc_pool, BTREE_N_NODE);
- hg_btree_allow_marking(priv->free_block_tree, FALSE);
+ priv->free_block_tree = hg_btree_new(BTREE_N_NODE);
priv->heap2block_array = g_ptr_array_new();
- priv->obj2block_tree = hg_btree_new(priv->libc_pool, BTREE_N_NODE);
- hg_btree_allow_marking(priv->obj2block_tree, FALSE);
+ priv->obj2block_tree = hg_btree_new(BTREE_N_NODE);
priv->age_of_snapshot = 0;
g_ptr_array_add(priv->heap2block_array, block);
@@ -438,6 +418,16 @@ _hg_allocator_bfit_real_initialize(HgMemPool *pool,
}
static gboolean
+_hg_allocator_bfit_real_free_block_traverse(gpointer key,
+ gpointer val,
+ gpointer data)
+{
+ hg_list_free(val);
+
+ return TRUE;
+}
+
+static gboolean
_hg_allocator_bfit_real_destroy(HgMemPool *pool)
{
HgAllocatorBFitPrivate *priv = pool->allocator->private;
@@ -465,11 +455,11 @@ _hg_allocator_bfit_real_destroy(HgMemPool *pool)
}
g_ptr_array_free(priv->heap2block_array, TRUE);
}
- hg_btree_foreach(priv->free_block_tree, _hg_allocator_bfit_btree_traverse_in_destroy, NULL);
- hg_mem_free(priv->free_block_tree);
- hg_mem_free(priv->obj2block_tree);
- hg_mem_pool_destroy(priv->libc_pool);
- hg_allocator_destroy(priv->libc_allocator);
+ hg_btree_foreach(priv->free_block_tree,
+ _hg_allocator_bfit_real_free_block_traverse,
+ NULL);
+ hg_btree_destroy(priv->free_block_tree);
+ hg_btree_destroy(priv->obj2block_tree);
g_free(priv);
return TRUE;
diff --git a/hieroglyph/hgallocator-libc.c b/hieroglyph/hgallocator-libc.c
deleted file mode 100644
index c1c2e68..0000000
--- a/hieroglyph/hgallocator-libc.c
+++ /dev/null
@@ -1,224 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-/*
- * hgallocator-libc.c
- * Copyright (C) 2006 Akira TAGOH
- *
- * Authors:
- * Akira TAGOH <at@gclab.org>
- *
- * 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 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, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include "hgallocator-libc.h"
-#include "hgallocator-private.h"
-#include "hgmem.h"
-
-
-typedef struct _HieroGlyphAllocatorLibcPrivate HgAllocatorLibcPrivate;
-
-
-struct _HieroGlyphAllocatorLibcPrivate {
- GSList *chunk_list;
-};
-
-
-static gboolean _hg_allocator_libc_real_initialize (HgMemPool *pool,
- gsize prealloc);
-static gboolean _hg_allocator_libc_real_destroy (HgMemPool *pool);
-static gboolean _hg_allocator_libc_real_resize_pool (HgMemPool *pool,
- gsize size);
-static gpointer _hg_allocator_libc_real_alloc (HgMemPool *pool,
- gsize size,
- guint flags);
-static void _hg_allocator_libc_real_free (HgMemPool *pool,
- gpointer data);
-static gpointer _hg_allocator_libc_real_resize (HgMemObject *object,
- gsize size);
-static gsize _hg_allocator_libc_real_get_size (HgMemObject *object);
-static gboolean _hg_allocator_libc_real_garbage_collection(HgMemPool *pool);
-static void _hg_allocator_libc_real_gc_mark (HgMemPool *pool);
-static gboolean _hg_allocator_libc_real_is_safe_object (HgMemPool *pool,
- HgMemObject *object);
-static HgMemSnapshot *_hg_allocator_libc_real_save_snapshot (HgMemPool *pool);
-static gboolean _hg_allocator_libc_real_restore_snapshot (HgMemPool *pool,
- HgMemSnapshot *snapshot);
-
-
-static HgAllocatorVTable __hg_allocator_libc_vtable = {
- .initialize = _hg_allocator_libc_real_initialize,
- .destroy = _hg_allocator_libc_real_destroy,
- .resize_pool = _hg_allocator_libc_real_resize_pool,
- .alloc = _hg_allocator_libc_real_alloc,
- .free = _hg_allocator_libc_real_free,
- .resize = _hg_allocator_libc_real_resize,
- .get_size = _hg_allocator_libc_real_get_size,
- .garbage_collection = _hg_allocator_libc_real_garbage_collection,
- .gc_mark = _hg_allocator_libc_real_gc_mark,
- .is_safe_object = _hg_allocator_libc_real_is_safe_object,
- .save_snapshot = _hg_allocator_libc_real_save_snapshot,
- .restore_snapshot = _hg_allocator_libc_real_restore_snapshot,
-};
-
-
-/* dummy allocator with libc */
-static gboolean
-_hg_allocator_libc_real_initialize(HgMemPool *pool,
- gsize prealloc)
-{
- HgAllocatorLibcPrivate *priv;
-
- priv = g_new0(HgAllocatorLibcPrivate, 1);
- if (priv == NULL)
- return FALSE;
-
- pool->total_heap_size = pool->initial_heap_size = prealloc;
-
- priv->chunk_list = NULL;
-
- pool->allocator->private = priv;
-
- return TRUE;
-}
-
-static gboolean
-_hg_allocator_libc_real_destroy(HgMemPool *pool)
-{
- HgAllocatorLibcPrivate *priv = pool->allocator->private;
- GSList *l = priv->chunk_list;
-
- while (l) {
- HgMemObject *obj = l->data;
-
- hg_mem_free(obj->data);
- l = g_slist_next(l);
- }
-
- g_slist_free(priv->chunk_list);
- g_free(priv);
-
- return TRUE;
-}
-
-static gboolean
-_hg_allocator_libc_real_resize_pool(HgMemPool *pool,
- gsize size)
-{
- pool->total_heap_size += size;
-
- return TRUE;
-}
-
-static gpointer
-_hg_allocator_libc_real_alloc(HgMemPool *pool,
- gsize size,
- guint flags)
-{
- HgAllocatorLibcPrivate *priv = pool->allocator->private;
- HgMemObject *retval;
-
- size += sizeof (HgMemObject);
-
- retval = g_malloc(size);
- if (!retval)
- return NULL;
-
- HG_SET_MAGIC_CODE (retval, HG_MEM_HEADER);
- retval->subid = 0;
- retval->pool = pool;
- HG_MEMOBJ_INIT_FLAGS (retval);
- HG_MEMOBJ_SET_HEAP_ID (retval, 0);
- if ((flags & HG_FL_HGOBJECT) != 0)
- HG_MEMOBJ_SET_HGOBJECT_ID (retval);
- HG_MEMOBJ_SET_FLAGS (retval, flags);
-
- priv->chunk_list = g_slist_append(priv->chunk_list, retval);
-
- return retval->data;
-}
-
-static void
-_hg_allocator_libc_real_free(HgMemPool *pool,
- gpointer data)
-{
- HgAllocatorLibcPrivate *priv = pool->allocator->private;
- HgMemObject *obj;
-
- hg_mem_get_object__inline(data, obj);
- if (obj == NULL) {
- g_warning("[BUG] Unknown object %p is going to be destroyed.", data);
- return;
- }
- priv->chunk_list = g_slist_remove(priv->chunk_list, obj);
- g_free(obj);
-}
-
-static gpointer
-_hg_allocator_libc_real_resize(HgMemObject *object,
- gsize size)
-{
- return NULL;
-}
-
-static gsize
-_hg_allocator_libc_real_get_size(HgMemObject *object)
-{
- return 0;
-}
-
-static gboolean
-_hg_allocator_libc_real_garbage_collection(HgMemPool *pool)
-{
- return FALSE;
-}
-
-static void
-_hg_allocator_libc_real_gc_mark(HgMemPool *pool)
-{
-}
-
-static gboolean
-_hg_allocator_libc_real_is_safe_object(HgMemPool *pool,
- HgMemObject *object)
-{
- HgAllocatorLibcPrivate *priv = pool->allocator->private;
-
- return g_slist_find(priv->chunk_list, object) != NULL;
-}
-
-static HgMemSnapshot *
-_hg_allocator_libc_real_save_snapshot(HgMemPool *pool)
-{
- return NULL;
-}
-
-static gboolean
-_hg_allocator_libc_real_restore_snapshot(HgMemPool *pool,
- HgMemSnapshot *snapshot)
-{
- return FALSE;
-}
-
-/*
- * Public Functions
- */
-HgAllocatorVTable *
-hg_allocator_libc_get_vtable(void)
-{
- return &__hg_allocator_libc_vtable;
-}
diff --git a/hieroglyph/hgallocator-libc.h b/hieroglyph/hgallocator-libc.h
deleted file mode 100644
index 8bca4b0..0000000
--- a/hieroglyph/hgallocator-libc.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-/*
- * hgallocator-libc.h
- * Copyright (C) 2006 Akira TAGOH
- *
- * Authors:
- * Akira TAGOH <at@gclab.org>
- *
- * 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 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, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-#ifndef __HG_ALLOCATOR_LIBC_H__
-#define __HG_ALLOCATOR_LIBC_H__
-
-#include <hieroglyph/hgtypes.h>
-
-G_BEGIN_DECLS
-
-HgAllocatorVTable *hg_allocator_libc_get_vtable(void) G_GNUC_CONST;
-
-G_END_DECLS
-
-#endif /* __HG_ALLOCATOR_LIBC_H__ */
diff --git a/hieroglyph/version.h.in b/hieroglyph/version.h.in
index ecd5a16..0587b49 100644
--- a/hieroglyph/version.h.in
+++ b/hieroglyph/version.h.in
@@ -29,7 +29,7 @@
G_BEGIN_DECLS
#define HIEROGLYPH_VERSION "@VERSION@"
-#define HIEROGLYPH_UUID "22af8123-418d-4988-a0ec-3b2381a8739c"
+#define HIEROGLYPH_UUID "77b6a045-2407-4ed4-bbe7-d92806cf58cc"
const char *__hg_rcsid G_GNUC_UNUSED = "$Rev$";