2 extern int classsize[];
4 //NOTE: "pile" ptr points to the head of the linked list of the machine pile data structures
6 /* This function creates a new pile data structure to hold
7 * obj ids of objects modified or read inside a transaction,
8 * no of objects read and no of objects modified
9 * that belong to a single machine */
11 plistnode_t *pCreate(int objects) {
14 //Create main structure
15 if((pile = calloc(1, sizeof(plistnode_t))) == NULL) {
16 printf("Calloc error %s %d\n", __FILE__, __LINE__);
19 if ((pile->oidmod = calloc(objects, sizeof(unsigned int))) == NULL) {
20 printf("Calloc error %s %d\n", __FILE__, __LINE__);
24 if ((pile->oidcreated = calloc(objects, sizeof(unsigned int))) == NULL) {
25 printf("Calloc error %s %d\n", __FILE__, __LINE__);
30 if ((pile->objread = calloc(objects, sizeof(unsigned int) + sizeof(short))) == NULL) {
31 printf("Calloc error %s %d\n", __FILE__, __LINE__);
34 free(pile->oidcreated);
38 pile->nummod = pile->numread = pile->numcreated = pile->sum_bytes = pile->mid = 0;
43 /* This function inserts necessary information into
44 * a machine pile data structure */
45 plistnode_t *pInsert(plistnode_t *pile, objheader_t *headeraddr, unsigned int mid, int num_objs) {
46 plistnode_t *ptr, *tmp;
47 int found = 0, offset = 0;
50 //Add oid into a machine that is already present in the pile linked list structure
52 if (tmp->mid == mid) {
55 if (STATUS(headeraddr) & NEW) {
56 tmp->oidcreated[tmp->numcreated] = OID(headeraddr);
57 tmp->numcreated = tmp->numcreated + 1;
58 GETSIZE(tmpsize, headeraddr);
59 tmp->sum_bytes += sizeof(objheader_t) + tmpsize;
60 }else if (STATUS(headeraddr) & DIRTY) {
61 tmp->oidmod[tmp->nummod] = OID(headeraddr);
62 tmp->nummod = tmp->nummod + 1;
63 GETSIZE(tmpsize, headeraddr);
64 tmp->sum_bytes += sizeof(objheader_t) + tmpsize;
66 offset = (sizeof(unsigned int) + sizeof(short)) * tmp->numread;
67 *((unsigned int *)(((char *)tmp->objread) + offset))=OID(headeraddr);
68 offset += sizeof(unsigned int);
69 *((short *)(((char *)tmp->objread) + offset)) = headeraddr->version;
70 tmp->numread = tmp->numread + 1;
77 //Add oid for any new machine
80 if((ptr = pCreate(num_objs)) == NULL) {
84 if (STATUS(headeraddr) & NEW) {
85 ptr->oidcreated[ptr->numcreated] = OID(headeraddr);
86 ptr->numcreated = ptr->numcreated + 1;
87 GETSIZE(tmpsize, headeraddr);
88 ptr->sum_bytes += sizeof(objheader_t) + tmpsize;
89 } else if (STATUS(headeraddr) & DIRTY) {
90 ptr->oidmod[ptr->nummod] = OID(headeraddr);
91 ptr->nummod = ptr->nummod + 1;
92 GETSIZE(tmpsize, headeraddr);
93 ptr->sum_bytes += sizeof(objheader_t) + tmpsize;
95 *((unsigned int *)ptr->objread)=OID(headeraddr);
96 offset = sizeof(unsigned int);
97 *((short *)(((char *)ptr->objread) + offset)) = headeraddr->version;
98 ptr->numread = ptr->numread + 1;
105 STATUS(headeraddr) &= ~NEW;
106 STATUS(headeraddr) &= ~DIRTY;
111 //Count the number of machine piles
112 int pCount(plistnode_t *pile) {
123 //Make a list of mid's for each machine group
124 int pListMid(plistnode_t *pile, unsigned int *list) {
128 while (tmp != NULL) {
136 //Delete the entire pile
137 void pDelete(plistnode_t *pile) {
138 plistnode_t *next, *tmp;
143 free(tmp->oidcreated);