From e4b5b20ebec60557af3c0c5ab35b9c4616e1dd31 Mon Sep 17 00:00:00 2001 From: MicroDev <70126934+MicroDev1@users.noreply.github.com> Date: Tue, 21 Mar 2023 21:34:30 +0530 Subject: [PATCH] don't call `reload_initiate` if already initiated --- supervisor/shared/reload.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/supervisor/shared/reload.c b/supervisor/shared/reload.c index 4e351704f8..da2ffc26e1 100644 --- a/supervisor/shared/reload.c +++ b/supervisor/shared/reload.c @@ -82,15 +82,19 @@ inline bool autoreload_is_enabled() { } void autoreload_trigger() { - if (autoreload_enabled & !autoreload_suspended) { - last_autoreload_trigger = supervisor_ticks_ms32(); - // Guard against the rare time that ticks is 0; - if (last_autoreload_trigger == 0) { - last_autoreload_trigger += 1; - } - // Initiate a reload of the VM immediately. Later code will pause to - // wait for the autoreload to become ready. Doing the VM exit - // immediately is clearer for the user. + if (!autoreload_enabled || autoreload_suspended != 0) { + return; + } + bool reload_initiated = autoreload_pending(); + last_autoreload_trigger = supervisor_ticks_ms32(); + // Guard against the rare time that ticks is 0; + if (last_autoreload_trigger == 0) { + last_autoreload_trigger += 1; + } + // Initiate a reload of the VM immediately. Later code will pause to + // wait for the autoreload to become ready. Doing the VM exit + // immediately is clearer for the user. + if (!reload_initiated) { reload_initiate(RUN_REASON_AUTO_RELOAD); } } @@ -111,5 +115,5 @@ bool autoreload_ready() { } bool autoreload_pending(void) { - return last_autoreload_trigger != 0; + return last_autoreload_trigger > 0; }