//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);
* 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))
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;
tmp->offset=1;
lockedobjs=tmp;
}
+ return header;
}
#endif
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
#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
}
void restartaftergc() {
+ if (needtocollect) {
+ pthread_mutex_lock(&gclock); // Wait for GC
+ pthread_mutex_unlock(&gclock);
+ }
pthread_mutex_lock(&gclistlock);
listcount--;
pthread_mutex_unlock(&gclistlock);
#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