diff options
author | Ivan Maidanski <ivmai@mail.ru> | 2022-08-05 20:01:56 +0300 |
---|---|---|
committer | Ivan Maidanski <ivmai@mail.ru> | 2022-08-05 20:01:56 +0300 |
commit | 952c70947375c8539028b3958e7a5d9ce4b49707 (patch) | |
tree | 1bc8f0faf7f800674aa44b81cdb688dfe8eba3ef /allchblk.c | |
parent | 12c142f2b0b6675420eafcbcf9b53db0d9617d19 (diff) | |
download | bdwgc-952c70947375c8539028b3958e7a5d9ce4b49707.tar.gz |
New GC_iterate_free_hblks API function
Issue #460 (bdwgc).
* allchblk.c (GC_iterate_free_hblks): Implement (copy part of code
from GC_compute_large_free_bytes).
* allchblk.c [!NO_DEBUGGING || GC_ASSERTIONS] (add_hb_sz): New static
function.
* allchblk.c [!NO_DEBUGGING || GC_ASSERTIONS]
(GC_compute_large_free_bytes): Use GC_iterate_free_hblks(add_hb_sz).
* include/gc/gc_mark.h (GC_iterate_free_hblks): Declare public
function.
Diffstat (limited to 'allchblk.c')
-rw-r--r-- | allchblk.c | 30 |
1 files changed, 20 insertions, 10 deletions
@@ -59,6 +59,20 @@ /* block. Remains externally visible */ /* as used by GNU GCJ currently. */ +GC_API void GC_CALL GC_iterate_free_hblks(GC_walk_hblk_fn fn, + GC_word client_data) +{ + int i; + + for (i = 0; i <= N_HBLK_FLS; ++i) { + struct hblk *h; + + for (h = GC_hblkfreelist[i]; h != NULL; h = HDR(h) -> hb_next) { + (*fn)(h, client_data); + } + } +} + #ifndef GC_GCJ_SUPPORT STATIC #endif @@ -101,21 +115,17 @@ STATIC int GC_hblk_fl_from_blocks(word blocks_needed) # endif /* !USE_MUNMAP */ #if !defined(NO_DEBUGGING) || defined(GC_ASSERTIONS) + static void GC_CALLBACK add_hb_sz(struct hblk *h, GC_word client_data) + { + *(word *)client_data += HDR(h) -> hb_sz; + } + /* Should return the same value as GC_large_free_bytes. */ GC_INNER word GC_compute_large_free_bytes(void) { word total_free = 0; - unsigned i; - for (i = 0; i <= N_HBLK_FLS; ++i) { - struct hblk * h; - hdr * hhdr; - - for (h = GC_hblkfreelist[i]; h != 0; h = hhdr->hb_next) { - hhdr = HDR(h); - total_free += hhdr->hb_sz; - } - } + GC_iterate_free_hblks(add_hb_sz, (word)&total_free); return total_free; } #endif /* !NO_DEBUGGING || GC_ASSERTIONS */ |