int numoidrdlocked=0;
int numoidwrlocked=0;
void * rdlocked[200];
+ int rdversion[200];
void * wrlocked[200];
int softabort=0;
int i;
void ** oidrdlocked;
void ** oidwrlocked;
+ int * oidrdversion;
if (c_numelements<200) {
oidrdlocked=rdlocked;
+ oidrdversion=rdversion;
oidwrlocked=wrlocked;
} else {
int size=c_numelements*sizeof(void*);
oidrdlocked=malloc(size);
+ oidrdversion=malloc(size);
oidwrlocked=malloc(size);
}
chashlistnode_t *ptr = c_table;
if(curr->key == NULL)
break;
objheader_t * headeraddr=&((objheader_t *) curr->val)[-1];
-
- unsigned int version = headeraddr->version;
objheader_t *header=(objheader_t *) (((char *)curr->key)-sizeof(objheader_t));
+ unsigned int version = headeraddr->version;
if(STATUS(headeraddr) & DIRTY) {
/* Read from the main heap and compare versions */
oidwrlocked[numoidwrlocked++] = OID(header);
} else {
oidwrlocked[numoidwrlocked++] = OID(header);
- transAbortProcess(oidrdlocked, &numoidrdlocked, oidwrlocked, &numoidwrlocked);
+ transAbortProcess(oidwrlocked, numoidwrlocked);
DEBUGSTM("WR Abort: rd: %u wr: %u tot: %u type: %u ver: %u\n", numoidrdlocked, numoidwrlocked, c_numelements, TYPE(header), header->version);
+ if (c_numelements>=200) {
+ free(oidrdlocked);
+ free(oidrdversion);
+ free(oidwrlocked);
+ }
return TRANS_ABORT;
}
} else { /* cannot aquire lock */
/* versions match */
softabort=1;
} else {
- transAbortProcess(oidrdlocked, &numoidrdlocked, oidwrlocked, &numoidwrlocked);
+ transAbortProcess(oidwrlocked, numoidwrlocked);
DEBUGSTM("WR Abort: rd: %u wr: %u tot: %u type: %u ver: %u\n", numoidrdlocked, numoidwrlocked, c_numelements, TYPE(header), header->version);
+ if (c_numelements>=200) {
+ free(oidrdlocked);
+ free(oidrdversion);
+ free(oidwrlocked);
+ }
return TRANS_ABORT;
}
}
} else {
- /* Read from the main heap and compare versions */
- if(read_trylock(&header->lock)) { //can further acquire read locks
- if(version == header->version) {/* versions match */
- oidrdlocked[numoidrdlocked++] = OID(header);
- } else {
- oidrdlocked[numoidrdlocked++] = OID(header);
- transAbortProcess(oidrdlocked, &numoidrdlocked, oidwrlocked, &numoidwrlocked);
- DEBUGSTM("RD Abort: rd: %u wr: %u tot: %u type: %u ver: %u\n", numoidrdlocked, numoidwrlocked, c_numelements, TYPE(header), header->version);
- return TRANS_ABORT;
- }
- } else { /* cannot aquire lock */
- if(version == header->version) {
- softabort=1;
- } else {
- transAbortProcess(oidrdlocked, &numoidrdlocked, oidwrlocked, &numoidwrlocked);
- DEBUGSTM("RD Abort: rd: %u wr: %u tot: %u type: %u ver: %u\n", numoidrdlocked, numoidwrlocked, c_numelements, TYPE(header), header->version);
- return TRANS_ABORT;
- }
- }
+ oidrdversion[numoidrdlocked]=version;
+ oidrdlocked[numoidrdlocked++] = header;
}
-
curr = curr->next;
}
} //end of for
+
+ //THIS IS THE SERIALIZATION POINT *****
+
+ for(i=0;i<numoidrdlocked;i++) {
+ /* Read from the main heap and compare versions */
+ objheader_t *header=oidrdlocked[i];
+ unsigned int version=oidrdversion[i];
+ if(header->lock>0) { //not write locked
+ if(version != header->version) {/* versions do not match */
+ oidrdlocked[numoidrdlocked++] = OID(header);
+ transAbortProcess(oidwrlocked, numoidwrlocked);
+ DEBUGSTM("RD Abort: rd: %u wr: %u tot: %u type: %u ver: %u\n", numoidrdlocked, numoidwrlocked, c_numelements, TYPE(header), header->version);
+ if (c_numelements>=200) {
+ free(oidrdlocked);
+ free(oidrdversion);
+ free(oidwrlocked);
+ }
+ return TRANS_ABORT;
+ }
+ } else { /* cannot aquire lock */
+ //do increment as we didn't get lock
+ if(version == header->version) {
+ softabort=1;
+ } else {
+ transAbortProcess(oidwrlocked, numoidwrlocked);
+ DEBUGSTM("RD Abort: rd: %u wr: %u tot: %u type: %u ver: %u\n", numoidrdlocked, numoidwrlocked, c_numelements, TYPE(header), header->version);
+ if (c_numelements>=200) {
+ free(oidrdlocked);
+ free(oidrdversion);
+ free(oidwrlocked);
+ }
+ return TRANS_ABORT;
+ }
+ }
+ }
/* Decide the final response */
if (softabort) {
- transAbortProcess(oidrdlocked, &numoidrdlocked, oidwrlocked, &numoidwrlocked);
+ transAbortProcess(oidwrlocked, numoidwrlocked);
DEBUGSTM("Soft Abort: rd: %u wr: %u tot: %u\n", numoidrdlocked, numoidwrlocked, c_numelements);
+ if (c_numelements>=200) {
+ free(oidrdlocked);
+ free(oidrdversion);
+ free(oidwrlocked);
+ }
return TRANS_SOFT_ABORT;
} else {
- transCommitProcess(oidrdlocked, &numoidrdlocked, oidwrlocked, &numoidwrlocked);
+ transCommitProcess(oidwrlocked, numoidwrlocked);
DEBUGSTM("Commit: rd: %u wr: %u tot: %u\n", numoidrdlocked, numoidwrlocked, c_numelements);
+ if (c_numelements>=200) {
+ free(oidrdlocked);
+ free(oidrdversion);
+ free(oidwrlocked);
+ }
return TRANS_COMMIT;
}
}
int numoidrdlocked=0;
int numoidwrlocked=0;
void * rdlocked[200];
+ int rdversion[200];
void * wrlocked[200];
int softabort=0;
int i;
void ** oidrdlocked;
+ int * oidrdversion;
void ** oidwrlocked;
if (c_numelements<200) {
oidrdlocked=rdlocked;
+ oidrdversion=rdversion;
oidwrlocked=wrlocked;
} else {
int size=c_numelements*sizeof(void*);
oidrdlocked=malloc(size);
+ oidrdversion=malloc(size);
oidwrlocked=malloc(size);
}
chashlistnode_t *curr = c_list;
while(curr != NULL) {
//if the first bin in hash table is empty
objheader_t * headeraddr=&((objheader_t *) curr->val)[-1];
-
- unsigned int version = headeraddr->version;
objheader_t *header=(objheader_t *) (((char *)curr->key)-sizeof(objheader_t));
+ unsigned int version = headeraddr->version;
if(STATUS(headeraddr) & DIRTY) {
/* Read from the main heap and compare versions */
oidwrlocked[numoidwrlocked++] = OID(header);
} else {
oidwrlocked[numoidwrlocked++] = OID(header);
- transAbortProcess(oidrdlocked, &numoidrdlocked, oidwrlocked, &numoidwrlocked);
+ transAbortProcess(oidwrlocked, numoidwrlocked);
DEBUGSTM("WR Abort: rd: %u wr: %u tot: %u type: %u ver: %u\n", numoidrdlocked, numoidwrlocked, c_numelements, TYPE(header), header->version);
+ if (c_numelements>=200) {
+ free(oidrdlocked);
+ free(oidrdversion);
+ free(oidwrlocked);
+ }
return TRANS_ABORT;
}
} else { /* cannot aquire lock */
/* versions match */
softabort=1;
} else {
- transAbortProcess(oidrdlocked, &numoidrdlocked, oidwrlocked, &numoidwrlocked);
+ transAbortProcess(oidwrlocked, numoidwrlocked);
DEBUGSTM("WR Abort: rd: %u wr: %u tot: %u type: %u ver: %u\n", numoidrdlocked, numoidwrlocked, c_numelements, TYPE(header), header->version);
+ if (c_numelements>=200) {
+ free(oidrdlocked);
+ free(oidrdversion);
+ free(oidwrlocked);
+ }
return TRANS_ABORT;
}
}
} else {
/* Read from the main heap and compare versions */
- if(read_trylock(&header->lock)) { //can further aquire read locks
- if(version == header->version) {/* versions match */
- oidrdlocked[numoidrdlocked++] = OID(header);
- } else {
- oidrdlocked[numoidrdlocked++] = OID(header);
- transAbortProcess(oidrdlocked, &numoidrdlocked, oidwrlocked, &numoidwrlocked);
- DEBUGSTM("RD Abort: rd: %u wr: %u tot: %u type: %u ver: %u\n", numoidrdlocked, numoidwrlocked, c_numelements, TYPE(header), header->version);
- return TRANS_ABORT;
+ oidrdversion[numoidrdlocked]=version;
+ oidrdlocked[numoidrdlocked++] = header;
+ }
+ curr = curr->lnext;
+ }
+ //THIS IS THE SERIALIZATION POINT *****
+ for(i=0;i<numoidrdlocked;i++) {
+ objheader_t * header = oidrdlocked[i];
+ unsigned int version=oidrdversion[i];
+ if(header->lock>=0) {
+ if(version != header->version) {
+ transAbortProcess(oidwrlocked, numoidwrlocked);
+ DEBUGSTM("RD Abort: rd: %u wr: %u tot: %u type: %u ver: %u\n", numoidrdlocked, numoidwrlocked, c_numelements, TYPE(header), header->version);
+ if (c_numelements>=200) {
+ free(oidrdlocked);
+ free(oidrdversion);
+ free(oidwrlocked);
}
- } else { /* cannot aquire lock */
- if(version == header->version) {
- softabort=1;
- } else {
- transAbortProcess(oidrdlocked, &numoidrdlocked, oidwrlocked, &numoidwrlocked);
- DEBUGSTM("RD Abort: rd: %u wr: %u tot: %u type: %u ver: %u\n", numoidrdlocked, numoidwrlocked, c_numelements, TYPE(header), header->version);
- return TRANS_ABORT;
+ return TRANS_ABORT;
+ }
+ } else { /* cannot aquire lock */
+ if(version == header->version) {
+ softabort=1;
+ } else {
+ transAbortProcess(oidwrlocked, numoidwrlocked);
+ DEBUGSTM("RD Abort: rd: %u wr: %u tot: %u type: %u ver: %u\n", numoidrdlocked, numoidwrlocked, c_numelements, TYPE(header), header->version);
+ if (c_numelements>=200) {
+ free(oidrdlocked);
+ free(oidrdversion);
+ free(oidwrlocked);
}
+ return TRANS_ABORT;
}
}
-
- curr = curr->lnext;
}
/* Decide the final response */
if (softabort) {
- transAbortProcess(oidrdlocked, &numoidrdlocked, oidwrlocked, &numoidwrlocked);
+ transAbortProcess(oidwrlocked, numoidwrlocked);
DEBUGSTM("Soft Abort: rd: %u wr: %u tot: %u\n", numoidrdlocked, numoidwrlocked, c_numelements);
+ if (c_numelements>=200) {
+ free(oidrdlocked);
+ free(oidrdversion);
+ free(oidwrlocked);
+ }
return TRANS_SOFT_ABORT;
} else {
- transCommitProcess(oidrdlocked, &numoidrdlocked, oidwrlocked, &numoidwrlocked);
+ transCommitProcess(oidwrlocked, numoidwrlocked);
DEBUGSTM("Commit: rd: %u wr: %u tot: %u\n", numoidrdlocked, numoidwrlocked, c_numelements);
+ if (c_numelements>=200) {
+ free(oidrdlocked);
+ free(oidrdversion);
+ free(oidwrlocked);
+ }
return TRANS_COMMIT;
}
}
*
* =================================
*/
-int transAbortProcess(void **oidrdlocked, int *numoidrdlocked, void **oidwrlocked, int *numoidwrlocked) {
+int transAbortProcess(void **oidwrlocked, int numoidwrlocked) {
int i;
objheader_t *header;
/* Release read locks */
- for(i=0; i< *numoidrdlocked; i++) {
- /* Read from the main heap */
- header = (objheader_t *)(((char *)(oidrdlocked[i])) - sizeof(objheader_t));
- read_unlock(&header->lock);
- }
/* Release write locks */
- for(i=0; i< *numoidwrlocked; i++) {
+ for(i=0; i< numoidwrlocked; i++) {
/* Read from the main heap */
header = (objheader_t *)(((char *)(oidwrlocked[i])) - sizeof(objheader_t));
write_unlock(&header->lock);
}
- if (c_numelements>=200) {
- free(oidrdlocked);
- free(oidwrlocked);
- }
}
/* ==================================
*
* =================================
*/
-int transCommitProcess(void ** oidrdlocked, int *numoidrdlocked,
- void ** oidwrlocked, int *numoidwrlocked) {
+int transCommitProcess(void ** oidwrlocked, int numoidwrlocked) {
objheader_t *header;
void *ptrcreate;
int i;
}
/* Copy from transaction cache -> main object store */
- for (i = 0; i < *numoidwrlocked; i++) {
+ for (i = 0; i < numoidwrlocked; i++) {
/* Read from the main heap */
header = (objheader_t *)(((char *)(oidwrlocked[i])) - sizeof(objheader_t));
int tmpsize;
header->version += 1;
}
- /* Release read locks */
- for(i=0; i< *numoidrdlocked; i++) {
- /* Read from the main heap */
- header = (objheader_t *)(((char *)(oidrdlocked[i])) - sizeof(objheader_t));
- read_unlock(&header->lock);
- }
-
/* Release write locks */
- for(i=0; i< *numoidwrlocked; i++) {
+ for(i=0; i< numoidwrlocked; i++) {
header = (objheader_t *)(((char *)(oidwrlocked[i])) - sizeof(objheader_t));
write_unlock(&header->lock);
}
- if (c_numelements>=200) {
- free(oidrdlocked);
- free(oidwrlocked);
- }
return 0;
}