Initial version checkin
[IRC.git] / Robust / src / Runtime / DSTM / interface / dstm.c
1 #include "dstm.h"
2
3 obj_store_t *obj_begin; 
4 obj_listnode_t *obj_lnode_begin;
5
6 extern int classsize[];
7
8 /* BEGIN - object store */
9
10 void dstm_init(void) {
11         obj_begin = NULL;
12         obj_lnode_begin = NULL;
13         return;
14 }
15
16 void create_objstr(unsigned int size) {
17         obj_store_t *tmp, *ptr;
18         static int id = 0;
19
20         if ((tmp = (obj_store_t *) malloc(sizeof(obj_store_t))) < 0) {
21                 printf("DSTM: Malloc error %s %d\n", __FILE__, __LINE__);
22                 exit(-1);
23         }
24         if ((tmp->base = (char *) malloc(sizeof(char)*size)) < 0) {
25                 printf("DSTM: Malloc error %s %d\n", __FILE__, __LINE__);
26                 exit(-1);
27         }
28         tmp->size = size;
29         tmp->top = tmp->base;
30         tmp->id = id++;
31         if (obj_begin == NULL) {        // First entry
32                 obj_begin = tmp;
33                 tmp->next = NULL;
34         } else {                        // Insert to the front of the linked list
35                 tmp->next = obj_begin;
36                 obj_begin = tmp;
37         }
38         return;
39 }
40
41 void delete_objstr(int id) {
42         //TODO Implement this along with garbage collector
43         return;
44 }
45
46 obj_store_t *get_objstr_begin(void) {
47         return obj_begin;
48 }
49
50 /* END object store */
51
52 /* BEGIN object header */
53 int get_newID(void) {
54         static int id = 0;
55         
56         return ++id;
57 }
58
59 int insertObject(obj_header_t h) {
60         int left, req;
61
62         left = obj_begin->size - (obj_begin->top - obj_begin->base);
63         req = getObjSize(h) + sizeof(obj_header_t);
64         if (req < left) {
65                 memcpy(obj_begin->top, &h, sizeof(obj_header_t));
66                 obj_begin->top = obj_begin->top + sizeof(obj_header_t) + getObjSize(h);
67         } else {
68                 return -1;
69         }
70         //TODO Update obj_addr_table
71         return 0;
72 }
73
74 int getObjSize(obj_header_t h) {
75         return classsize[h.type];
76 }
77
78 void createObject(unsigned short type) {
79         obj_header_t h;
80
81         h.oid = get_newID();
82         h.type = type;
83         h.version = 0;
84         h.rcount = 1;
85         h.status = CLEAN;
86         insert_object(h);
87 }
88 /* END object header */
89
90 /* BEGIN obj_listnode */
91
92 int IsEmpty(obj_listnode_t *node) {
93         return obj_lnode_begin == NULL;
94 }
95
96 void insert_lnode(obj_listnode_t *node) {
97         if(obj_lnode_begin == NULL) {           // Enter "node" as the first node in linked list
98                 obj_lnode_begin = node;
99                 node->next = NULL;
100         } else {                              // Enter "node" to the beginning of the linked list
101                 node->next = obj_lnode_begin;
102                 obj_lnode_begin = node ;
103
104         }
105                                 
106 }
107
108 int delete_lnode(obj_listnode_t *node, unsigned int oid) {
109         obj_listnode_t pre, curr;
110         if( obj_lnode_begin == NULL){
111                 printf(" No nodes to delete ");
112                 return -1;
113          }else {
114         //Traverse list         
115         pre = curr = obj_lnode_begin;
116         while(node->next != NULL) {
117                 pre = curr;
118                 curr= curr->next;
119                 if(oid == node->oid){
120                 }
121         }
122 }
123
124
125 /* END obj_listnode */