5b4fb574981ff55b6e140d22cba758eb8c89b52b
35 #define CURR_CDAT (*cdat_stackp)
36 #define CURR_SET set_list[CURR_CDAT->num_sets]
37 #define REF_IDX (num_refs % (refs_per_page * pages_per_chunk))
38 #define PREV_REF (ref_buf[num_ref_chunks] + (REF_IDX * (sizeof (struct ref)) + pagesize - (sizeof (struct ref))))
39 #define CURR_REF (ref_buf[num_ref_chunks] + (REF_IDX * (sizeof (struct ref)) + pagesize))
40 #define ODAT_IDX (num_odats % (odats_per_page * pages_per_chunk))
41 #define CURR_ODAT (odat_buf[num_odat_chunks] + (ODAT_IDX * (sizeof (struct odat)) + pagesize))
42 #define VDAT_IDX (num_vdats % (vdats_per_page * pages_per_chunk))
43 #define CURR_VDAT (vdat_buf[num_vdat_chunks] + (VDAT_IDX * (sizeof (struct vdat)) + pagesize))
44 #define CURR_MODEL (CURR_VDAT.model_list[CURR_VDAT.num_models])
45 #define CURR_LINK (link_buf[num_links])
46 #define CURR_POST (post_buf[num_posts])
47 #define CURR_QUAD (CURR_ODAT->quad_file)
51 int pages_per_chunk
= 10;
54 int curr_max_cdats
= PTRS_IN_PAGE
;
56 struct cdat
* cdat_buf
[PTRS_IN_PAGE
];
57 struct cdat
* cdat_stack
[PTRS_IN_PAGE
];
58 struct cdat
** cdat_stackp
;
61 int num_odat_chunks
= 0;
63 void* odat_buf
[MAX_CHUNKS
];
67 //"type free" chunk stacking
69 { void* chunks
[MAX_CHUNKS
];
70 void* csp
; //chunk stack pointer
71 void* dsp
[MAX_CHUNKS
]; //dat stack pointer (per chunk)
72 } ocs
, vcs
, ccs
; //odat, vdat, and cdat chunk stacks
74 //type safety handled by macro expansion
75 #define CHUNK_LEN(STACK) ((STACK).csp - (STACK).chunks)
76 #define CURRENT_DAT(STACK,TYPE) ((TYPE)(STACK.dsp[CHUNK_LEN(STACK)])
77 #define INCREMENT_DAT(STACK,TYPE) (++CURRENT_DAT(STACK,TYPE))
78 //Stack-specific macros
79 #define CURRENT_ODAT() (CURRENT_DAT(ocs,struct odat*))
80 #define CURRENT_VDAT() (CURRENT_DAT(vcs,struct vdat*))
81 #define CURRENT_CDAT() (CURRENT_DAT(ccs,struct cdat*))
83 #define CURRENT_MODEL() (CURRENT_VDAT()->model_list[CURRENT_VDAT()->num_models])
86 int num_vdat_chunks
= 0;
88 struct vdat
* vdat_buf
[MAX_CHUNKS
];
91 int num_ref_chunks
= 0;
93 void* ref_buf
[MAX_CHUNKS
];
95 uint64_t ss_ref_id
= 0x00FFFFFF; /* system space for ref_ids */
98 int curr_max_posts
= PTRS_IN_PAGE
;
99 struct ref
* post_buf
[PTRS_IN_PAGE
];
103 int curr_max_links
= PTRS_IN_PAGE
;
104 struct link
* link_buf
[PTRS_IN_PAGE
];
107 /* The initalization function of the IR. */
112 /* Init root cdat and stack */
113 char root
[4] = "root";
115 if( (cdat_buf
[num_cdats
] = (struct cdat
*) malloc(sizeof(struct cdat
))) == NULL
)
117 perror("malloc root class failed\n");
120 cdat_buf
[num_cdats
]->idx
= num_cdats
;
121 memmove(cdat_buf
[num_cdats
]->name
, root
, 4);
123 cdat_stackp
= cdat_stack
;
124 *cdat_stackp
++ = cdat_buf
[num_cdats
++];
126 pagesize
= sysconf(_SC_PAGESIZE
);
127 odats_per_page
= (sizeof (struct odat
)/pagesize
);
128 vdats_per_page
= (sizeof (struct vdat
)/pagesize
);
129 refs_per_page
= (sizeof (struct ref
)/pagesize
);
140 for(i
= 0; i
<= num_odats
; i
++)
144 for(i
= 0; i
<= num_cdats
; i
++)
148 for(i
= 0; i
<= num_vdats
; i
++)
152 for(i
= 0; i
<= num_refs
; i
++)
156 for(i
= 0; i
<= num_links
; i
++)
168 if(curr_max_cdats
<= num_cdats
)
169 { if( (realloc((void*) cdat_buf
, PTRS_IN_PAGE
* 4)) == NULL
)
170 perror("realloc cdat_buf failed");
171 curr_max_cdats
+= PTRS_IN_PAGE
;
172 if( (realloc( (void*) cdat_stack
, PTRS_IN_PAGE
* 4)) == NULL
) //increase cdat_stack also
173 perror("realloc cdat_stack failed");
175 if( (CURR_CDAT
= (struct cdat
*) malloc(sizeof (struct cdat
)) ) == NULL
)
176 perror("malloc cdat failed");
187 if(!(num_odats
% (odats_per_page
* pages_per_chunk
))) //chunk is full
190 if( ((odat_buf
[num_odat_chunks
] = malloc(odats_per_page
* pages_per_chunk
)) == NULL
) )
191 perror("malloc odat chunk failed");
203 if(!(num_vdats
% (vdats_per_page
* pages_per_chunk
))) //chunk is full
206 if( ((vdat_buf
[num_vdat_chunks
] = malloc(vdats_per_page
* pages_per_chunk
)) == NULL
) )
207 perror("malloc vdat chunk failed");
218 if(num_links
>= curr_max_links
)
219 { if( (realloc((void*) link_buf
, PTRS_IN_PAGE
* 4)) == NULL
)
220 perror("realloc vdat_buf failed");
221 curr_max_links
+= PTRS_IN_PAGE
;
223 if((CURR_LINK
= (struct link
*) malloc(sizeof (struct link
))) == NULL
)
224 perror("malloc link failed");
235 if(num_refs
% 16 == 0)
236 { CURR_POST
= CURR_REF
;
239 if(!(num_refs
% (refs_per_page
* pages_per_chunk
))) //chunk is full
242 if( ((ref_buf
[num_ref_chunks
] = malloc(refs_per_page
* pages_per_chunk
)) == NULL
) )
243 perror("malloc ref chunk failed");
252 if(num_posts
>= curr_max_posts
)
253 { if( (realloc((void*) ref_buf
, PTRS_IN_PAGE
* 4)) == NULL
)
254 perror("realoc post_buf failed");
255 curr_max_posts
+= PTRS_IN_PAGE
;
257 if ((CURR_POST
= (struct ref
*) malloc (sizeof (struct ref
))) == NULL
)
258 perror("malloc post failed");
285 return &CURR_CDAT
->CURR_SET
;