|
9 | 9 | import java.util.Objects;
|
10 | 10 | import java.util.concurrent.ExecutionException;
|
11 | 11 | import java.util.concurrent.atomic.AtomicInteger;
|
| 12 | +import java.util.concurrent.locks.Lock; |
12 | 13 | import java.util.function.Consumer;
|
13 | 14 | import java.util.stream.Collectors;
|
14 | 15 |
|
@@ -175,14 +176,22 @@ protected void done() {
|
175 | 176 | protected void process(List<MapillarySequence> chunks) {
|
176 | 177 | super.process(chunks);
|
177 | 178 | VectorDataSet ds = MapillaryLayer.getInstance().getData();
|
178 |
| - for (MapillarySequence seq : chunks) { |
179 |
| - for (MapillaryNode oldNode : seq.getNodes()) { |
180 |
| - VectorNode oldPrimitive = (VectorNode) ds.getPrimitiveById(oldNode); |
181 |
| - if (oldPrimitive != null) { |
182 |
| - oldPrimitive.putAll(oldNode.getKeys()); |
183 |
| - oldPrimitive.setCoor(oldNode.getCoor()); |
| 179 | + // Technically a writeLock would be better, but we cannot get that with the current VectorDataSet |
| 180 | + // implementation. |
| 181 | + final Lock dsLock = ds.getReadLock(); |
| 182 | + try { |
| 183 | + dsLock.lock(); |
| 184 | + for (MapillarySequence seq : chunks) { |
| 185 | + for (MapillaryNode oldNode : seq.getNodes()) { |
| 186 | + VectorNode oldPrimitive = (VectorNode) ds.getPrimitiveById(oldNode); |
| 187 | + if (oldPrimitive != null) { |
| 188 | + oldPrimitive.putAll(oldNode.getKeys()); |
| 189 | + oldPrimitive.setCoor(oldNode.getCoor()); |
| 190 | + } |
184 | 191 | }
|
185 | 192 | }
|
| 193 | + } finally { |
| 194 | + dsLock.unlock(); |
186 | 195 | }
|
187 | 196 | // The counter just avoids many resets of the imagery window in short order
|
188 | 197 | if (!chunks.isEmpty() && counter.getAndAdd(chunks.size()) < 3) {
|
|
0 commit comments