Changeset 11444 in josm
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/cache/HostLimitQueue.java
r11438 r11444 84 84 job = pollFirst(timeout, unit); 85 85 if (job != null) { 86 acquireSemaphore(job); 86 try { 87 boolean gotLock = tryAcquireSemaphore(job, timeout, unit); 88 return gotLock ? job : null; 89 } catch (InterruptedException e) { 90 // acquire my got interrupted, first offer back what was taken 91 offer(job); 92 throw e; 93 } 87 94 } 88 95 return job; … … 96 103 } 97 104 job = takeFirst(); 98 acquireSemaphore(job); 105 try { 106 acquireSemaphore(job); 107 } catch (InterruptedException e) { 108 // acquire my got interrupted, first offer back what was taken 109 offer(job); 110 throw e; 111 } 99 112 return job; 100 113 } … … 176 189 } 177 190 191 private boolean tryAcquireSemaphore(Runnable job, long timeout, TimeUnit unit) throws InterruptedException { 192 boolean ret = true; 193 if (job instanceof JCSCachedTileLoaderJob) { 194 final JCSCachedTileLoaderJob<?, ?> jcsJob = (JCSCachedTileLoaderJob<?, ?>) job; 195 Semaphore limit = getSemaphore(jcsJob); 196 if (limit != null) { 197 ret = limit.tryAcquire(timeout, unit); 198 if (ret) { 199 jcsJob.setFinishedTask(() -> releaseSemaphore(jcsJob)); 200 } 201 } 202 } 203 return ret; 204 } 205 178 206 private void releaseSemaphore(JCSCachedTileLoaderJob<?, ?> job) { 179 207 Semaphore limit = getSemaphore(job);
Note:
See TracChangeset
for help on using the changeset viewer.