Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Unity-Technologies/bdwgc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBill Holmes <bill.holmes@unity3d.com>2021-10-22 18:53:26 +0300
committerBill Holmes <bill.holmes@unity3d.com>2021-10-22 18:53:26 +0300
commit7c11c39eec4f7936e4aea0e56753de9eb8541874 (patch)
treebc16fe321b52d74d85dd40f091435b03c02ec34f
parent1032fe80d582aa4b58415b84c257091d3172b3ad (diff)
Adding a call to allow the finalizer loop to be interrupted.unity-case-1363998
GC_invoke_finalizers can take a long period of time to complete. During Mono shutdown we need a way to safely stop the finalization of objects.
-rw-r--r--finalize.c10
-rw-r--r--include/gc.h4
2 files changed, 13 insertions, 1 deletions
diff --git a/finalize.c b/finalize.c
index 8790a5b9..6d04c2f9 100644
--- a/finalize.c
+++ b/finalize.c
@@ -1264,6 +1264,14 @@ GC_INNER void GC_finalize(void)
#endif /* !JAVA_FINALIZATION_NOT_NEEDED */
+static volatile GC_bool GC_interrupt_finalizers = FALSE;
+
+void
+GC_set_interrupt_finalizers(void)
+{
+ GC_interrupt_finalizers = TRUE;
+}
+
/* Returns true if it is worth calling GC_invoke_finalizers. (Useful if */
/* finalizers can only be called from some kind of "safe state" and */
/* getting into that safe state is expensive.) */
@@ -1284,7 +1292,7 @@ GC_API int GC_CALL GC_invoke_finalizers(void)
word bytes_freed_before = 0; /* initialized to prevent warning. */
DCL_LOCK_STATE;
- while (GC_should_invoke_finalizers()) {
+ while (GC_should_invoke_finalizers() && !GC_interrupt_finalizers) {
struct finalizable_object * curr_fo;
# ifdef THREADS
diff --git a/include/gc.h b/include/gc.h
index 3d10a9a4..fb7d73d5 100644
--- a/include/gc.h
+++ b/include/gc.h
@@ -1294,6 +1294,10 @@ GC_API GC_await_finalize_proc GC_CALL GC_get_await_finalize_proc(void);
/* Does not use any synchronization. */
GC_API int GC_CALL GC_should_invoke_finalizers(void);
+/* Sets flag to signal GC_invoke_finalizers to break */
+/* Does not use any synchronization. */
+GC_API void GC_CALL GC_set_interrupt_finalizers(void);
+
GC_API int GC_CALL GC_invoke_finalizers(void);
/* Run finalizers for all objects that are ready to */
/* be finalized. Return the number of finalizers */