change
[IRC.git] / Robust / src / Runtime / DSTM / interface / plookup.c
1 #include "plookup.h"
2 extern int classsize[];
3
4 //NOTE: "pile" ptr points to the head of the linked list of the machine pile data structures
5
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 */
10
11 plistnode_t *pCreate(int objects) {
12   plistnode_t *pile;
13
14   //Create main structure
15   if((pile = calloc(1, sizeof(plistnode_t))) == NULL) {
16     printf("Calloc error %s %d\n", __FILE__, __LINE__);
17     return NULL;
18   }
19   if ((pile->oidmod = calloc(objects, sizeof(unsigned int))) == NULL) {
20     printf("Calloc error %s %d\n", __FILE__, __LINE__);
21     free(pile);
22     return NULL;
23   }
24   if ((pile->oidcreated = calloc(objects, sizeof(unsigned int))) == NULL) {
25     printf("Calloc error %s %d\n", __FILE__, __LINE__);
26     free(pile);
27     free(pile->oidmod);
28     return NULL;
29   }
30   if ((pile->objread = calloc(objects, sizeof(unsigned int) + sizeof(short))) == NULL) {
31     printf("Calloc error %s %d\n", __FILE__, __LINE__);
32     free(pile);
33     free(pile->oidmod);
34     free(pile->oidcreated);
35     return NULL;
36   }
37
38   pile->nummod = pile->numread = pile->numcreated = pile->sum_bytes = pile->mid = 0;
39   pile->next = NULL;
40   return pile;
41 }
42
43 //Count the number of machine piles
44 int pCount(plistnode_t *pile) {
45   plistnode_t *tmp;
46   int pcount = 0;
47   tmp = pile;
48   while(tmp != NULL) {
49     pcount++;
50     tmp = tmp->next;
51   }
52   return pcount;
53 }
54
55 //Make a list of mid's for each machine group
56 int pListMid(plistnode_t *pile, unsigned int *list) {
57   int i = 0;
58   plistnode_t *tmp;
59   tmp = pile;
60   while (tmp != NULL) {
61     list[i] = tmp->mid;
62     i++;
63     tmp = tmp->next;
64   }
65   return 0;
66 }
67
68 //Delete the entire pile
69 void pDelete(plistnode_t *pile) {
70   plistnode_t *next, *tmp;
71   tmp = pile;
72   while(tmp != NULL) {
73     next = tmp->next;
74     free(tmp->oidmod);
75     free(tmp->oidcreated);
76     free(tmp->objread);
77     free(tmp);
78     tmp = next;
79   }
80   return;
81 }