From 7eaa65bee53b4f8f283f3e2d948bee3cc69b15e8 Mon Sep 17 00:00:00 2001 From: Axel Uhl Date: Thu, 29 Jul 2021 00:11:22 +0900 Subject: [PATCH] bug5608: removed redundant put to windTracks in createWindTrack --- .../TrackedRaceWithWindEssentials.java | 34 +++++++++---------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/TrackedRaceWithWindEssentials.java b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/TrackedRaceWithWindEssentials.java index 41aa97ed289..0ad87d43b78 100644 --- a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/TrackedRaceWithWindEssentials.java +++ b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/TrackedRaceWithWindEssentials.java @@ -103,16 +103,21 @@ public abstract class TrackedRaceWithWindEssentials implements TrackedRace { result = getLegMiddleWindTrack((WindSourceWithAdditionalID) windSource); } else { final WindTrack windTrackCreated[] = new WindTrack[1]; - // atomically add to windTracks if not yet there and assign to windTrackCreated[0] so we know - // whether creation took place and we need to log/notify. See also bug5608. - result = windTracks.computeIfAbsent(windSource, ws->(windTrackCreated[0]= - windSource.getType() == WindSourceType.MANEUVER_BASED_ESTIMATION - // wind track of wind estimation gets unavailable only in one case: wind estimation was detached - // but it is still running. Hence, return dummy track to complete to finish the run. - ? new DummyWindTrackImpl() - : createWindTrack(windSource, - delayForWindEstimationCacheInvalidation == -1 ? getMillisecondsOverWhichToAverageWind() / 2 - : delayForWindEstimationCacheInvalidation))); + LockUtil.lockForRead(getSerializationLock()); + try { + // atomically add to windTracks if not yet there and assign to windTrackCreated[0] so we know + // whether creation took place and we need to log/notify. See also bug5608. + result = windTracks.computeIfAbsent(windSource, ws->(windTrackCreated[0]= + windSource.getType() == WindSourceType.MANEUVER_BASED_ESTIMATION + // wind track of wind estimation gets unavailable only in one case: wind estimation was detached + // but it is still running. Hence, return dummy track to complete to finish the run. + ? new DummyWindTrackImpl() + : createWindTrack(windSource, + delayForWindEstimationCacheInvalidation == -1 ? getMillisecondsOverWhichToAverageWind() / 2 + : delayForWindEstimationCacheInvalidation))); + } finally { + LockUtil.unlockAfterRead(getSerializationLock()); + } if (windTrackCreated[0] != null) { // give subclasses a chance to react to the creation of a wind track *after* is has been added to windTracks notifyWindTrackHasBeenCreatedAndAddedToWindTracks(windSource, windTrackCreated[0]); @@ -139,15 +144,8 @@ public abstract class TrackedRaceWithWindEssentials implements TrackedRace { * no other wind source exists yet. */ protected WindTrack createWindTrack(WindSource windSource, long delayForWindEstimationCacheInvalidation) { - WindTrack result = windStore.getWindTrack(trackedRegatta.getRegatta().getName(), this, windSource, millisecondsOverWhichToAverageWind, + return windStore.getWindTrack(trackedRegatta.getRegatta().getName(), this, windSource, millisecondsOverWhichToAverageWind, delayForWindEstimationCacheInvalidation); - LockUtil.lockForRead(getSerializationLock()); - try { - windTracks.put(windSource, result); - } finally { - LockUtil.unlockAfterRead(getSerializationLock()); - } - return result; } private WindSource getLegMiddleWindSource(TrackedLeg trackedLeg) {