Changeset 29484 in osm for applications/editors/josm/plugins/imagerycache/src/org/mapdb/Queues.java
- Timestamp:
- 2013-04-07T17:07:27+02:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/imagerycache/src/org/mapdb/Queues.java
r29363 r29484 1 1 package org.mapdb; 2 3 4 2 5 3 import java.io.DataInput; … … 13 11 14 12 /** 15 * Various queue salgorithms13 * Various queue algorithms 16 14 */ 17 15 public final class Queues { … … 107 105 public void clear() { 108 106 while(!isEmpty()) 109 remove();107 poll(); 110 108 } 111 109 … … 124 122 if(ret == null) throw new NoSuchElementException(); 125 123 return ret; 126 127 124 } 128 125 … … 132 129 return add(e); 133 130 } 134 135 131 136 132 … … 202 198 203 199 protected final boolean useLocks; 204 protected final Locks.RecidLocks locks; 205 200 protected final ReentrantLock[] locks; 206 201 207 202 … … 209 204 super(engine, serializer, headerRecid); 210 205 this.useLocks = useLocks; 211 locks = useLocks? new Locks.LongHashMapRecidLocks() : null;206 locks = useLocks? Utils.newLocks(32) : null; 212 207 } 213 208 … … 229 224 Node<E> n; 230 225 do{ 231 if(useLocks && head2!=0) locks.unlock(head2);226 if(useLocks && head2!=0)Utils.lock(locks,head2); 232 227 head2 =head.get(); 233 228 if(head2 == 0) return null; 234 229 235 if(useLocks && head2!=0) locks.lock(head2);230 if(useLocks && head2!=0)Utils.lock(locks,head2); 236 231 n = engine.get(head2, nodeSerializer); 237 232 }while(n==null || !head.compareAndSet(head2, n.next)); 238 233 if(useLocks && head2!=0){ 239 234 engine.delete(head2,Serializer.LONG_SERIALIZER); 240 locks.unlock(head2);235 Utils.unlock(locks,head2); 241 236 }else{ 242 237 engine.update(head2, null, nodeSerializer); … … 328 323 } 329 324 330 331 @Override 332 public boolean isEmpty() { 333 return head.get() == 0; 334 } 335 325 @Override 336 326 public boolean add(E item){ 337 327 final long nextTail = engine.put((Node<E>)Node.EMPTY, nodeSerializer); … … 347 337 } 348 338 339 @Override 349 340 public E poll(){ 350 341 while(true){ … … 472 463 473 464 @Override 465 public void clear() { 466 // praise locking 467 lock.lock(); 468 try { 469 for (int i = 0; i < size; i++) { 470 poll(); 471 } 472 } finally { 473 lock.unlock(); 474 } 475 } 476 477 @Override 474 478 public E poll() { 475 479 lock.lock(); … … 569 573 } 570 574 571 572 575 }
Note:
See TracChangeset
for help on using the changeset viewer.
