diff options
-rw-r--r-- | gc.c | 33 | ||||
-rw-r--r-- | gc.h | 1 | ||||
-rw-r--r-- | txr.1 | 17 |
3 files changed, 51 insertions, 0 deletions
@@ -834,11 +834,44 @@ val gc_finalize(val obj, val fun, val rev_order_p) return obj; } +val gc_call_finalizers(val obj) +{ + struct fin_reg *new_list = 0, *old_list = final_list; + struct fin_reg **tail = &new_list, *f, *next; + val ret = nil; + + if (!final_list) + return ret; + + final_list = 0; + final_tail = &final_list; + + for (f = old_list; f; f = next) { + next = f->next; + + if (f->obj == obj) { + funcall1(f->fun, f->obj); + free(f); + ret = t; + } else { + *tail = f; + tail = &f->next; + } + } + + *tail = 0; + *final_tail = new_list; + final_tail = tail; + return ret; +} + void gc_late_init(void) { reg_fun(intern(lit("gc"), system_package), func_n0(gc_wrap)); reg_fun(intern(lit("gc-set-delta"), system_package), func_n1(gc_set_delta)); reg_fun(intern(lit("finalize"), user_package), func_n3o(gc_finalize, 2)); + reg_fun(intern(lit("call-finalizers"), user_package), + func_n1(gc_call_finalizers)); } /* @@ -36,6 +36,7 @@ void gc_mark(val); void gc_conservative_mark(val); int gc_is_reachable(val); val gc_finalize(val obj, val fun, val rev_order_p); +val gc_call_finalizers(val obj); #if CONFIG_GEN_GC val gc_set(loc, val); @@ -34111,6 +34111,23 @@ or any other object for finalization. Such registrations made during finalization execution are not eligible for the current phase of finalization processing; they will be processed in a later garbage collection pass. +.coNP Function @ call-finalizers +.synb +.mets (call-finalizers << object ) +.syne +.desc +The +.code call-finalizers +function invokes and removes the finalizers, if any, registered against +.metn object . +If any finalizers are called, it returns +.codn t , +otherwise +.code nil . + +Note: the behavior is unspecified if a finalizer function calls +.codn call-finalizers . + .SS* Modularization .coNP Variable @ self-path .desc |