mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-01 15:03:39 +02:00
This commit merges the glib-threads branch into the main
branch. See the ChangeLog for details of the changes. In brief overview: - The set of threading functions can be set - A default implementation is provided in -lgthread - All static data structures are locked using these functions if g_thread_init() is called.
This commit is contained in:
44
glist.c
44
glist.c
@@ -16,6 +16,11 @@
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
* MT safe
|
||||
*/
|
||||
|
||||
#include "glib.h"
|
||||
|
||||
|
||||
@@ -31,9 +36,11 @@ struct _GAllocator /* from gmem.c */
|
||||
};
|
||||
|
||||
static GAllocator *current_allocator = NULL;
|
||||
static G_LOCK_DEFINE(current_allocator);
|
||||
|
||||
void
|
||||
g_list_push_allocator (GAllocator *allocator)
|
||||
/* HOLDS: current_allocator_lock */
|
||||
static void
|
||||
g_list_validate_allocator (GAllocator *allocator)
|
||||
{
|
||||
g_return_if_fail (allocator != NULL);
|
||||
g_return_if_fail (allocator->is_unused == TRUE);
|
||||
@@ -58,13 +65,22 @@ g_list_push_allocator (GAllocator *allocator)
|
||||
}
|
||||
|
||||
allocator->is_unused = FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
g_list_push_allocator(GAllocator *allocator)
|
||||
{
|
||||
g_list_validate_allocator ( allocator );
|
||||
g_lock (current_allocator);
|
||||
allocator->last = current_allocator;
|
||||
current_allocator = allocator;
|
||||
g_unlock (current_allocator);
|
||||
}
|
||||
|
||||
void
|
||||
g_list_pop_allocator (void)
|
||||
{
|
||||
g_lock (current_allocator);
|
||||
if (current_allocator)
|
||||
{
|
||||
GAllocator *allocator;
|
||||
@@ -74,6 +90,7 @@ g_list_pop_allocator (void)
|
||||
allocator->last = NULL;
|
||||
allocator->is_unused = TRUE;
|
||||
}
|
||||
g_unlock (current_allocator);
|
||||
}
|
||||
|
||||
GList*
|
||||
@@ -81,9 +98,15 @@ g_list_alloc (void)
|
||||
{
|
||||
GList *list;
|
||||
|
||||
g_lock (current_allocator);
|
||||
if (!current_allocator)
|
||||
g_list_push_allocator (g_allocator_new ("GLib default GList allocator", 1024));
|
||||
|
||||
{
|
||||
GAllocator *allocator = g_allocator_new ("GLib default GList allocator",
|
||||
1024);
|
||||
g_list_validate_allocator (allocator);
|
||||
allocator->last = NULL;
|
||||
current_allocator = allocator;
|
||||
}
|
||||
if (!current_allocator->free_lists)
|
||||
{
|
||||
list = g_chunk_new (GList, current_allocator->mem_chunk);
|
||||
@@ -103,6 +126,7 @@ g_list_alloc (void)
|
||||
current_allocator->free_lists = list->next;
|
||||
}
|
||||
}
|
||||
g_unlock (current_allocator);
|
||||
list->next = NULL;
|
||||
list->prev = NULL;
|
||||
|
||||
@@ -112,23 +136,31 @@ g_list_alloc (void)
|
||||
void
|
||||
g_list_free (GList *list)
|
||||
{
|
||||
#if 0
|
||||
if (list)
|
||||
{
|
||||
list->data = list->next;
|
||||
list->data = list->next;
|
||||
g_lock (current_allocator);
|
||||
list->next = current_allocator->free_lists;
|
||||
current_allocator->free_lists = list;
|
||||
g_unlock (current_allocator);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
g_list_free_1 (GList *list)
|
||||
{
|
||||
#if 0
|
||||
if (list)
|
||||
{
|
||||
list->data = NULL;
|
||||
list->data = NULL;
|
||||
g_lock (current_allocator);
|
||||
list->next = current_allocator->free_lists;
|
||||
current_allocator->free_lists = list;
|
||||
g_unlock (current_allocator);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
GList*
|
||||
|
Reference in New Issue
Block a user