From ace1c170f96f67e5861646be64e0539a6eff6e04 Mon Sep 17 00:00:00 2001 From: Charlie Nolan Date: Tue, 7 Jan 2025 19:53:38 -0800 Subject: [PATCH] Shuttles have air again. (#27884) --- code/controllers/subsystem/SSair.dm | 17 +++++++++++++++-- code/modules/shuttle/shuttle.dm | 6 +++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/code/controllers/subsystem/SSair.dm b/code/controllers/subsystem/SSair.dm index 5cbb6256890..a02013adb5e 100644 --- a/code/controllers/subsystem/SSair.dm +++ b/code/controllers/subsystem/SSair.dm @@ -85,6 +85,9 @@ SUBSYSTEM_DEF(air) /// Are we currently running in a MILLA-safe context, i.e. is is_synchronous *guaranteed* to be TRUE. Nothing outside of this file should change this. VAR_PRIVATE/in_milla_safe_code = FALSE + /// Are we in MILLA-safe code that can safely sleep? + VAR_PRIVATE/safe_to_sleep = FALSE + /// A list of callbacks waiting for MILLA to finish its tick and enter synchronous mode. var/list/waiting_for_sync = list() var/list/sleepable_waiting_for_sync = list() @@ -724,16 +727,24 @@ SUBSYSTEM_DEF(air) waiting_for_sync += CB /// Similar to addtimer, but triggers once MILLA enters synchronous mode. This version allows for sleeping if it's absolutely necessary. -/datum/controller/subsystem/air/proc/sleepable_synchronize(datum/milla_safe/CB) +/datum/controller/subsystem/air/proc/sleepable_synchronize(datum/milla_safe_must_sleep/CB) + if(safe_to_sleep) + var/was_safe = SSair.in_milla_safe_code + SSair.in_milla_safe_code = TRUE + // This is one of two intended places to call this otherwise-unsafe proc. + CB.private_unsafe_invoke() + SSair.in_milla_safe_code = was_safe + return + sleepable_waiting_for_sync += CB /datum/controller/subsystem/air/proc/is_in_milla_safe_code() return in_milla_safe_code /datum/controller/subsystem/air/proc/on_milla_tick_finished() - run_sleepless_callbacks() run_sleeping_callbacks() is_synchronous = TRUE + run_sleepless_callbacks() /datum/controller/subsystem/air/proc/run_sleepless_callbacks() // Just in case someone is naughty and decides to sleep, make sure that this method runs fully anyway. @@ -748,11 +759,13 @@ SUBSYSTEM_DEF(air) /datum/controller/subsystem/air/proc/run_sleeping_callbacks() in_milla_safe_code = TRUE + safe_to_sleep = TRUE for(var/datum/milla_safe_must_sleep/CB as anything in sleepable_waiting_for_sync) // This is one of two intended places to call this otherwise-unsafe proc. CB.private_unsafe_invoke() sleepable_waiting_for_sync.Cut() in_milla_safe_code = FALSE + safe_to_sleep = FALSE /proc/milla_tick_finished() // Any proc that wants MILLA to be synchronous should not sleep. diff --git a/code/modules/shuttle/shuttle.dm b/code/modules/shuttle/shuttle.dm index 8923e19616e..dfe2eb53605 100644 --- a/code/modules/shuttle/shuttle.dm +++ b/code/modules/shuttle/shuttle.dm @@ -448,12 +448,12 @@ if(!canMove()) return -1 - var/datum/milla_safe/docking_port_dock/milla = new() + var/datum/milla_safe_must_sleep/docking_port_dock/milla = new() milla.invoke_async(src, S1, force, transit) -/datum/milla_safe/docking_port_dock +/datum/milla_safe_must_sleep/docking_port_dock -/datum/milla_safe/docking_port_dock/on_run(obj/docking_port/mobile/mobile_port, obj/docking_port/stationary/S1, force, transit) +/datum/milla_safe_must_sleep/docking_port_dock/on_run(obj/docking_port/mobile/mobile_port, obj/docking_port/stationary/S1, force, transit) // Re-check that it's OK to dock. if(S1.get_docked() == mobile_port) mobile_port.remove_ripples()