2 #include "abortreaders.h"
4 chashtable_t * aborttable;
5 pthread_mutex_t aborttablelock;
6 struct readerlist *freelist;
8 void initreaderlist() {
9 pthread_mutex_init(&aborttablelock, NULL);
10 aborttable=chashCreate(CHASH_SIZE, CLOADFACTOR);
14 void addtransaction(unsigned int oid, struct transrecord * trans) {
15 struct readerlist * rl;
17 if (pthread_mutex_trylock(&aborttablelock)!=0)
19 rl=(struct readerlist *)chashSearch(aborttable, oid);
22 rl=calloc(1,sizeof(struct readerlist ));
26 memset(rl,0, sizeof(struct readerlist));
28 chashInsert(rl, oid, rl);
30 while(rl->numreaders==READERSIZE) {
34 rl->next=calloc(1,sizeof(struct readerlist));
39 for(i=0;i<READERSIZE;i++) {
40 if (rl->array[i]==NULL) {
42 pthread_mutex_unlock(&aborttablelock);
46 pthread_mutex_unlock(&aborttablelock);
47 printf("ERROR in addtransaction\n");
50 void removetransaction(unsigned int oidarray[], unsigned int numoids) {
52 pthread_mutex_lock(&aborttablelock);
53 for(i=0;i<numoids;i++) {
54 unsigned int oid=oidarray[i];
55 struct readerlist *rl=chashRemove2(table, oid);
56 struct readerlist *tmp;
59 for(int j=0;count;j++) {
60 struct transrecord *trans=rl->array[j];
62 trans->abort=1;//It's okay to set our own abort flag...it is
63 //too late to abort us
73 pthread_mutex_unlock(&aborttablelock);
76 void removeaborttransaction(unsigned int oidarray[], unsigned int numoids, struct transrecord * trans) {
78 pthread_mutex_lock(&aborttablelock);
79 for(i=0;i<numoids;i++) {
80 unsigned int oid=oidarray[i];
81 struct readerlist * rl=chashSearch(aborttable, oid);
83 struct readerlist *first=rl;
85 for(j=0;j<READERSIZE;j++) {
86 if (rl->array[j]==trans) {
88 if ((--rl->numreaders)==0) {
90 chashRemove2(table, oid);
92 chashInsert(table, oid, rl->next);
109 pthread_mutex_unlock(&aborttablelock);