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 chunk_size
; //size of a chunk (including its forfeited page)
44 int max_dats
; //number of dats per chunk for this stack
45 } ocs
, vcs
, ccs
, rcs
, lcs
, pcs
; //odat, vdat, and cdat, ref, link, post stacks
47 //type safety handled by macro expansion (do not call these directly from code, make dependent macros for access to these)
48 #define CHUNKS_LEN(STACK) ((STACK).csp - (STACK).chunks)
49 #define CURRENT_CHUNK(STACK) ((STACK).chunks[CHUNKS_LEN(STACK) - 1])
50 #define CURRENT_DSP(STACK,TYPE) ((TYPE*) ((STACK).dsp[CHUNKS_LEN(STACK) - 1]))
51 #define DATA_FULL(STACK,TYPE) ((void*) CURRENT_DSP(STACK,TYPE) >= \
52 (CURRENT_CHUNK(STACK) + (STACK).chunk_size))
53 #define CSP_PUSH(STACK) (*(++(STACK).csp) = malloc((STACK).chunk_size))
54 #define CURRENT_DATP(STACK,TYPE) (((TYPE**)(STACK).dsp)[CHUNKS_LEN(STACK) - 1])
55 #define PREVIOUS_DATP(STACK,TYPE) (((TYPE**)(STACK).dsp)[CHUNKS_LEN(STACK) - 2])
56 #define ALLOC_DAT(STACK,TYPE) (++CURRENT_DATP(STACK,TYPE))
57 #define INIT_STACK(STACK,TYPE) \
59 (STACK).chunk_size = PAGES_PER_CHUNK; \
60 (STACK).max_dats = (STACK).chunk_size / sizeof (TYPE); \
63 //Stack-specific macros (called directly from code (safety enforcement)
64 #define CURRENT_ODAT() (CURRENT_DATP(ocs,struct odat))
65 #define ODAT_FULL() (DATA_FULL(ocs,struct odat))
66 #define ODAT_ALLOC() (ALLOC_DAT(ocs,struct odat))
67 #define CURRENT_VDAT() (CURRENT_DATP(vcs,struct vdat))
68 #define VDAT_FULL() (DATA_FULL(vcs,struct vdat))
69 #define VDAT_ALLOC() (ALLOC_DAT(vcs,struct vdat))
70 #define CURRENT_CDAT() (CURRENT_DATP(ccs,struct cdat))
71 #define CDAT_FULL() (DATA_FULL(ccs, struct cdat))
72 #define CDAT_ALLOC() (ALLOC_DAT(ccs, struct cdat))
73 #define CURRENT_LINK() (CURRENT_DATP(lcs,struct link))
74 #define LDAT_FULL() (DATA_FULL(lcs, struct link))
75 #define LDAT_ALLOC() (ALLOC_DAT(lcs, struct link))
76 #define CURRENT_POST() (CURRENT_DATP(pcs,struct ref))
77 #define POST_FULL() (DATA_FULL(pcs,struct ref))
78 #define POST_ALLOC() (ALLOC_DAT(pcs,struct ref))
79 #define CURRENT_REF() (CURRENT_DATP(rcs,struct ref))
80 #define PREVIOUS_REF() (PREVIOUS_DATP(rcs, struct ref))
81 #define REF_FULL() (DATA_FULL(rcs,struct ref))
82 #define REF_ALLOC() (ALLOC_DAT(rcs,struct ref))
84 #define CURRENT_SET() (CURRENT_CDAT()->set_list[CURRENT_CDAT()->num_sets])
85 #define CURRENT_MODEL() (CURRENT_VDAT()->model_list[CURRENT_VDAT()->num_models])
88 #define CURR_QUAD (CURR_ODAT->quad_file)
92 int pages_per_chunk
= 10;
95 int curr_max_cdats
= PTRS_IN_PAGE
;
97 struct cdat
* cdat_buf
[PTRS_IN_PAGE
];
98 struct cdat
* cdat_stack
[PTRS_IN_PAGE
];
99 struct cdat
** cdat_stackp
;
106 uint64_t ss_ref_id
= 0x00FFFFFF; /* system space for ref_ids */
109 int curr_max_posts
= PTRS_IN_PAGE
;
110 struct ref
* post_buf
[PTRS_IN_PAGE
];
114 int curr_max_links
= PTRS_IN_PAGE
;
115 struct link
* link_buf
[PTRS_IN_PAGE
];
118 /* The initalization function of the IR. */
123 /* Init root cdat and stack */
124 char root
[4] = "root";
126 if( (cdat_buf
[num_cdats
] = (struct cdat
*) malloc(sizeof(struct cdat
))) == NULL
)
128 perror("malloc root class failed\n");
131 cdat_buf
[num_cdats
]->idx
= num_cdats
;
132 memmove(cdat_buf
[num_cdats
]->name
, root
, 4);
134 cdat_stackp
= cdat_stack
;
135 *cdat_stackp
++ = cdat_buf
[num_cdats
++];
137 pagesize
= sysconf(_SC_PAGESIZE
);
148 for(i
= 0; i
<= num_odats
; i
++)
151 for(i
= 0; i
<= num_cdats
; i
++)
154 for(i
= 0; i
<= num_vdats
; i
++)
157 for(i
= 0; i
<= num_refs
; i
++)
160 for(i
= 0; i
<= num_links
; i
++)
163 for(i
= 0; i
<= num_posts
; i
++)
174 if(curr_max_cdats
<= num_cdats
)
175 { if( (realloc((void*) cdat_buf
, PTRS_IN_PAGE
* 4)) == NULL
)
176 perror("realloc cdat_buf failed");
177 curr_max_cdats
+= PTRS_IN_PAGE
;
178 if( (realloc( (void*) cdat_stack
, PTRS_IN_PAGE
* 4)) == NULL
) //increase cdat_stack also
179 perror("realloc cdat_stack failed");
181 if( (CURR_CDAT
= (struct cdat
*) malloc(sizeof (struct cdat
)) ) == NULL
)
182 perror("malloc cdat failed");
188 //these should probably be inline
196 return CURRENT_ODAT();
217 return CURRENT_LINK();
229 if(num_refs
% 16 == 0)
230 { CURRENT_POST() = CURRENT_REF();
234 return CURRENT_REF();
257 return CURRENT_ODAT();
263 return CURRENT_VDAT();
269 return &CURRENT_SET();
275 return PREVIOUS_REF();
281 return &CURRENT_MODEL();