diff options
author | Owen Taylor <otaylor@src.gnome.org> | 1998-12-15 05:28:02 +0000 |
---|---|---|
committer | Owen Taylor <otaylor@src.gnome.org> | 1998-12-15 05:28:02 +0000 |
commit | 931ea952650b013b834041b91b0c37a748ffd449 (patch) | |
tree | 0c97c450b0e07953d836f1603c6fcb0357a58149 /gtree.c | |
parent | c8ba100dab8949c49097f11004c09ef36ea5136f (diff) |
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 'gtree.c')
-rw-r--r-- | gtree.c | 18 |
1 files changed, 15 insertions, 3 deletions
@@ -16,6 +16,11 @@ * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ + +/* + * MT safe + */ + #include "glib.h" @@ -78,6 +83,7 @@ static GTreeNode* g_tree_node_rotate_right (GTreeNode *node); static void g_tree_node_check (GTreeNode *node); +static G_LOCK_DEFINE(g_tree_global); static GMemChunk *node_mem_chunk = NULL; static GTreeNode *node_free_list = NULL; @@ -88,6 +94,7 @@ g_tree_node_new (gpointer key, { GTreeNode *node; + g_lock (g_tree_global); if (node_free_list) { node = node_free_list; @@ -102,7 +109,8 @@ g_tree_node_new (gpointer key, G_ALLOC_ONLY); node = g_chunk_new (GTreeNode, node_mem_chunk); - } + } + g_unlock (g_tree_global); node->balance = 0; node->left = NULL; @@ -120,9 +128,11 @@ g_tree_node_destroy (GTreeNode *node) { g_tree_node_destroy (node->right); g_tree_node_destroy (node->left); + g_lock (g_tree_global); node->right = node_free_list; node_free_list = node; - } + g_unlock (g_tree_global); + } } @@ -375,9 +385,11 @@ g_tree_node_remove (GTreeNode *node, node = g_tree_node_restore_right_balance (new_root, old_balance); } + g_lock (g_tree_global); garbage->right = node_free_list; node_free_list = garbage; - } + g_unlock (g_tree_global); + } else if (cmp < 0) { if (node->left) |