Ignore:
Timestamp:
2013-04-07T17:07:27+02:00 (13 years ago)
Author:
akks
Message:

JOSM/ImageryCache: updated MapDB (no more deadlocks, Java 1.6 compatible), less crashes, multiple-JOSM support

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/imagerycache/src/org/mapdb/Queues.java

    r29363 r29484  
    11package org.mapdb;
    2 
    3 
    42
    53import java.io.DataInput;
     
    1311
    1412/**
    15  * Various queues algorithms
     13 * Various queue algorithms
    1614 */
    1715public final class Queues {
     
    107105        public void clear() {
    108106            while(!isEmpty())
    109                 remove();
     107                poll();
    110108        }
    111109
     
    124122            if(ret == null) throw new NoSuchElementException();
    125123            return ret;
    126 
    127124        }
    128125
     
    132129            return add(e);
    133130        }
    134 
    135131
    136132
     
    202198
    203199        protected final boolean useLocks;
    204         protected final Locks.RecidLocks locks;
    205 
     200        protected final ReentrantLock[] locks;
    206201
    207202
     
    209204            super(engine, serializer, headerRecid);
    210205            this.useLocks = useLocks;
    211             locks = useLocks? new Locks.LongHashMapRecidLocks() : null;
     206            locks = useLocks? Utils.newLocks(32) : null;
    212207        }
    213208
     
    229224            Node<E> n;
    230225            do{
    231                 if(useLocks && head2!=0)locks.unlock(head2);
     226                if(useLocks && head2!=0)Utils.lock(locks,head2);
    232227                head2 =head.get();
    233228                if(head2 == 0) return null;
    234229
    235                 if(useLocks && head2!=0)locks.lock(head2);
     230                if(useLocks && head2!=0)Utils.lock(locks,head2);
    236231                n = engine.get(head2, nodeSerializer);
    237232            }while(n==null || !head.compareAndSet(head2, n.next));
    238233            if(useLocks && head2!=0){
    239234                engine.delete(head2,Serializer.LONG_SERIALIZER);
    240                 locks.unlock(head2);
     235                Utils.unlock(locks,head2);
    241236            }else{
    242237                engine.update(head2, null, nodeSerializer);
     
    328323        }
    329324
    330 
    331         @Override
    332         public boolean isEmpty() {
    333             return head.get() == 0;
    334         }
    335 
     325        @Override
    336326        public boolean add(E item){
    337327            final long nextTail = engine.put((Node<E>)Node.EMPTY, nodeSerializer);
     
    347337        }
    348338
     339        @Override
    349340        public E poll(){
    350341            while(true){
     
    472463
    473464        @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
    474478        public E poll() {
    475479            lock.lock();
     
    569573    }
    570574
    571 
    572575}
Note: See TracChangeset for help on using the changeset viewer.