/* 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<<softaborted))<<1; //1-11 microsec
nanosleep(&req, NULL);
return;
}
if(finalResponse == TRANS_SOFT_ABORT) {
#ifdef TRANSSTATS
nSoftAbort++;
- softaborted=1;
+ softaborted++;
#endif
- randomdelay();
+ if (softaborted>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);
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 {
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;
}
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;
}
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;
}
int alttraverseCache();
int transAbortProcess(void **, int *, void **, int *);
int transCommmitProcess(void **, int *, void **, int *);
-void randomdelay();
+void randomdelay(int);
#endif
}
}
-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;
newlist=tmp;
} else if (isfirst) {
chashlistnode_t *newnode;
- if (c_structs->num<NUMCLIST) {
- newnode=&c_structs->array[c_structs->num];
- c_structs->num++;
+ if ((*cstr)->num<NUMCLIST) {
+ newnode=&(*cstr)->array[(*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;
}
#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;
#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;
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
#endif
#ifdef STM
unsigned int tc_size;
+ cliststruct_t **tc_structs;
chashlistnode_t **tc_table;
chashlistnode_t **tc_list;
struct objlist * objlist;
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