summaryrefslogtreecommitdiff
path: root/ghash.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 /ghash.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 'ghash.c')
-rw-r--r--ghash.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/ghash.c b/ghash.c
index 4ab82b3fa..724036388 100644
--- a/ghash.c
+++ b/ghash.c
@@ -16,6 +16,11 @@
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
+
+/*
+ * MT safe
+ */
+
#include "glib.h"
@@ -52,6 +57,8 @@ static void g_hash_node_destroy (GHashNode *hash_node);
static void g_hash_nodes_destroy (GHashNode *hash_node);
+static G_LOCK_DEFINE(g_hash_global);
+
static GMemChunk *node_mem_chunk = NULL;
static GHashNode *node_free_list = NULL;
@@ -338,6 +345,7 @@ g_hash_node_new (gpointer key,
{
GHashNode *hash_node;
+ g_lock (g_hash_global);
if (node_free_list)
{
hash_node = node_free_list;
@@ -352,6 +360,7 @@ g_hash_node_new (gpointer key,
hash_node = g_chunk_new (GHashNode, node_mem_chunk);
}
+ g_unlock (g_hash_global);
hash_node->key = key;
hash_node->value = value;
@@ -363,8 +372,10 @@ g_hash_node_new (gpointer key,
static void
g_hash_node_destroy (GHashNode *hash_node)
{
+ g_lock (g_hash_global);
hash_node->next = node_free_list;
node_free_list = hash_node;
+ g_unlock (g_hash_global);
}
static void
@@ -380,6 +391,8 @@ g_hash_nodes_destroy (GHashNode *hash_node)
while (node->next)
node = node->next;
+ g_lock (g_hash_global);
node->next = node_free_list;
node_free_list = hash_node;
+ g_unlock (g_hash_global);
}