major changes to prefetching code
[IRC.git] / Robust / src / Runtime / DSTM / interface / objstr.c
1 #include "dstm.h"
2
3 objstr_t *objstrCreate(unsigned int size) {
4   objstr_t *tmp = calloc(1, (sizeof(objstr_t) + size));
5   tmp->size = size;
6   tmp->next = NULL;
7   tmp->top = tmp + 1; //points to end of objstr_t structure!
8   return tmp;
9 }
10
11 //free entire list, starting at store
12 void objstrDelete(objstr_t *store)
13 {
14         objstr_t *tmp;
15         while (store != NULL)
16         {
17                 tmp = store->next;
18                 free(store);
19                 store = tmp;
20         }
21         return;
22 }
23
24 void *objstrAlloc(objstr_t *store, unsigned int size)
25 {
26         void *tmp;
27         while (1)
28         {
29                 if (((unsigned int)store->top - (unsigned int)store - sizeof(objstr_t) + size) <= store->size)
30                 {  //store not full
31                         tmp = store->top;
32                         store->top += size;
33                         return tmp;
34                 }
35                 //store full
36                 if (store->next == NULL)
37                 {  //end of list, all full
38                         if (size > DEFAULT_OBJ_STORE_SIZE) //in case of large objects
39                         {
40                                 store->next = (objstr_t *)calloc(1,(sizeof(objstr_t) + size));
41                                 if (store->next == NULL)
42                                         return NULL;
43                                 store = store->next;
44                                 store->size = size;
45                         }
46                         else
47                         {
48                                 store->next = calloc(1,(sizeof(objstr_t) + DEFAULT_OBJ_STORE_SIZE));
49                                 if (store->next == NULL)
50                                         return NULL;
51                                 store = store->next;
52                                 store->next = NULL;
53                                 store->size = DEFAULT_OBJ_STORE_SIZE;
54                         }
55                         store->top = (void *)((unsigned int)store + sizeof(objstr_t) + size);
56                         return (void *)((unsigned int)store + sizeof(objstr_t));
57                 }
58                 else  //try the next one
59                         store = store->next;
60         }
61 }
62