diff options
author | Marius Vollmer <mvo@zagadka.de> | 2004-08-19 16:48:38 +0000 |
---|---|---|
committer | Marius Vollmer <mvo@zagadka.de> | 2004-08-19 16:48:38 +0000 |
commit | eb01cb6494c4ccf1494ef09ccbb352b4702f7753 (patch) | |
tree | bd3892af0ee095707b9bac24f0d0175214b04e8e /libguile/gc-malloc.c | |
parent | fddf60002a11cd962db15a905e86f5721eb04680 (diff) | |
download | guile-eb01cb6494c4ccf1494ef09ccbb352b4702f7753.tar.gz |
* gc.h, gc.c (scm_i_gc_admin_mutex): New, to protect
scm_gc_mallocated, for now.
(scm_init_storage): Initialize it.
* gc-malloc.c (descrease_mtrigger, increase_mtrigger): Use it.
* gc-mark.c (scm_gc_mark_dependencies): Call scm_i_string_mark,
scm_i_stringbuf_mark and scm_i_symbol_mark, as appropriate.
* gc-card.c (scm_i_sweep_card): Call scm_i_string_free,
scm_i_stringbuf_free and scm_i_symbol_free, as appropriate.
Diffstat (limited to 'libguile/gc-malloc.c')
-rw-r--r-- | libguile/gc-malloc.c | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/libguile/gc-malloc.c b/libguile/gc-malloc.c index ef7a4e473..b909e9424 100644 --- a/libguile/gc-malloc.c +++ b/libguile/gc-malloc.c @@ -177,23 +177,37 @@ scm_strdup (const char *str) return scm_strndup (str, strlen (str)); } - static void decrease_mtrigger (size_t size, const char * what) { + scm_i_plugin_mutex_lock (&scm_i_gc_admin_mutex); scm_mallocated -= size; scm_gc_malloc_collected += size; + scm_i_plugin_mutex_unlock (&scm_i_gc_admin_mutex); } static void increase_mtrigger (size_t size, const char *what) { + size_t mallocated = 0; + int overflow = 0, triggered = 0; + + scm_i_plugin_mutex_lock (&scm_i_gc_admin_mutex); if (ULONG_MAX - size < scm_mallocated) + overflow = 1; + else { - scm_memory_error ("Overflow of scm_mallocated: too much memory in use."); + scm_mallocated += size; + mallocated = scm_mallocated; + if (scm_mallocated > scm_mtrigger) + triggered = 1; } + scm_i_plugin_mutex_unlock (&scm_i_gc_admin_mutex); - scm_mallocated += size; + if (overflow) + { + scm_memory_error ("Overflow of scm_mallocated: too much memory in use."); + } /* A program that uses a lot of malloced collectable memory (vectors, @@ -201,14 +215,14 @@ increase_mtrigger (size_t size, const char *what) do GC more often (before cells are exhausted), otherwise swapping and malloc management will tie it down. */ - if (scm_mallocated > scm_mtrigger) + if (triggered) { unsigned long prev_alloced; float yield; scm_rec_mutex_lock (&scm_i_sweep_mutex); - prev_alloced = scm_mallocated; + prev_alloced = mallocated; scm_igc (what); scm_i_sweep_all_segments ("mtrigger"); |