From c756f8b9f71189eb9070659f34ecd8b7367b2ad3 Mon Sep 17 00:00:00 2001 From: Christian Thalinger Date: Fri, 8 Aug 2008 19:13:36 +0200 Subject: [PATCH] * src/toolbox/avl.c (avl_create): Use Mutex functions. (avl_insert, avl_find): Likewise. * src/toolbox/avl.h (avl_tree_t): Removed lock and added mutex. --- src/toolbox/avl.c | 21 +++++++-------------- src/toolbox/avl.h | 18 ++++++++---------- 2 files changed, 15 insertions(+), 24 deletions(-) diff --git a/src/toolbox/avl.c b/src/toolbox/avl.c index 0b6b48144..404328c05 100644 --- a/src/toolbox/avl.c +++ b/src/toolbox/avl.c @@ -31,7 +31,7 @@ #include "mm/memory.h" -#include "threads/lock-common.h" +#include "threads/mutex.hpp" #include "toolbox/avl.h" #include "toolbox/logging.h" @@ -52,18 +52,11 @@ avl_tree_t *avl_create(avl_comparator *comparator) t = NEW(avl_tree_t); + t->mutex = Mutex_new(); t->root = NULL; t->comparator = comparator; t->entries = 0; -#if defined(ENABLE_THREADS) - /* create lock object for this tree */ - - t->lock = NEW(java_object_t); - - LOCK_INIT_OBJECT_LOCK(t->lock); -#endif - return t; } @@ -310,7 +303,7 @@ bool avl_insert(avl_tree_t *tree, void *data) assert(tree); assert(data); - LOCK_MONITOR_ENTER(tree->lock); + Mutex_lock(tree->mutex); /* if we don't have a root node, create one */ @@ -323,7 +316,7 @@ bool avl_insert(avl_tree_t *tree, void *data) tree->entries++; - LOCK_MONITOR_EXIT(tree->lock); + Mutex_unlock(tree->mutex); /* insertion was ok */ @@ -346,7 +339,7 @@ void *avl_find(avl_tree_t *tree, void *data) assert(tree); assert(data); - LOCK_MONITOR_ENTER(tree->lock); + Mutex_lock(tree->mutex); /* search the tree for the given node */ @@ -358,7 +351,7 @@ void *avl_find(avl_tree_t *tree, void *data) /* was the entry found? return it */ if (res == 0) { - LOCK_MONITOR_EXIT(tree->lock); + Mutex_unlock(tree->mutex); return node->data; } @@ -368,7 +361,7 @@ void *avl_find(avl_tree_t *tree, void *data) node = node->childs[(res < 0) ? AVL_LEFT : AVL_RIGHT]; } - LOCK_MONITOR_EXIT(tree->lock); + Mutex_unlock(tree->mutex); /* entry was not found, returning NULL */ diff --git a/src/toolbox/avl.h b/src/toolbox/avl.h index a8dcaba58..c968fa8a9 100644 --- a/src/toolbox/avl.h +++ b/src/toolbox/avl.h @@ -1,9 +1,7 @@ /* src/toolbox/avl.h - AVL tree implementation - Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel, - C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring, - E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, - J. Wenninger, Institut f. Computersprachen - TU Wien + Copyright (C) 1996-2005, 2006, 2007, 2008 + CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO This file is part of CACAO. @@ -32,6 +30,8 @@ #include "vm/types.h" +#include "threads/mutex.hpp" + #include "vm/global.h" @@ -55,12 +55,10 @@ typedef struct avl_node_t avl_node_t; /* avl_tree_t *****************************************************************/ struct avl_tree_t { -#if defined(ENABLE_THREADS) - java_object_t *lock; /* threads lock object */ -#endif - avl_node_t *root; /* pointer to root node */ - avl_comparator *comparator; /* pointer to comparison function */ - s4 entries; /* contains number of entries */ + Mutex* mutex; ///< Mutex to lock the tree. + avl_node_t *root; /* pointer to root node */ + avl_comparator *comparator; /* pointer to comparison function */ + s4 entries; /* contains number of entries */ }; -- 2.25.1