1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-17 01:00:20 +02:00

* 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.
This commit is contained in:
Marius Vollmer 2004-08-19 16:48:38 +00:00
parent fddf60002a
commit eb01cb6494
5 changed files with 45 additions and 18 deletions

View file

@ -177,38 +177,52 @@ 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_mallocated += size;
mallocated = scm_mallocated;
if (scm_mallocated > scm_mtrigger)
triggered = 1;
}
scm_i_plugin_mutex_unlock (&scm_i_gc_admin_mutex);
if (overflow)
{
scm_memory_error ("Overflow of scm_mallocated: too much memory in use.");
}
scm_mallocated += size;
/*
A program that uses a lot of malloced collectable memory (vectors,
strings), will use a lot of memory off the cell-heap; it needs to
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");