Changeset 7448 in josm
- Timestamp:
- 2014-08-27T20:14:45+02:00 (10 years ago)
- 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 1343 1343 @Override 1344 1344 public List<StyleRecord> call() throws Exception { 1345 synchronized (MapCSSStyleSource.STYLE_SOURCE_LOCK) { 1345 MapCSSStyleSource.STYLE_SOURCE_LOCK.readLock().lock(); 1346 try { 1346 1347 for (int i = from; i<to; i++) { 1347 1348 OsmPrimitive osm = input.get(i); … … 1351 1352 } 1352 1353 return output; 1354 } finally { 1355 MapCSSStyleSource.STYLE_SOURCE_LOCK.readLock().unlock(); 1353 1356 } 1354 1357 } -
trunk/src/org/openstreetmap/josm/gui/NavigatableComponent.java
r7447 r7448 91 91 if (!prim.isSelectable()) return false; 92 92 // 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 { 94 95 return !MapPaintStyles.getStyles().get(prim, getDist100Pixel(), NavigatableComponent.this).isEmpty(); 96 } finally { 97 MapCSSStyleSource.STYLE_SOURCE_LOCK.readLock().unlock(); 95 98 } 96 99 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/InspectPrimitiveDialog.java
r7447 r7448 337 337 double scale = nc.getDist100Pixel(); 338 338 339 synchronized (MapCSSStyleSource.STYLE_SOURCE_LOCK) { 339 MapCSSStyleSource.STYLE_SOURCE_LOCK.readLock().lock(); 340 try { 340 341 for (OsmPrimitive osm : sel) { 341 342 txtMappaint.append(tr("Styles Cache for \"{0}\":", osm.getDisplayName(DefaultNameFormatter.getInstance()))); … … 362 363 txtMappaint.append("\n\n"); 363 364 } 365 } finally { 366 MapCSSStyleSource.STYLE_SOURCE_LOCK.readLock().unlock(); 364 367 } 365 368 if (sel.size() == 2) { -
trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyles.java
r7447 r7448 447 447 */ 448 448 public static AreaElemStyle getAreaElemStyle(OsmPrimitive p, boolean pretendWayIsClosed) { 449 synchronized (MapCSSStyleSource.STYLE_SOURCE_LOCK) { 449 MapCSSStyleSource.STYLE_SOURCE_LOCK.readLock().lock(); 450 try { 450 451 if (MapPaintStyles.getStyles() == null) 451 452 return null; … … 455 456 } 456 457 return null; 458 } finally { 459 MapCSSStyleSource.STYLE_SOURCE_LOCK.readLock().unlock(); 457 460 } 458 461 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java
r7447 r7448 144 144 virtualNode.put(tag.getKey(), tag.getValue()); 145 145 StyleList styleList; 146 synchronized (MapCSSStyleSource.STYLE_SOURCE_LOCK) { 146 MapCSSStyleSource.STYLE_SOURCE_LOCK.readLock().lock(); 147 try { 147 148 styleList = getStyles().generateStyles(virtualNode, 0.5, null, false).a; 149 } finally { 150 MapCSSStyleSource.STYLE_SOURCE_LOCK.readLock().unlock(); 148 151 } 149 152 if (styleList != null) { -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSStyleSource.java
r7447 r7448 20 20 import java.util.Map.Entry; 21 21 import java.util.Set; 22 import java.util.concurrent.locks.ReadWriteLock; 23 import java.util.concurrent.locks.ReentrantReadWriteLock; 22 24 import java.util.zip.ZipEntry; 23 25 import java.util.zip.ZipFile; … … 70 72 71 73 /** 72 * This lock prevents concurrent execution of {@link MapCSSRuleIndex#clear() } ,74 * This lock prevents concurrent execution of {@link MapCSSRuleIndex#clear() } / 73 75 * {@link MapCSSRuleIndex#initIndex()} and {@link MapCSSRuleIndex#getRuleCandidates }. 74 76 * … … 76 78 * stack trace. 77 79 */ 78 public final static Object STYLE_SOURCE_LOCK = new Object();79 80 public final static ReadWriteLock STYLE_SOURCE_LOCK = new ReentrantReadWriteLock(); 81 80 82 /** 81 83 * A collection of {@link MapCSSRule}s, that are indexed by tag key and value. … … 100 102 public final Set<MapCSSRule> remaining = new HashSet<>(); 101 103 102 private static final boolean DEBUG_LOCKING = false;103 104 104 public void add(MapCSSRule rule) { 105 105 rules.add(rule); … … 109 109 * Initialize the index. 110 110 * 111 * You must own the lockSTYLE_SOURCE_LOCK when calling this method.111 * You must own the write lock of STYLE_SOURCE_LOCK when calling this method. 112 112 */ 113 113 public void initIndex() { 114 if (DEBUG_LOCKING) {115 if (!Thread.holdsLock(STYLE_SOURCE_LOCK)) {116 throw new RuntimeException();117 }118 }119 114 for (MapCSSRule r: rules) { 120 115 // find the rightmost selector, this must be a GeneralSelector … … 154 149 * that cannot match, based on the tags of the primitive 155 150 * 156 * You must own the lockSTYLE_SOURCE_LOCK when calling this method.151 * You must have a read lock of STYLE_SOURCE_LOCK when calling this method. 157 152 */ 158 153 public Collection<MapCSSRule> getRuleCandidates(OsmPrimitive osm) { 159 if (DEBUG_LOCKING) {160 if (!Thread.holdsLock(STYLE_SOURCE_LOCK)) {161 throw new RuntimeException();162 }163 }164 154 List<MapCSSRule> ruleCandidates = new ArrayList<>(remaining); 165 155 for (Map.Entry<String,String> e : osm.getKeys().entrySet()) { … … 179 169 * Clear the index. 180 170 * 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. 182 172 */ 183 173 public void clear() { 184 if (DEBUG_LOCKING) {185 if (!Thread.holdsLock(STYLE_SOURCE_LOCK)) {186 throw new RuntimeException();187 }188 }189 174 rules.clear(); 190 175 index.clear(); … … 216 201 @Override 217 202 public void loadStyleSource() { 218 synchronized (STYLE_SOURCE_LOCK) { 203 STYLE_SOURCE_LOCK.writeLock().lock(); 204 try { 219 205 init(); 220 206 rules.clear(); … … 304 290 multipolygonRules.initIndex(); 305 291 canvasRules.initIndex(); 292 } finally { 293 STYLE_SOURCE_LOCK.writeLock().unlock(); 306 294 } 307 295 }
Note:
See TracChangeset
for help on using the changeset viewer.