From 146e0bf5693e09dc7478047102025560bc56627e Mon Sep 17 00:00:00 2001 From: Mikayla Fischler Date: Wed, 27 Apr 2022 15:56:55 -0400 Subject: [PATCH] protected sleep call --- reactor-plc/startup.lua | 2 +- reactor-plc/threads.lua | 10 ++++++---- rtu/startup.lua | 2 +- rtu/threads.lua | 6 ++++-- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/reactor-plc/startup.lua b/reactor-plc/startup.lua index df117f5..bca0027 100644 --- a/reactor-plc/startup.lua +++ b/reactor-plc/startup.lua @@ -12,7 +12,7 @@ os.loadAPI("config.lua") os.loadAPI("plc.lua") os.loadAPI("threads.lua") -local R_PLC_VERSION = "alpha-v0.4.1" +local R_PLC_VERSION = "alpha-v0.4.2" local print = util.print local println = util.println diff --git a/reactor-plc/threads.lua b/reactor-plc/threads.lua index 17ab22e..ce17609 100644 --- a/reactor-plc/threads.lua +++ b/reactor-plc/threads.lua @@ -8,6 +8,8 @@ local println = util.println local print_ts = util.print_ts local println_ts = util.println_ts +local psleep = util.psleep + local MAIN_CLOCK = 1 -- (1Hz, 20 ticks) local ISS_CLOCK = 0.5 -- (2Hz, 10 ticks) local COMMS_CLOCK = 0.25 -- (4Hz, 5 ticks) @@ -302,9 +304,9 @@ function thread__iss(smem) local sleep_for = ISS_CLOCK - (util.time() - last_update) last_update = util.time() if sleep_for > 0 then - sleep(sleep_for) + psleep(sleep_for) else - sleep(0.05) + psleep(0.05) end end end @@ -361,9 +363,9 @@ function thread__comms(smem) local sleep_for = COMMS_CLOCK - (util.time() - last_update) last_update = util.time() if sleep_for > 0 then - sleep(sleep_for) + psleep(sleep_for) else - sleep(0.05) + psleep(0.05) end end end diff --git a/rtu/startup.lua b/rtu/startup.lua index fed7dd0..c04a902 100644 --- a/rtu/startup.lua +++ b/rtu/startup.lua @@ -19,7 +19,7 @@ os.loadAPI("dev/boiler_rtu.lua") os.loadAPI("dev/imatrix_rtu.lua") os.loadAPI("dev/turbine_rtu.lua") -local RTU_VERSION = "alpha-v0.4.1" +local RTU_VERSION = "alpha-v0.4.2" local print = util.print local println = util.println diff --git a/rtu/threads.lua b/rtu/threads.lua index 3f021a6..692697d 100644 --- a/rtu/threads.lua +++ b/rtu/threads.lua @@ -8,6 +8,8 @@ local println = util.println local print_ts = util.print_ts local println_ts = util.println_ts +local psleep = util.psleep + local MAIN_CLOCK = 2 -- (2Hz, 40 ticks) local COMMS_CLOCK = 0.25 -- (4Hz, 5 ticks) @@ -146,9 +148,9 @@ function thread__comms(smem) local sleep_for = COMMS_CLOCK - (util.time() - last_update) last_update = util.time() if sleep_for > 0 then - sleep(sleep_for) + psleep(sleep_for) else - sleep(0.05) + psleep(0.05) end end end