summaryrefslogtreecommitdiff
path: root/src/alloc.c
diff options
context:
space:
mode:
authorAndrea Corallo <akrl@sdf.org>2020-12-06 18:07:27 +0100
committerAndrea Corallo <akrl@sdf.org>2020-12-06 18:07:27 +0100
commit715a1ca1744f9a5918376bf7662c81302f0b20c0 (patch)
treee6ea1ac67e88ead92df65087d3f41b8e544f5e86 /src/alloc.c
parent27f666e111a34d64de81a214024e1e30928b416e (diff)
parent40e11743ca3803bdc2c6c612f35ab695efb3eb8b (diff)
downloademacs-715a1ca1744f9a5918376bf7662c81302f0b20c0.tar.gz
Merge remote-tracking branch 'savannah/master' into HEAD
Diffstat (limited to 'src/alloc.c')
-rw-r--r--src/alloc.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/alloc.c b/src/alloc.c
index 133b0e6c9e9..22f37b0cedd 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -6230,6 +6230,30 @@ For further details, see Info node `(elisp)Garbage Collection'. */)
return CALLMANY (Flist, total);
}
+DEFUN ("garbage-collect-maybe", Fgarbage_collect_maybe,
+Sgarbage_collect_maybe, 1, 1, "",
+ doc: /* Call `garbage-collect' if enough allocation happened.
+FACTOR determines what "enough" means here:
+If FACTOR is a positive number N, it means to run GC if more than
+1/Nth of the allocations needed to trigger automatic allocation took
+place.
+Therefore, as N gets higher, this is more likely to perform a GC.
+Returns non-nil if GC happened, and nil otherwise. */)
+ (Lisp_Object factor)
+{
+ CHECK_FIXNAT (factor);
+ EMACS_INT fact = XFIXNAT (factor);
+
+ EMACS_INT since_gc = gc_threshold - consing_until_gc;
+ if (fact >= 1 && since_gc > gc_threshold / fact)
+ {
+ garbage_collect ();
+ return Qt;
+ }
+ else
+ return Qnil;
+}
+
/* Mark Lisp objects in glyph matrix MATRIX. Currently the
only interesting objects referenced from glyphs are strings. */
@@ -7584,6 +7608,7 @@ N should be nonnegative. */);
defsubr (&Smake_finalizer);
defsubr (&Spurecopy);
defsubr (&Sgarbage_collect);
+ defsubr (&Sgarbage_collect_maybe);
defsubr (&Smemory_info);
defsubr (&Smemory_use_counts);
#ifdef GNU_LINUX