From 3632bbbe7b49817e5bcbe8fd6f05f2a929206670 Mon Sep 17 00:00:00 2001 From: bdemsky Date: Thu, 16 Apr 2009 05:58:59 +0000 Subject: [PATCH] finally fix bug...after a full day on this one. --- Robust/src/Runtime/STM/stm.c | 40 ++++++++++++++++++++++-------------- Robust/src/Runtime/STM/tm.h | 2 +- Robust/src/Runtime/garbage.c | 17 +++++++-------- Robust/src/Runtime/garbage.h | 3 ++- 4 files changed, 37 insertions(+), 25 deletions(-) diff --git a/Robust/src/Runtime/STM/stm.c b/Robust/src/Runtime/STM/stm.c index 84a0ab64..89815bb6 100644 --- a/Robust/src/Runtime/STM/stm.c +++ b/Robust/src/Runtime/STM/stm.c @@ -109,13 +109,14 @@ objheader_t *transCreateObj(void * ptr, unsigned int size) { /* This functions inserts randowm wait delays in the order of msec * Mostly used when transaction commits retry*/ -void randomdelay() { +void randomdelay(int softaborted) { struct timespec req; - time_t t; + struct timeval t; + + gettimeofday(&t,NULL); - t = time(NULL); req.tv_sec = 0; - req.tv_nsec = (long)(t%4); //1-11 microsec + req.tv_nsec = (long)((t.tv_usec)%(1<4) { + //retry if to many soft aborts + freenewobjs(); + objstrReset(); + t_chashreset(); + return TRANS_ABORT; + } + randomdelay(softaborted); } else { printf("Error: in %s() Unknown outcome", __func__); exit(-1); @@ -314,16 +322,17 @@ int traverseCache() { return TRANS_ABORT; } } else { /* cannot aquire lock */ - if(version == header->version) /* versions match */ + if(version == header->version) { + /* versions match */ softabort=1; - else { + } else { transAbortProcess(oidrdlocked, &numoidrdlocked, oidwrlocked, &numoidwrlocked); return TRANS_ABORT; } } } else { /* Read from the main heap and compare versions */ - if(read_trylock(&header->lock)) { //can further aquire read locks + if(read_trylock(&header->lock)) { //can further acquire read locks if(version == header->version) {/* versions match */ oidrdlocked[numoidrdlocked++] = OID(header); } else { @@ -332,9 +341,9 @@ int traverseCache() { return TRANS_ABORT; } } else { /* cannot aquire lock */ - if(version == header->version) + if(version == header->version) { softabort=1; - else { + } else { transAbortProcess(oidrdlocked, &numoidrdlocked, oidwrlocked, &numoidwrlocked); return TRANS_ABORT; } @@ -400,9 +409,10 @@ int alttraverseCache() { return TRANS_ABORT; } } else { /* cannot aquire lock */ - if(version == header->version) /* versions match */ + if(version == header->version) { + /* versions match */ softabort=1; - else { + } else { transAbortProcess(oidrdlocked, &numoidrdlocked, oidwrlocked, &numoidwrlocked); return TRANS_ABORT; } @@ -418,9 +428,9 @@ int alttraverseCache() { return TRANS_ABORT; } } else { /* cannot aquire lock */ - if(version == header->version) + if(version == header->version) { softabort=1; - else { + } else { transAbortProcess(oidrdlocked, &numoidrdlocked, oidwrlocked, &numoidwrlocked); return TRANS_ABORT; } diff --git a/Robust/src/Runtime/STM/tm.h b/Robust/src/Runtime/STM/tm.h index 5f701588..1da40df5 100644 --- a/Robust/src/Runtime/STM/tm.h +++ b/Robust/src/Runtime/STM/tm.h @@ -148,6 +148,6 @@ int traverseCache(); int alttraverseCache(); int transAbortProcess(void **, int *, void **, int *); int transCommmitProcess(void **, int *, void **, int *); -void randomdelay(); +void randomdelay(int); #endif diff --git a/Robust/src/Runtime/garbage.c b/Robust/src/Runtime/garbage.c index 5289c4ed..182342d1 100644 --- a/Robust/src/Runtime/garbage.c +++ b/Robust/src/Runtime/garbage.c @@ -147,7 +147,7 @@ void fixobjlist(struct objlist * ptr) { } } -void fixtable(chashlistnode_t ** tc_table, chashlistnode_t **tc_list, unsigned int tc_size) { +void fixtable(chashlistnode_t ** tc_table, chashlistnode_t **tc_list, cliststruct_t **cstr, unsigned int tc_size) { unsigned int mask=(tc_size<<4)-1; chashlistnode_t *node=calloc(tc_size, sizeof(chashlistnode_t)); chashlistnode_t *ptr=*tc_table; @@ -212,14 +212,14 @@ void fixtable(chashlistnode_t ** tc_table, chashlistnode_t **tc_list, unsigned i newlist=tmp; } else if (isfirst) { chashlistnode_t *newnode; - if (c_structs->numarray[c_structs->num]; - c_structs->num++; + if ((*cstr)->numarray[(*cstr)->num]; + (*cstr)->num++; } else { //get new list cliststruct_t *tcl=calloc(1,sizeof(cliststruct_t)); - tcl->next=c_structs; - c_structs=tcl; + tcl->next=*cstr; + *cstr=tcl; newnode=&tcl->array[0]; tcl->num=1; } @@ -300,7 +300,7 @@ void collect(struct garbagelist * stackptr) { #ifdef STM if (c_table!=NULL) { - fixtable(&c_table, &c_list, c_size); + fixtable(&c_table, &c_list, &c_structs, c_size); fixobjlist(newobjs); } memorybase=NULL; @@ -330,7 +330,7 @@ void collect(struct garbagelist * stackptr) { #endif #ifdef STM if ((*listptr->tc_table)!=NULL) { - fixtable(listptr->tc_table, listptr->tc_list, listptr->tc_size); + fixtable(listptr->tc_table, listptr->tc_list, listptr->tc_structs, listptr->tc_size); fixobjlist(listptr->objlist); } *(listptr->base)=NULL; @@ -602,6 +602,7 @@ struct listitem * stopforgc(struct garbagelist * ptr) { litem->tc_size=c_size; litem->tc_table=&c_table; litem->tc_list=&c_list; + litem->tc_structs=&c_structs; litem->objlist=newobjs; litem->base=&memorybase; #endif diff --git a/Robust/src/Runtime/garbage.h b/Robust/src/Runtime/garbage.h index 597734ed..d402ab92 100644 --- a/Robust/src/Runtime/garbage.h +++ b/Robust/src/Runtime/garbage.h @@ -18,6 +18,7 @@ struct listitem { #endif #ifdef STM unsigned int tc_size; + cliststruct_t **tc_structs; chashlistnode_t **tc_table; chashlistnode_t **tc_list; struct objlist * objlist; @@ -41,5 +42,5 @@ int gc_createcopy(void * orig, void **); void * mygcmalloc(struct garbagelist * ptr, int size); #endif #ifdef STM -void fixtable(chashlistnode_t **, chashlistnode_t **, unsigned int); +void fixtable(chashlistnode_t **, chashlistnode_t **, cliststruct_t **, unsigned int); #endif -- 2.34.1