+/* We need a mechanism to release the lock and invoke finalizers. */
+/* We don't really have an opportunity to do this on a rarely executed */
+/* path on which the lock is not held. Thus we check at a */
+/* rarely executed point at which it is safe to release the lock. */
+/* We do this even where we could just call GC_INVOKE_FINALIZERS, */
+/* since it's probably cheaper and certainly more uniform. */
+/* FIXME - Consider doing the same elsewhere? */
+static void maybe_finalize()
+{
+ static int last_finalized_no = 0;
+
+ if (GC_gc_no == last_finalized_no) return;
+ if (!GC_is_initialized) return;
+ UNLOCK();
+ GC_INVOKE_FINALIZERS();
+ last_finalized_no = GC_gc_no;
+ LOCK();
+}
+