From: bdemsky Date: Wed, 13 May 2009 03:06:41 +0000 (+0000) Subject: changes X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=48e7c8338287dc94e6bf7ed51c5f3b6da003b235;p=IRC.git changes --- diff --git a/Robust/src/Runtime/STM/stm.c b/Robust/src/Runtime/STM/stm.c index a0d73370..a4b57e54 100644 --- a/Robust/src/Runtime/STM/stm.c +++ b/Robust/src/Runtime/STM/stm.c @@ -255,7 +255,7 @@ __attribute__((pure)) void *transRead(void * oid, void *gl) { //DEBUGSTMSTAT("type: %d, header->abortCount: %d, header->accessCount: %d\n", TYPE(header), header->abortCount, header->accessCount); //if(header->abortCount > MAXABORTS && riskratio > NEED_LOCK_THRESHOLD) { if(header->riskyflag) { - needLock(header,gl); + header=needLock(header,gl); } #endif A_memcpy(objcopy, header, size); @@ -817,7 +817,7 @@ void getTotalAbortCount(int start, int stop, void *startptr, void *checkptr, int * params: Object header * Locks an object that causes aborts **/ -void needLock(objheader_t *header, void *gl) { +objheader_t * needLock(objheader_t *header, void *gl) { int lockstatus; threadrec_t *ptr; while((lockstatus = pthread_mutex_trylock(header->objlock)) @@ -838,12 +838,15 @@ void needLock(objheader_t *header, void *gl) { return; } else { #ifdef PRECISE_GC - stopforgc((struct garbagelist *)gl); -#endif + INTPTR ptrarray[]={1, (INTPTR)gl, (INTPTR) header}; + void *lockptr=header->objlock; + stopforgc((struct garbagelist *)ptrarray); //grab lock and wait our turn - pthread_mutex_lock(header->objlock); -#ifdef PRECISE_GC + pthread_mutex_lock(lockptr); restartaftergc(); + header=(objheader_t *) ptrarray[2]; +#else + pthread_mutex_lock(header->objptr); #endif /* we have lock, so we are not blocked anymore */ trec->blocked = 0; @@ -863,5 +866,6 @@ void needLock(objheader_t *header, void *gl) { tmp->offset=1; lockedobjs=tmp; } + return header; } #endif diff --git a/Robust/src/Runtime/STM/tm.h b/Robust/src/Runtime/STM/tm.h index 08caa5d3..9df9b74a 100644 --- a/Robust/src/Runtime/STM/tm.h +++ b/Robust/src/Runtime/STM/tm.h @@ -174,6 +174,6 @@ int transCommmitProcess(void **, int); void randomdelay(int); #ifdef STMSTATS void getTotalAbortCount(int, int, void *, void *, int); -void needLock(objheader_t *, void *); +objheader_t * needLock(objheader_t *, void *); #endif #endif diff --git a/Robust/src/Runtime/garbage.c b/Robust/src/Runtime/garbage.c index f6c43d68..16892171 100644 --- a/Robust/src/Runtime/garbage.c +++ b/Robust/src/Runtime/garbage.c @@ -599,18 +599,14 @@ void * tomalloc(int size) { #if defined(THREADS)||defined(DSTM)||defined(STM) void checkcollect(void * ptr) { stopforgc((struct garbagelist *)ptr); - pthread_mutex_lock(&gclock); // Wait for GC restartaftergc(); - pthread_mutex_unlock(&gclock); } #ifdef DSTM void checkcollect2(void * ptr) { int ptrarray[]={1, (int)ptr, (int) revertlist}; stopforgc((struct garbagelist *)ptrarray); - pthread_mutex_lock(&gclock); // Wait for GC restartaftergc(); - pthread_mutex_unlock(&gclock); revertlist=(struct ___Object___*)ptrarray[2]; } #endif @@ -650,6 +646,10 @@ void stopforgc(struct garbagelist * ptr) { } void restartaftergc() { + if (needtocollect) { + pthread_mutex_lock(&gclock); // Wait for GC + pthread_mutex_unlock(&gclock); + } pthread_mutex_lock(&gclistlock); listcount--; pthread_mutex_unlock(&gclistlock); @@ -678,9 +678,8 @@ void * mygcmalloc(struct garbagelist * stackptr, int size) { #endif void *ptr; #if defined(THREADS)||defined(DSTM)||defined(STM) - if (pthread_mutex_trylock(&gclock)!=0) { + while (pthread_mutex_trylock(&gclock)!=0) { stopforgc(stackptr); - pthread_mutex_lock(&gclock); restartaftergc(); } #endif