From 71ac99cb50f3e4f62dbabb436cc89825e31e7543 Mon Sep 17 00:00:00 2001 From: joylink_zhangsai <1021828630@qq.com> Date: Mon, 22 Feb 2021 10:55:55 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BD=A6=E7=AB=99=E9=A2=84=E5=A4=8D=E4=BD=8D?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../simulation/cbtc/ATS/service/AtsStationService.java | 8 ++++---- .../joylink/rtss/simulation/cbtc/data/map/Station.java | 7 ++++--- .../rtss/simulation/cbtc/data/status/StationStatus.java | 4 ++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/AtsStationService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/AtsStationService.java index 641d6786c..8ba0404b2 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/AtsStationService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/AtsStationService.java @@ -429,7 +429,7 @@ public class AtsStationService { * 计轴预复位 */ public void preReset(Simulation simulation, Station station) { - station.setPreResetValidDuration(60 * 1000); + station.getPreResetValidDuration().set(60 * 1000); } /** @@ -446,9 +446,9 @@ public class AtsStationService { } private void updatePreResetRemainderTime(Station station) { - int remainderTime = station.getPreResetValidDuration(); - if (remainderTime > 0) { - station.setPreResetValidDuration(Math.max(0, remainderTime - SimulationConstants.ATS_LOOP_RATE)); + int validDuration = station.getPreResetValidDuration().get(); + if (validDuration > 0) { + station.getPreResetValidDuration().compareAndExchange(validDuration, Math.max(0, validDuration - SimulationConstants.ATS_LOOP_RATE)); } } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/data/map/Station.java b/src/main/java/club/joylink/rtss/simulation/cbtc/data/map/Station.java index 9f5f3b680..632df6c24 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/data/map/Station.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/data/map/Station.java @@ -17,6 +17,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; @Getter @@ -180,7 +181,7 @@ public class Station extends MayOutOfOrderDevice { /** * 预复位剩余时间/ms */ - private int preResetValidDuration; + private AtomicInteger preResetValidDuration = new AtomicInteger(0); @Override public void reset() { @@ -204,7 +205,7 @@ public class Station extends MayOutOfOrderDevice { this.controller = null; this.emergencyController = false; this.controlApplicant = null; - this.preResetValidDuration = 0; + this.preResetValidDuration = new AtomicInteger(0); } public List getStandOf(boolean right) { @@ -402,7 +403,7 @@ public class Station extends MayOutOfOrderDevice { } public int getPreResetValidDurationInSeconds() { - return this.preResetValidDuration / 1000; + return this.preResetValidDuration.get() / 1000; } public enum ControlMode { diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/data/status/StationStatus.java b/src/main/java/club/joylink/rtss/simulation/cbtc/data/status/StationStatus.java index e60c8258c..195978c01 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/data/status/StationStatus.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/data/status/StationStatus.java @@ -145,9 +145,9 @@ public class StationStatus extends DeviceStatus { this.controlApplicant = station.getControlApplicantId(); } status.setControlApplicant(this.controlApplicant); - if (Objects.equals(this.preResetValidDuration, station.getPreResetValidDuration())) { + if (Objects.equals(this.preResetValidDuration, station.getPreResetValidDurationInSeconds())) { change = true; - this.preResetValidDuration = station.getPreResetValidDuration(); + this.preResetValidDuration = station.getPreResetValidDurationInSeconds(); status.setPreResetValidDuration(this.preResetValidDuration); } return change;