Changes: Christian Thalinger
- $Id: threads.c 3830 2005-12-01 23:07:33Z twisti $
+ $Id: threads.c 4087 2006-01-03 23:46:48Z twisti $
*/
}
-static struct avl_table *criticaltree;
+static avl_tree *criticaltree;
threadobject *mainthreadobj;
#ifndef HAVE___THREAD
pthread_mutex_unlock_rec(&tablelock);
}
-static int criticalcompare(const void *pa, const void *pb, void *param)
+
+static s4 criticalcompare(const void *pa, const void *pb)
{
const threadcritnode *na = pa;
const threadcritnode *nb = pb;
return 0;
}
+
static const threadcritnode *findcritical(u1 *mcodeptr)
{
- struct avl_node *n = criticaltree->avl_root;
- const threadcritnode *m = NULL;
+ avl_node *n;
+ const threadcritnode *m;
+
+ n = criticaltree->root;
+ m = NULL;
+
if (!n)
return NULL;
- for (;;)
- {
- const threadcritnode *d = n->avl_data;
+
+ for (;;) {
+ const threadcritnode *d = n->data;
+
if (mcodeptr == d->mcodebegin)
return d;
+
if (mcodeptr < d->mcodebegin) {
- if (n->avl_link[0])
- n = n->avl_link[0];
+ if (n->childs[0])
+ n = n->childs[0];
else
return m;
+
} else {
- if (n->avl_link[1]) {
- m = n->avl_data;
- n = n->avl_link[1];
+ if (n->childs[1]) {
+ m = n->data;
+ n = n->childs[1];
} else
- return n->avl_data;
+ return n->data;
}
}
}
+
void thread_registercritical(threadcritnode *n)
{
avl_insert(criticaltree, n);
setthreadobject(mainthreadobj);
initPools();
- criticaltree = avl_create(criticalcompare, NULL, NULL);
- thread_addstaticcritical();
- sem_init(&suspend_ack, 0, 0);
-
/* Every newly created object's monitorPtr points here so we save
a check against NULL */
+
dummyLR = NEW(monitorLockRecord);
dummyLR->o = NULL;
dummyLR->ownerThread = NULL;
dummyLR->waiting = false;
+
+ /* we need a working dummyLR before initializing the critical
+ section tree */
+
+ criticaltree = avl_create(&criticalcompare);
+
+ thread_addstaticcritical();
+ sem_init(&suspend_ack, 0, 0);
}
+
static pthread_attr_t threadattr;
static void freeLockRecordPools(lockRecordPool *);
memory. All functions writing values into the data area return the offset
relative the begin of the code area (start of procedure).
- $Id: codegen-common.c 4012 2005-12-30 14:17:30Z twisti $
+ $Id: codegen-common.c 4087 2006-01-03 23:46:48Z twisti $
*/
/* in this tree we store all method addresses *********************************/
#if defined(__I386__) || defined(__X86_64__) || defined(ENABLE_INTRP) || defined(DISABLE_GC)
-static struct avl_table *methodtree = NULL;
-static int methodtree_comparator(const void *pc, const void *element,
- void *param);
+static avl_tree *methodtree = NULL;
+static s4 methodtree_comparator(const void *pc, const void *element);
#endif
methodtree_element *mte;
#endif
- methodtree = avl_create(methodtree_comparator, NULL, NULL);
+ methodtree = avl_create(&methodtree_comparator);
#if !defined(ENABLE_INTRP)
/* insert asm_calljavafunction */
*******************************************************************************/
-static int methodtree_comparator(const void *pc, const void *element, void *param)
+static s4 methodtree_comparator(const void *pc, const void *element)
{
methodtree_element *mte;
methodtree_element *mtepc;
{
methodtree_element *mte;
-#if defined(USE_THREADS)
-#if defined(NATIVE_THREADS)
- tables_lock();
-#endif
-#endif
+ /* allocate new method entry */
mte = NEW(methodtree_element);
+
mte->startpc = startpc;
mte->endpc = endpc;
- if (avl_insert(methodtree, mte)) {
-#if defined(USE_THREADS)
-#if defined(NATIVE_THREADS)
- tables_unlock();
-#endif
-#endif
- assert(0);
- throw_cacao_exception_exit(string_java_lang_InternalError,
- "duplicate entry");
- }
+ /* this function does not return an error, but asserts for
+ duplicate entries */
-#if defined(USE_THREADS)
-#if defined(NATIVE_THREADS)
- tables_unlock();
-#endif
-#endif
+ avl_insert(methodtree, mte);
}
methodtree_element mtepc;
methodtree_element *mte;
-#if defined(USE_THREADS)
-#if defined(NATIVE_THREADS)
- tables_lock();
-#endif
-#endif
+ /* allocation of the search structure on the stack is much faster */
mtepc.startpc = pc;
- mtepc.endpc = pc;
+ mtepc.endpc = pc;
mte = avl_find(methodtree, &mtepc);
if (!mte) {
-#if defined(USE_THREADS)
-#if defined(NATIVE_THREADS)
- tables_unlock();
-#endif
-#endif
printf("Cannot find Java function at %p\n", (void *) (ptrint) pc);
assert(0);
+
throw_cacao_exception_exit(string_java_lang_InternalError,
"Cannot find Java function at %p", pc);
}
-#if defined(USE_THREADS)
-#if defined(NATIVE_THREADS)
- tables_unlock();
-#endif
-#endif
-
return mte->startpc;
}
#endif /* defined(__I386__) || defined(__X86_64__) || defined(ENABLE_INTRP) || defined(DISABLE_GC) */