mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-01 23:13:40 +02:00
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.
This commit is contained in:
35
glib/gtree.c
35
glib/gtree.c
@@ -101,34 +101,11 @@ static GTreeNode* g_tree_node_rotate_right (GTreeNode *node);
|
||||
static void g_tree_node_check (GTreeNode *node);
|
||||
|
||||
|
||||
G_LOCK_DEFINE_STATIC (g_tree_global);
|
||||
static GMemChunk *node_mem_chunk = NULL;
|
||||
static GTreeNode *node_free_list = NULL;
|
||||
|
||||
|
||||
static GTreeNode*
|
||||
g_tree_node_new (gpointer key,
|
||||
gpointer value)
|
||||
{
|
||||
GTreeNode *node;
|
||||
|
||||
G_LOCK (g_tree_global);
|
||||
if (node_free_list)
|
||||
{
|
||||
node = node_free_list;
|
||||
node_free_list = node->right;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!node_mem_chunk)
|
||||
node_mem_chunk = g_mem_chunk_new ("GLib GTreeNode mem chunk",
|
||||
sizeof (GTreeNode),
|
||||
1024,
|
||||
G_ALLOC_ONLY);
|
||||
|
||||
node = g_chunk_new (GTreeNode, node_mem_chunk);
|
||||
}
|
||||
G_UNLOCK (g_tree_global);
|
||||
GTreeNode *node = g_slice_new (GTreeNode);
|
||||
|
||||
node->balance = 0;
|
||||
node->left = NULL;
|
||||
@@ -162,10 +139,7 @@ g_tree_node_destroy (GTreeNode *node,
|
||||
node->value = NULL;
|
||||
#endif /* ENABLE_GC_FRIENDLY */
|
||||
|
||||
G_LOCK (g_tree_global);
|
||||
node->right = node_free_list;
|
||||
node_free_list = node;
|
||||
G_UNLOCK (g_tree_global);
|
||||
g_slice_free (GTreeNode, node);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -742,10 +716,7 @@ g_tree_node_remove (GTree *tree,
|
||||
garbage->value = NULL;
|
||||
#endif /* ENABLE_GC_FRIENDLY */
|
||||
|
||||
G_LOCK (g_tree_global);
|
||||
garbage->right = node_free_list;
|
||||
node_free_list = garbage;
|
||||
G_UNLOCK (g_tree_global);
|
||||
g_slice_free (GTreeNode, garbage);
|
||||
|
||||
*removed = TRUE;
|
||||
}
|
||||
|
Reference in New Issue
Block a user