don't call reload_initiate if already initiated

This commit is contained in:
MicroDev 2023-03-21 21:34:30 +05:30
parent 7ee3f30c17
commit e4b5b20ebe
No known key found for this signature in database
GPG Key ID: 2C0867BE60967730

View File

@ -82,15 +82,19 @@ inline bool autoreload_is_enabled() {
} }
void autoreload_trigger() { void autoreload_trigger() {
if (autoreload_enabled & !autoreload_suspended) { if (!autoreload_enabled || autoreload_suspended != 0) {
last_autoreload_trigger = supervisor_ticks_ms32(); return;
// Guard against the rare time that ticks is 0; }
if (last_autoreload_trigger == 0) { bool reload_initiated = autoreload_pending();
last_autoreload_trigger += 1; last_autoreload_trigger = supervisor_ticks_ms32();
} // Guard against the rare time that ticks is 0;
// Initiate a reload of the VM immediately. Later code will pause to if (last_autoreload_trigger == 0) {
// wait for the autoreload to become ready. Doing the VM exit last_autoreload_trigger += 1;
// immediately is clearer for the user. }
// 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); reload_initiate(RUN_REASON_AUTO_RELOAD);
} }
} }
@ -111,5 +115,5 @@ bool autoreload_ready() {
} }
bool autoreload_pending(void) { bool autoreload_pending(void) {
return last_autoreload_trigger != 0; return last_autoreload_trigger > 0;
} }