summaryrefslogtreecommitdiff
path: root/glist.c
diff options
context:
space:
mode:
authorOwen Taylor <otaylor@src.gnome.org>1998-12-15 05:28:02 +0000
committerOwen Taylor <otaylor@src.gnome.org>1998-12-15 05:28:02 +0000
commit931ea952650b013b834041b91b0c37a748ffd449 (patch)
tree0c97c450b0e07953d836f1603c6fcb0357a58149 /glist.c
parentc8ba100dab8949c49097f11004c09ef36ea5136f (diff)
downloadglib-931ea952650b013b834041b91b0c37a748ffd449.tar.gz
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.
Diffstat (limited to 'glist.c')
-rw-r--r--glist.c44
1 files changed, 38 insertions, 6 deletions
diff --git a/glist.c b/glist.c
index 41a09dd18..e74dee872 100644
--- a/glist.c
+++ b/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*