summaryrefslogtreecommitdiffstats
path: root/byterun/freelist.c
diff options
context:
space:
mode:
Diffstat (limited to 'byterun/freelist.c')
-rw-r--r--byterun/freelist.c78
1 files changed, 39 insertions, 39 deletions
diff --git a/byterun/freelist.c b/byterun/freelist.c
index d359db591..00b095e96 100644
--- a/byterun/freelist.c
+++ b/byterun/freelist.c
@@ -23,7 +23,7 @@
/* The free-list is kept sorted by increasing addresses.
This makes the merging of adjacent free blocks possible.
- (See [fl_merge_block].)
+ (See [caml_fl_merge_block].)
*/
typedef struct {
@@ -42,16 +42,16 @@ static struct {
#define Fl_head ((char *) (&(sentinel.first_bp)))
static char *fl_prev = Fl_head; /* Current allocation pointer. */
static char *fl_last = NULL; /* Last block in the list. Only valid
- just after fl_allocate returned NULL. */
-char *fl_merge = Fl_head; /* Current insertion pointer. Managed
+ just after [caml_fl_allocate] returns NULL. */
+char *caml_fl_merge = Fl_head; /* Current insertion pointer. Managed
jointly with [sweep_slice]. */
-asize_t fl_cur_size = 0; /* Number of words in the free list,
+asize_t caml_fl_cur_size = 0; /* Number of words in the free list,
including headers but not fragments. */
#define Next(b) (((block *) (b))->next_bp)
#ifdef DEBUG
-void fl_check (void)
+static void fl_check (void)
{
char *cur, *prev;
int prev_found = 0, merge_found = 0;
@@ -63,17 +63,17 @@ void fl_check (void)
size_found += Whsize_bp (cur);
Assert (Is_in_heap (cur));
if (cur == fl_prev) prev_found = 1;
- if (cur == fl_merge) merge_found = 1;
+ if (cur == caml_fl_merge) merge_found = 1;
prev = cur;
cur = Next (prev);
}
Assert (prev_found || fl_prev == Fl_head);
- Assert (merge_found || fl_merge == Fl_head);
- Assert (size_found == fl_cur_size);
+ Assert (merge_found || caml_fl_merge == Fl_head);
+ Assert (size_found == caml_fl_cur_size);
}
#endif
-/* [allocate_block] is called by [fl_allocate]. Given a suitable free
+/* [allocate_block] is called by [caml_fl_allocate]. Given a suitable free
block and the desired size, it allocates a new block from the free
block. There are three cases:
0. The free block has the desired size. Detach the block from the
@@ -92,30 +92,30 @@ static char *allocate_block (mlsize_t wh_sz, char *prev, char *cur)
header_t h = Hd_bp (cur);
Assert (Whsize_hd (h) >= wh_sz);
if (Wosize_hd (h) < wh_sz + 1){ /* Cases 0 and 1. */
- fl_cur_size -= Whsize_hd (h);
+ caml_fl_cur_size -= Whsize_hd (h);
Next (prev) = Next (cur);
Assert (Is_in_heap (Next (prev)) || Next (prev) == NULL);
- if (fl_merge == cur) fl_merge = prev;
+ if (caml_fl_merge == cur) caml_fl_merge = prev;
#ifdef DEBUG
fl_last = NULL;
#endif
/* In case 1, the following creates the empty block correctly.
In case 0, it gives an invalid header to the block. The function
- calling [fl_allocate] will overwrite it. */
+ calling [caml_fl_allocate] will overwrite it. */
Hd_op (cur) = Make_header (0, 0, Caml_white);
}else{ /* Case 2. */
- fl_cur_size -= wh_sz;
+ caml_fl_cur_size -= wh_sz;
Hd_op (cur) = Make_header (Wosize_hd (h) - wh_sz, 0, Caml_blue);
}
fl_prev = prev;
return cur + Bosize_hd (h) - Bsize_wsize (wh_sz);
}
-/* [fl_allocate] does not set the header of the newly allocated block.
+/* [caml_fl_allocate] does not set the header of the newly allocated block.
The calling function must do it before any GC function gets called.
- [fl_allocate] returns a head pointer.
+ [caml_fl_allocate] returns a head pointer.
*/
-char *fl_allocate (mlsize_t wo_sz)
+char *caml_fl_allocate (mlsize_t wo_sz)
{
char *cur, *prev;
Assert (sizeof (char *) == sizeof (value));
@@ -148,33 +148,33 @@ char *fl_allocate (mlsize_t wo_sz)
static char *last_fragment;
-void fl_init_merge (void)
+void caml_fl_init_merge (void)
{
last_fragment = NULL;
- fl_merge = Fl_head;
+ caml_fl_merge = Fl_head;
#ifdef DEBUG
fl_check ();
#endif
}
/* This is called by caml_compact_heap. */
-void fl_reset (void)
+void caml_fl_reset (void)
{
Next (Fl_head) = 0;
fl_prev = Fl_head;
- fl_cur_size = 0;
- fl_init_merge ();
+ caml_fl_cur_size = 0;
+ caml_fl_init_merge ();
}
-/* [fl_merge_block] returns the head pointer of the next block after [bp],
+/* [caml_fl_merge_block] returns the head pointer of the next block after [bp],
because merging blocks may change the size of [bp]. */
-char *fl_merge_block (char *bp)
+char *caml_fl_merge_block (char *bp)
{
char *prev, *cur, *adj;
header_t hd = Hd_bp (bp);
mlsize_t prev_wosz;
- fl_cur_size += Whsize_hd (hd);
+ caml_fl_cur_size += Whsize_hd (hd);
#ifdef DEBUG
{
@@ -184,7 +184,7 @@ char *fl_merge_block (char *bp)
}
}
#endif
- prev = fl_merge;
+ prev = caml_fl_merge;
cur = Next (prev);
/* The sweep code makes sure that this is the right place to insert
this block: */
@@ -198,7 +198,7 @@ char *fl_merge_block (char *bp)
hd = Make_header (bp_whsz, 0, Caml_white);
bp = last_fragment;
Hd_bp (bp) = hd;
- fl_cur_size += Whsize_wosize (0);
+ caml_fl_cur_size += Whsize_wosize (0);
}
}
@@ -232,29 +232,29 @@ char *fl_merge_block (char *bp)
#ifdef DEBUG
Hd_bp (bp) = Debug_free_major;
#endif
- Assert (fl_merge == prev);
+ Assert (caml_fl_merge == prev);
}else if (Wosize_hd (hd) != 0){
Hd_bp (bp) = Bluehd_hd (hd);
Next (bp) = cur;
Next (prev) = bp;
- fl_merge = bp;
+ caml_fl_merge = bp;
}else{
/* This is a fragment. Leave it in white but remember it for eventual
merging with the next block. */
last_fragment = bp;
- fl_cur_size -= Whsize_wosize (0);
+ caml_fl_cur_size -= Whsize_wosize (0);
}
return adj;
}
/* This is a heap extension. We have to insert it in the right place
in the free-list.
- [fl_add_block] can only be called just after a call to [fl_allocate]
- that returned NULL.
+ [caml_fl_add_block] can only be called right after a call to
+ [caml_fl_allocate] that returned NULL.
Most of the heap extensions are expected to be at the end of the
free list. (This depends on the implementation of [malloc].)
*/
-void fl_add_block (char *bp)
+void caml_fl_add_block (char *bp)
{
Assert (fl_last != NULL);
Assert (Next (fl_last) == NULL);
@@ -267,7 +267,7 @@ void fl_add_block (char *bp)
}
#endif
- fl_cur_size += Whsize_bp (bp);
+ caml_fl_cur_size += Whsize_bp (bp);
if (bp > fl_last){
Next (fl_last) = bp;
@@ -284,10 +284,10 @@ void fl_add_block (char *bp)
Assert (cur > bp || cur == NULL);
Next (bp) = cur;
Next (prev) = bp;
- /* When inserting a block between fl_merge and caml_gc_sweep_hp, we must
- advance fl_merge to the new block, so that fl_merge is always the
- last free-list block before caml_gc_sweep_hp. */
- if (prev == fl_merge && bp <= caml_gc_sweep_hp) fl_merge = bp;
+ /* When inserting a block between [caml_fl_merge] and [caml_gc_sweep_hp],
+ we must advance [caml_fl_merge] to the new block, so that [caml_fl_merge]
+ is always the last free-list block before [caml_gc_sweep_hp]. */
+ if (prev == caml_fl_merge && bp <= caml_gc_sweep_hp) caml_fl_merge = bp;
}
}
@@ -298,7 +298,7 @@ void fl_add_block (char *bp)
size: size of the block (in words)
do_merge: 1 -> do merge; 0 -> do not merge
*/
-void make_free_blocks (value *p, mlsize_t size, int do_merge)
+void caml_make_free_blocks (value *p, mlsize_t size, int do_merge)
{
mlsize_t sz;
@@ -309,7 +309,7 @@ void make_free_blocks (value *p, mlsize_t size, int do_merge)
sz = size;
}
*(header_t *)p = Make_header (Wosize_whsize (sz), 0, Caml_white);
- if (do_merge) fl_merge_block (Bp_hp (p));
+ if (do_merge) caml_fl_merge_block (Bp_hp (p));
size -= sz;
p += sz;
}