-/* Copyright (C) 1995,1996,1997,1998,1999,2000,2001, 2002, 2003, 2006, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
+/* Copyright (C) 1995,1996,1997,1998,1999,2000,2001, 2002, 2003, 2006,
+ * 2008, 2009, 2010, 2011, 2012, 2013, 2014 Free Software Foundation, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
#include <stdio.h>
#include <errno.h>
#include <string.h>
+#include <stdlib.h>
#include <math.h>
#ifdef __ia64__
#include "libguile/debug-malloc.h"
#endif
-#ifdef HAVE_MALLOC_H
-#include <malloc.h>
-#endif
-
-#ifdef HAVE_UNISTD_H
#include <unistd.h>
-#endif
/* Set this to != 0 if every cell that is accessed shall be checked:
*/
static void
run_before_gc_c_hook (void)
{
+ if (!SCM_I_CURRENT_THREAD)
+ /* GC while a thread is spinning up; punt. */
+ return;
+
scm_c_hook_run (&scm_before_gc_c_hook, NULL);
}
/* {Scheme Interface to GC}
*/
-static SCM
-tag_table_to_type_alist (void *closure, SCM key, SCM val, SCM acc)
-{
- if (scm_is_integer (key))
- {
- int c_tag = scm_to_int (key);
-
- char const * name = scm_i_tag_name (c_tag);
- if (name != NULL)
- {
- key = scm_from_locale_string (name);
- }
- else
- {
- char s[100];
- sprintf (s, "tag %d", c_tag);
- key = scm_from_locale_string (s);
- }
- }
-
- return scm_cons (scm_cons (key, val), acc);
-}
-
-SCM_DEFINE (scm_gc_live_object_stats, "gc-live-object-stats", 0, 0, 0,
- (),
- "Return an alist of statistics of the current live objects. ")
-#define FUNC_NAME s_scm_gc_live_object_stats
-{
- SCM tab = scm_make_hash_table (scm_from_int (57));
- SCM alist;
-
- alist
- = scm_internal_hash_fold (&tag_table_to_type_alist, NULL, SCM_EOL, tab);
-
- return alist;
-}
-#undef FUNC_NAME
-
extern int scm_gc_malloc_yield_percentage;
SCM_DEFINE (scm_gc_stats, "gc-stats", 0, 0, 0,
(),
GC_get_heap_usage_safe (&heap_size, &free_bytes, &unmapped_bytes,
&bytes_since_gc, &total_bytes);
+#ifdef HAVE_GC_GET_GC_NO
+ /* This function was added in 7.2alpha2 (June 2009). */
+ gc_times = GC_get_gc_no ();
+#else
+ /* This symbol is deprecated as of 7.3. */
gc_times = GC_gc_no;
+#endif
answer =
scm_list_n (scm_cons (sym_gc_time_taken, scm_from_long (gc_time_taken)),
#define FUNC_NAME s_scm_gc
{
scm_i_gc ("call");
+ /* If you're calling scm_gc(), you probably want synchronous
+ finalization. */
+ GC_invoke_finalizers ();
return SCM_UNSPECIFIED;
}
#undef FUNC_NAME
return res;
}
+#ifndef HAVE_GC_SET_FINALIZE_ON_DEMAND
+static void
+GC_set_finalize_on_demand (int foo)
+{
+ GC_finalize_on_demand = foo;
+}
+#endif
+
void
scm_storage_prehistory ()
{
+#ifdef HAVE_GC_SET_ALL_INTERIOR_POINTERS
+ /* This function was added in 7.2alpha2 (June 2009). */
+ GC_set_all_interior_pointers (0);
+#else
+ /* This symbol is deprecated in 7.3. */
GC_all_interior_pointers = 0;
+#endif
+
free_space_divisor = scm_getenv_int ("GC_FREE_SPACE_DIVISOR", 3);
minimum_free_space_divisor = free_space_divisor;
target_free_space_divisor = free_space_divisor;
GC_set_free_space_divisor (free_space_divisor);
+ GC_set_finalize_on_demand (1);
GC_INIT ();