Changeset 7107 in josm for trunk


Ignore:
Timestamp:
2014-05-11T17:36:15+02:00 (6 years ago)
Author:
bastiK
Message:

mappaint: hold read lock on Dataset during painting, so modifications do not lead to inconsistent state (fixes #8671, see #9691)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java

    r7090 r7107  
    15111511        }
    15121512
    1513         List<Node> nodes = data.searchNodes(bbox);
    1514         List<Way> ways = data.searchWays(bbox);
    1515         List<Relation> relations = data.searchRelations(bbox);
    1516 
    1517         final List<StyleRecord> allStyleElems = new ArrayList<>(nodes.size()+ways.size()+relations.size());
    1518 
    1519         ConcurrentTasksHelper helper = new ConcurrentTasksHelper(allStyleElems, data);
    1520 
    1521         // Need to process all relations first.
    1522         // Reason: Make sure, ElemStyles.getStyleCacheWithRange is
    1523         // not called for the same primitive in parallel threads.
    1524         // (Could be synchronized, but try to avoid this for
    1525         // performance reasons.)
    1526         helper.process(relations);
    1527         helper.process(new CompositeList<>(nodes, ways));
    1528 
    1529         if (Main.isTraceEnabled()) {
    1530             timePhase1 = System.currentTimeMillis();
    1531             System.err.print("phase 1 (calculate styles): " + (timePhase1 - timeStart) + " ms");
    1532         }
    1533 
    1534         Collections.sort(allStyleElems);
    1535 
    1536         for (StyleRecord r : allStyleElems) {
    1537             r.style.paintPrimitive(
    1538                     r.osm,
    1539                     paintSettings,
    1540                     StyledMapRenderer.this,
    1541                     (r.flags & FLAG_SELECTED) != 0,
    1542                     (r.flags & FLAG_MEMBER_OF_SELECTED) != 0
    1543             );
    1544         }
    1545 
    1546         if (Main.isTraceEnabled()) {
    1547             timeFinished = System.currentTimeMillis();
    1548             System.err.println("; phase 2 (draw): " + (timeFinished - timePhase1) + " ms; total: " + (timeFinished - timeStart) + " ms");
    1549         }
    1550 
    1551         drawVirtualNodes(data, bbox);
     1513        data.getReadLock().lock();
     1514        try {
     1515            List<Node> nodes = data.searchNodes(bbox);
     1516            List<Way> ways = data.searchWays(bbox);
     1517            List<Relation> relations = data.searchRelations(bbox);
     1518
     1519            final List<StyleRecord> allStyleElems = new ArrayList<>(nodes.size()+ways.size()+relations.size());
     1520
     1521            ConcurrentTasksHelper helper = new ConcurrentTasksHelper(allStyleElems, data);
     1522
     1523            // Need to process all relations first.
     1524            // Reason: Make sure, ElemStyles.getStyleCacheWithRange is
     1525            // not called for the same primitive in parallel threads.
     1526            // (Could be synchronized, but try to avoid this for
     1527            // performance reasons.)
     1528            helper.process(relations);
     1529            helper.process(new CompositeList<>(nodes, ways));
     1530
     1531            if (Main.isTraceEnabled()) {
     1532                timePhase1 = System.currentTimeMillis();
     1533                System.err.print("phase 1 (calculate styles): " + (timePhase1 - timeStart) + " ms");
     1534            }
     1535
     1536            Collections.sort(allStyleElems);
     1537
     1538            for (StyleRecord r : allStyleElems) {
     1539                r.style.paintPrimitive(
     1540                        r.osm,
     1541                        paintSettings,
     1542                        StyledMapRenderer.this,
     1543                        (r.flags & FLAG_SELECTED) != 0,
     1544                        (r.flags & FLAG_MEMBER_OF_SELECTED) != 0
     1545                );
     1546            }
     1547
     1548            if (Main.isTraceEnabled()) {
     1549                timeFinished = System.currentTimeMillis();
     1550                System.err.println("; phase 2 (draw): " + (timeFinished - timePhase1) + " ms; total: " + (timeFinished - timeStart) + " ms");
     1551            }
     1552
     1553            drawVirtualNodes(data, bbox);
     1554        } finally {
     1555            data.getReadLock().unlock();
     1556        }
    15521557    }
    15531558}
Note: See TracChangeset for help on using the changeset viewer.