performance, bug 3380: replacing TrackedRaceImpl.windSourcesToExclude by a ConcurrentHashMap, removing the need to use "synchronized"

This commit is contained in:
Axel Uhl committed 2015-12-03 17:11:29 +01:00
1 parent ac7f3de28d
commit a3613c6f23
1 file changed
+11 -15
@@ -183,7 +183,7 @@ public abstract class TrackedRaceImpl extends TrackedRaceWithWindEssentials impl
* By default, all wind sources are used, none are excluded. However, e.g., for performance reasons, particular wind
* sources such as the track-based estimation wind source, may be excluded by adding them to this set.
*/
private final Set<WindSource> windSourcesToExclude;
private final ConcurrentHashMap<WindSource, TrackedRaceImpl> windSourcesToExclude;
/**
* Keeps the oldest timestamp that is fed into this tracked race, either from a boat fix, a mark fix, a race
@@ -424,7 +424,7 @@ public abstract class TrackedRaceImpl extends TrackedRaceWithWindEssentials impl
+ race.getName(), /* fair */ false);
this.cacheInvalidationTimerLock = new Object();
this.updateCount = 0;
this.windSourcesToExclude = new HashSet<WindSource>();
this.windSourcesToExclude = new ConcurrentHashMap<>();
this.directionFromStartToNextMarkCache = new HashMap<TimePoint, Future<Wind>>();
this.millisecondsOverWhichToAverageSpeed = millisecondsOverWhichToAverageSpeed;
this.delayToLiveInMillis = delayToLiveInMillis;
@@ -1679,24 +1679,20 @@ public abstract class TrackedRaceImpl extends TrackedRaceWithWindEssentials impl
@Override
public Set<WindSource> getWindSourcesToExclude() {
synchronized (windSourcesToExclude) {
return Collections.unmodifiableSet(windSourcesToExclude);
}
return Collections.unmodifiableSet(windSourcesToExclude.keySet());
}
@Override
public void setWindSourcesToExclude(Iterable<? extends WindSource> windSourcesToExclude) {
Set<WindSource> old = new HashSet<>(this.windSourcesToExclude);
synchronized (this.windSourcesToExclude) {
LockUtil.lockForRead(getSerializationLock());
try {
this.windSourcesToExclude.clear();
for (WindSource windSourceToExclude : windSourcesToExclude) {
this.windSourcesToExclude.add(windSourceToExclude);
}
} finally {
LockUtil.unlockAfterRead(getSerializationLock());
Set<WindSource> old = new HashSet<>(getWindSourcesToExclude());
LockUtil.lockForRead(getSerializationLock());
try {
this.windSourcesToExclude.clear();
for (WindSource windSourceToExclude : windSourcesToExclude) {
this.windSourcesToExclude.put(windSourceToExclude, this);
}
} finally {
LockUtil.unlockAfterRead(getSerializationLock());
}
if (!old.equals(this.windSourcesToExclude)) {
clearAllCachesExceptManeuvers();