Changeset 7448 in josm


Ignore:
Timestamp:
2014-08-27T20:14:45+02:00 (10 years ago)
Author:
bastiK
Message:

see #10425 - fix [7447]: lock prevented mappaint code in StyledMapRenderer from running in parallel

Location:
trunk/src/org/openstreetmap/josm
Files:
6 edited

Legend:

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

    r7447 r7448  
    13431343        @Override
    13441344        public List<StyleRecord> call() throws Exception {
    1345             synchronized (MapCSSStyleSource.STYLE_SOURCE_LOCK) {
     1345            MapCSSStyleSource.STYLE_SOURCE_LOCK.readLock().lock();
     1346            try {
    13461347                for (int i = from; i<to; i++) {
    13471348                    OsmPrimitive osm = input.get(i);
     
    13511352                }
    13521353                return output;
     1354            } finally {
     1355                MapCSSStyleSource.STYLE_SOURCE_LOCK.readLock().unlock();
    13531356            }
    13541357        }
  • trunk/src/org/openstreetmap/josm/gui/NavigatableComponent.java

    r7447 r7448  
    9191            if (!prim.isSelectable()) return false;
    9292            // if it isn't displayed on screen, you cannot click on it
    93             synchronized (MapCSSStyleSource.STYLE_SOURCE_LOCK) {
     93            MapCSSStyleSource.STYLE_SOURCE_LOCK.readLock().lock();
     94            try {
    9495                return !MapPaintStyles.getStyles().get(prim, getDist100Pixel(), NavigatableComponent.this).isEmpty();
     96            } finally {
     97                MapCSSStyleSource.STYLE_SOURCE_LOCK.readLock().unlock();
    9598            }
    9699        }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/InspectPrimitiveDialog.java

    r7447 r7448  
    337337        double scale = nc.getDist100Pixel();
    338338
    339         synchronized (MapCSSStyleSource.STYLE_SOURCE_LOCK) {
     339        MapCSSStyleSource.STYLE_SOURCE_LOCK.readLock().lock();
     340        try {
    340341            for (OsmPrimitive osm : sel) {
    341342                txtMappaint.append(tr("Styles Cache for \"{0}\":", osm.getDisplayName(DefaultNameFormatter.getInstance())));
     
    362363                txtMappaint.append("\n\n");
    363364            }
     365        } finally {
     366            MapCSSStyleSource.STYLE_SOURCE_LOCK.readLock().unlock();
    364367        }
    365368        if (sel.size() == 2) {
  • trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyles.java

    r7447 r7448  
    447447     */
    448448    public static AreaElemStyle getAreaElemStyle(OsmPrimitive p, boolean pretendWayIsClosed) {
    449         synchronized (MapCSSStyleSource.STYLE_SOURCE_LOCK) {
     449        MapCSSStyleSource.STYLE_SOURCE_LOCK.readLock().lock();
     450        try {
    450451            if (MapPaintStyles.getStyles() == null)
    451452                return null;
     
    455456            }
    456457            return null;
     458        } finally {
     459            MapCSSStyleSource.STYLE_SOURCE_LOCK.readLock().unlock();
    457460        }
    458461    }
  • trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java

    r7447 r7448  
    144144            virtualNode.put(tag.getKey(), tag.getValue());
    145145            StyleList styleList;
    146             synchronized (MapCSSStyleSource.STYLE_SOURCE_LOCK) {
     146            MapCSSStyleSource.STYLE_SOURCE_LOCK.readLock().lock();
     147            try {
    147148                styleList = getStyles().generateStyles(virtualNode, 0.5, null, false).a;
     149            } finally {
     150                MapCSSStyleSource.STYLE_SOURCE_LOCK.readLock().unlock();
    148151            }
    149152            if (styleList != null) {
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSStyleSource.java

    r7447 r7448  
    2020import java.util.Map.Entry;
    2121import java.util.Set;
     22import java.util.concurrent.locks.ReadWriteLock;
     23import java.util.concurrent.locks.ReentrantReadWriteLock;
    2224import java.util.zip.ZipEntry;
    2325import java.util.zip.ZipFile;
     
    7072
    7173    /**
    72      * This lock prevents concurrent execution of {@link MapCSSRuleIndex#clear() },
     74     * This lock prevents concurrent execution of {@link MapCSSRuleIndex#clear() } /
    7375     * {@link MapCSSRuleIndex#initIndex()} and {@link MapCSSRuleIndex#getRuleCandidates }.
    7476     *
     
    7678     * stack trace.
    7779     */
    78     public final static Object STYLE_SOURCE_LOCK = new Object();
    79    
     80    public final static ReadWriteLock STYLE_SOURCE_LOCK = new ReentrantReadWriteLock();
     81
    8082    /**
    8183     * A collection of {@link MapCSSRule}s, that are indexed by tag key and value.
     
    100102        public final Set<MapCSSRule> remaining = new HashSet<>();
    101103       
    102         private static final boolean DEBUG_LOCKING = false;
    103        
    104104        public void add(MapCSSRule rule) {
    105105            rules.add(rule);
     
    109109         * Initialize the index.
    110110         *
    111          * You must own the lock STYLE_SOURCE_LOCK when calling this method.
     111         * You must own the write lock of STYLE_SOURCE_LOCK when calling this method.
    112112         */
    113113        public void initIndex() {
    114             if (DEBUG_LOCKING) {
    115                 if (!Thread.holdsLock(STYLE_SOURCE_LOCK)) {
    116                     throw new RuntimeException();
    117                 }
    118             }
    119114            for (MapCSSRule r: rules) {
    120115                // find the rightmost selector, this must be a GeneralSelector
     
    154149         * that cannot match, based on the tags of the primitive
    155150         *
    156          * You must own the lock STYLE_SOURCE_LOCK when calling this method.
     151         * You must have a read lock of STYLE_SOURCE_LOCK when calling this method.
    157152         */
    158153        public Collection<MapCSSRule> getRuleCandidates(OsmPrimitive osm) {
    159             if (DEBUG_LOCKING) {
    160                 if (!Thread.holdsLock(STYLE_SOURCE_LOCK)) {
    161                     throw new RuntimeException();
    162                 }
    163             }
    164154            List<MapCSSRule> ruleCandidates = new ArrayList<>(remaining);
    165155            for (Map.Entry<String,String> e : osm.getKeys().entrySet()) {
     
    179169         * Clear the index.
    180170         *
    181          * You must own the lock STYLE_SOURCE_LOCK when calling this method.
     171         * You must own the write lock STYLE_SOURCE_LOCK when calling this method.
    182172         */
    183173        public void clear() {
    184             if (DEBUG_LOCKING) {
    185                 if (!Thread.holdsLock(STYLE_SOURCE_LOCK)) {
    186                     throw new RuntimeException();
    187                 }
    188             }
    189174            rules.clear();
    190175            index.clear();
     
    216201    @Override
    217202    public void loadStyleSource() {
    218         synchronized (STYLE_SOURCE_LOCK) {
     203        STYLE_SOURCE_LOCK.writeLock().lock();
     204        try {
    219205            init();
    220206            rules.clear();
     
    304290            multipolygonRules.initIndex();
    305291            canvasRules.initIndex();
     292        } finally {
     293            STYLE_SOURCE_LOCK.writeLock().unlock();
    306294        }
    307295    }
Note: See TracChangeset for help on using the changeset viewer.