summaryrefslogtreecommitdiff
path: root/misc.c
diff options
context:
space:
mode:
authorEli Barzilay <eli@racket-lang.org>2015-07-09 00:49:31 +0300
committerIvan Maidanski <ivmai@mail.ru>2015-07-09 00:49:31 +0300
commit67f8e2523ed2bac0a89011b01225b43908ae18ec (patch)
treed612fc694231bdad2aea73fdfd4a900cdb697bea /misc.c
parent005d9f57acd6e23e2a5727d272bb7553e150d602 (diff)
downloadbdwgc-67f8e2523ed2bac0a89011b01225b43908ae18ec.tar.gz
Add API function to calculate total memory in use by all GC blocks
(Apply part of commit db2b9f1 from 'racket_gc' branch.) * include/gc.h (GC_get_memory_use): New API function declaration. * misc.c (get_size, GC_get_memory_use): New function.
Diffstat (limited to 'misc.c')
-rw-r--r--misc.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/misc.c b/misc.c
index e67a76f1..55d078c8 100644
--- a/misc.c
+++ b/misc.c
@@ -2014,6 +2014,25 @@ GC_API void * GC_CALL GC_do_blocking(GC_fn_type fn, void * client_data)
}
#endif /* !NO_DEBUGGING */
+static void get_size(struct hblk *h, word lptr)
+{
+ hdr *hhdr = HDR(h);
+ long bytes = WORDS_TO_BYTES(hhdr->hb_sz);
+
+ bytes += HBLKSIZE-1;
+ bytes &= ~(HBLKSIZE-1);
+
+ *(long *)lptr += bytes;
+}
+long GC_get_memory_use()
+{
+ long c = 0;
+ LOCK();
+ GC_apply_to_all_blocks(get_size, (word)&c);
+ UNLOCK();
+ return c;
+}
+
/* Getter functions for the public Read-only variables. */
/* GC_get_gc_no() is unsynchronized and should be typically called */