6089f911a6475e5ae12be3bfc17f6f4e384dbb3d
35 #define PAGES_PER_CHUNK 16
37 #define CURR_CDAT (*cdat_stackp)
38 //"type free" chunk stacking
40 { void* chunks
[MAX_CHUNKS
];
41 void* csp
; //chunk stack pointer
42 void* dsp
[MAX_CHUNKS
]; //dat stack pointer (per chunk)
43 int max_dats
; //num dats in a chunk
44 } ocs
, vcs
, ccs
, rcs
, lcs
, pcs
; //odat, vdat, and cdat, ref, link, post stacks
46 //type safety handled by macro expansion
47 #define CURRENT_CHUNK(STACK) ( (void*) (STACK).csp - (void*) (STACK).chunks - 1)
48 #define CHUNKS_LEN(STACK) ( (void*) (STACK).csp - (void*) (STACK).chunks)
49 #define CHUNK_FULL(STACK, TYPE) ( (CURRENT_DAT(STACK,TYPE) - (TYPE) CURRENT_CHUNK(STACK)) \
51 #define CSP_PUSH(STACK) (++(STACK).csp = malloc(pagesize * PAGES_PER_CHUNK))
52 #define CURRENT_DAT(STACK,TYPE) ((TYPE) (STACK).dsp[CHUNKS_LEN(STACK)])
53 #define PREVIOUS_DAT(STACK,TYPE) ((TYPE) (STACK).dsp[CHUNKS_LEN(STACK)]-1)
54 #define INCREMENT_DAT(STACK,TYPE) (++CURRENT_DAT(STACK,TYPE))
55 //Stack-specific macros
56 #define CURRENT_ODAT() (CURRENT_DAT(ocs,struct odat*))
57 #define CURRENT_VDAT() (CURRENT_DAT(vcs,struct vdat*))
58 #define CURRENT_CDAT() (CURRENT_DAT(ccs,struct cdat*))
59 #define CURRENT_LINK() (CURRENT_DAT(lcs,struct link*))
60 #define CURRENT_POST() (CURRENT_DAT(pcs,struct ref*))
61 #define CURRENT_REF() (CURRENT_DAT(rcs,struct ref*))
62 #define PREVIOUS_REF() (PREVIOUS_DAT(rcs, struct ref*))
64 #define CURRENT_SET() (CURRENT_CDAT()->set_list[CURRENT_CDAT()->num_sets])
65 #define CURRENT_MODEL() (CURRENT_VDAT()->model_list[CURRENT_VDAT()->num_models])
68 #define CURR_QUAD (CURR_ODAT->quad_file)
72 int pages_per_chunk
= 10;
75 int curr_max_cdats
= PTRS_IN_PAGE
;
77 struct cdat
* cdat_buf
[PTRS_IN_PAGE
];
78 struct cdat
* cdat_stack
[PTRS_IN_PAGE
];
79 struct cdat
** cdat_stackp
;
86 uint64_t ss_ref_id
= 0x00FFFFFF; /* system space for ref_ids */
89 int curr_max_posts
= PTRS_IN_PAGE
;
90 struct ref
* post_buf
[PTRS_IN_PAGE
];
94 int curr_max_links
= PTRS_IN_PAGE
;
95 struct link
* link_buf
[PTRS_IN_PAGE
];
98 /* The initalization function of the IR. */
103 /* Init root cdat and stack */
104 char root
[4] = "root";
106 if( (cdat_buf
[num_cdats
] = (struct cdat
*) malloc(sizeof(struct cdat
))) == NULL
)
108 perror("malloc root class failed\n");
111 cdat_buf
[num_cdats
]->idx
= num_cdats
;
112 memmove(cdat_buf
[num_cdats
]->name
, root
, 4);
114 cdat_stackp
= cdat_stack
;
115 *cdat_stackp
++ = cdat_buf
[num_cdats
++];
117 pagesize
= sysconf(_SC_PAGESIZE
);
128 for(i
= 0; i
<= num_odats
; i
++)
131 for(i
= 0; i
<= num_cdats
; i
++)
134 for(i
= 0; i
<= num_vdats
; i
++)
137 for(i
= 0; i
<= num_refs
; i
++)
140 for(i
= 0; i
<= num_links
; i
++)
143 for(i
= 0; i
<= num_posts
; i
++)
154 if(curr_max_cdats
<= num_cdats
)
155 { if( (realloc((void*) cdat_buf
, PTRS_IN_PAGE
* 4)) == NULL
)
156 perror("realloc cdat_buf failed");
157 curr_max_cdats
+= PTRS_IN_PAGE
;
158 if( (realloc( (void*) cdat_stack
, PTRS_IN_PAGE
* 4)) == NULL
) //increase cdat_stack also
159 perror("realloc cdat_stack failed");
161 if( (CURR_CDAT
= (struct cdat
*) malloc(sizeof (struct cdat
)) ) == NULL
)
162 perror("malloc cdat failed");
171 if(CHUNK_FULL(ocs
, struct odat
*))
174 INCREMENT_DAT(ocs
, struct odat
*);
176 return CURRENT_ODAT();
185 if(CHUNK_FULL(vcs
, struct vdat
*))
188 INCREMENT_DAT(vcs
, struct vdat
*);
198 if(CHUNK_FULL(lcs
, struct link
*))
201 INCREMENT_DAT(lcs
, struct link
*);
203 return CURRENT_LINK();
211 if(CHUNK_FULL(rcs
, struct link
*))
214 INCREMENT_DAT(rcs
, struct link
*);
216 if(num_refs
% 16 == 0)
217 { CURRENT_POST() = CURRENT_REF();
221 return CURRENT_REF();
229 if(CHUNK_FULL(pcs
, struct ref
*))
232 INCREMENT_DAT(pcs
, struct ref
*);
248 return CURRENT_ODAT();
254 return CURRENT_VDAT();
260 return &CURRENT_SET();
266 return PREVIOUS_REF();
272 return &CURRENT_MODEL();