diff options
author | Tim Janik <timj@imendio.com> | 2005-11-01 18:10:31 +0000 |
---|---|---|
committer | Tim Janik <timj@src.gnome.org> | 2005-11-01 18:10:31 +0000 |
commit | 0cba1b531d5d28890fa4f48359d4e7adacf2a603 (patch) | |
tree | fa2a88ef5c43b20004851e2b9f3eb14cf10c71f2 /glib/gnode.c | |
parent | 3a042a8959501f9e90df41fc31e3167dd7aa6222 (diff) | |
download | glib-0cba1b531d5d28890fa4f48359d4e7adacf2a603.tar.gz |
prepared deprecation of GMemChunk and GAllocator. added g_slice_*() API to
Tue Nov 1 16:24:20 2005 Tim Janik <timj@imendio.com>
* glib/gmem.[hc]: prepared deprecation of GMemChunk and GAllocator.
added g_slice_*() API to allocate and cache small bits of memory.
an actuall allocator implementation for g_slice_*() is still pending.
* glib/gthread.[hc]: changes from a patch by Matthias Clasen.
changed GRealThread list to use in-structure *next; fields instead
of GSList, in order for thread iteration to not depenend on g_slice_*()
indirectly.
_g_thread_mem_private_get():
_g_thread_mem_private_set(): added accessors for private memory,
needed because the ordinary GPrivate implementation relies on GArray
and GSList and therefore indirectly on working g_slice_*() allocations.
* glib/gthread.[hc]:
g_thread_foreach(): new public API function to loop over all existing threads.
* glib/gdataset.c:
* glib/gstring.c:
* glib/gcache.c:
* glib/garray.c:
* glib/gqueue.c:
* glib/gslist.c:
* glib/glist.c:
* glib/ghash.c:
* glib/gtree.c:
* glib/ghook.c:
* glib/gmain.c:
* glib/gnode.c:
removed GAllocator and free list usages and accompanying locks.
use g_slice_*() API to allocate and cache small bits of memory.
* glib/ghook.h: removed GMemChunk field from public API.
* glib/gslist.h:
* glib/glist.h: deprecate allocator API, provide _free1() for consistency.
* glib/gnode.h: deprecate allocator API.
* glib/gmain.c: reordered GPollRec fields so g_slice_free_chain() can
be used for poll rec lists.
* glib/grel.c: removed mem chunk usage, and allocated tuples via g_slice_*().
g_relation_destroy(): free all tuples from the all_tuples hash table,
this effectively maintains the life time track keeping of tuples.
g_relation_delete_tuple(): free tuples which are removed from the
all_tuples hash table. this fixes a temporary leak that was present
in the memchunk code until the destruction of the relation.
Diffstat (limited to 'glib/gnode.c')
-rw-r--r-- | glib/gnode.c | 157 |
1 files changed, 10 insertions, 147 deletions
diff --git a/glib/gnode.c b/glib/gnode.c index 572da5cc4..c9c5bcb96 100644 --- a/glib/gnode.c +++ b/glib/gnode.c @@ -36,170 +36,33 @@ #include "glib.h" #include "galias.h" -#ifndef DISABLE_MEM_POOLS -/* node allocation - */ -struct _GAllocator /* from gmem.c */ -{ - gchar *name; - guint16 n_preallocs; - guint is_unused : 1; - guint type : 4; - GAllocator *last; - GMemChunk *mem_chunk; - GNode *free_nodes; /* implementation specific */ -}; - -G_LOCK_DEFINE_STATIC (current_allocator); -static GAllocator *current_allocator = NULL; - -/* HOLDS: current_allocator_lock */ -static void -g_node_validate_allocator (GAllocator *allocator) -{ - g_return_if_fail (allocator != NULL); - g_return_if_fail (allocator->is_unused == TRUE); - - if (allocator->type != G_ALLOCATOR_NODE) - { - allocator->type = G_ALLOCATOR_NODE; - if (allocator->mem_chunk) - { - g_mem_chunk_destroy (allocator->mem_chunk); - allocator->mem_chunk = NULL; - } - } - - if (!allocator->mem_chunk) - { - allocator->mem_chunk = g_mem_chunk_new (allocator->name, - sizeof (GNode), - sizeof (GNode) * allocator->n_preallocs, - G_ALLOC_ONLY); - allocator->free_nodes = NULL; - } - - allocator->is_unused = FALSE; -} - -void -g_node_push_allocator (GAllocator *allocator) -{ - G_LOCK (current_allocator); - g_node_validate_allocator (allocator); - allocator->last = current_allocator; - current_allocator = allocator; - G_UNLOCK (current_allocator); -} - -void -g_node_pop_allocator (void) -{ - G_LOCK (current_allocator); - if (current_allocator) - { - GAllocator *allocator; - - allocator = current_allocator; - current_allocator = allocator->last; - allocator->last = NULL; - allocator->is_unused = TRUE; - } - G_UNLOCK (current_allocator); -} +void g_node_push_allocator (gpointer dummy) { /* present for binary compat only */ } +void g_node_pop_allocator (void) { /* present for binary compat only */ } +#define g_node_alloc0() g_slice_new0 (GNode) +#define g_node_free(node) g_slice_free (GNode, node) /* --- functions --- */ GNode* g_node_new (gpointer data) { - GNode *node; - - G_LOCK (current_allocator); - if (!current_allocator) - { - GAllocator *allocator = g_allocator_new ("GLib default GNode allocator", - 128); - g_node_validate_allocator (allocator); - allocator->last = NULL; - current_allocator = allocator; - } - if (!current_allocator->free_nodes) - node = g_chunk_new (GNode, current_allocator->mem_chunk); - else - { - node = current_allocator->free_nodes; - current_allocator->free_nodes = node->next; - } - G_UNLOCK (current_allocator); - + GNode *node = g_node_alloc0(); node->data = data; - node->next = NULL; - node->prev = NULL; - node->parent = NULL; - node->children = NULL; - return node; } static void g_nodes_free (GNode *node) { - GNode *parent; - - parent = node; - while (1) - { - if (parent->children) - g_nodes_free (parent->children); - -#ifdef ENABLE_GC_FRIENDLY - parent->data = NULL; - parent->prev = NULL; - parent->parent = NULL; - parent->children = NULL; -#endif /* ENABLE_GC_FRIENDLY */ - - if (parent->next) - parent = parent->next; - else - break; - } - - G_LOCK (current_allocator); - parent->next = current_allocator->free_nodes; - current_allocator->free_nodes = node; - G_UNLOCK (current_allocator); -} -#else /* DISABLE_MEM_POOLS */ - -GNode* -g_node_new (gpointer data) -{ - GNode *node; - - node = g_new0 (GNode, 1); - - node->data = data; - - return node; -} - -static void -g_nodes_free (GNode *root) -{ - GNode *node, *next; - - node = root; - while (node != NULL) + while (node) { - next = node->next; - g_nodes_free (node->children); - g_free (node); + GNode *next = node->next; + if (node->children) + g_nodes_free (node->children); + g_node_free (node); node = next; } } -#endif void g_node_destroy (GNode *root) |