Ignore:
Timestamp:
2013-04-07T17:07:27+02:00 (12 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/CacheWeakSoftRef.java

    r29363 r29484  
    2020import java.lang.ref.SoftReference;
    2121import java.lang.ref.WeakReference;
     22import java.util.concurrent.locks.ReentrantLock;
    2223
    2324/**
     
    3031
    3132
    32     protected final Locks.RecidLocks locks = new Locks.LongHashMapRecidLocks();
     33    protected final ReentrantLock[] locks = Utils.newLocks(32);
    3334
    3435    protected interface CacheItem{
     
    130131
    131132        try{
    132             locks.lock(recid);
     133            Utils.lock(locks,recid);
    133134            Object value = getWrappedEngine().get(recid, serializer);
    134135            if(value!=null) putItemIntoCache(recid, value);
     
    136137            return (A) value;
    137138        }finally{
    138             locks.unlock(recid);
     139            Utils.unlock(locks,recid);
    139140        }
    140141
     
    144145    public <A> void update(long recid, A value, Serializer<A> serializer) {
    145146        try{
    146             locks.lock(recid);
     147            Utils.lock(locks,recid);
    147148            putItemIntoCache(recid, value);
    148149            getWrappedEngine().update(recid, value, serializer);
    149150        }finally {
    150             locks.unlock(recid);
     151            Utils.unlock(locks,recid);
    151152        }
    152153    }
     
    163164    public <A> void delete(long recid, Serializer<A> serializer){
    164165        try{
    165             locks.lock(recid);
     166            Utils.lock(locks,recid);
    166167            checkClosed(items).remove(recid);
    167168            getWrappedEngine().delete(recid,serializer);
    168169        }finally {
    169             locks.unlock(recid);
     170            Utils.unlock(locks,recid);
    170171        }
    171172
     
    175176    public <A> boolean compareAndSwap(long recid, A expectedOldValue, A newValue, Serializer<A> serializer) {
    176177        try{
    177             locks.lock(recid);
     178            Utils.lock(locks,recid);
    178179            CacheItem item = checkClosed(items).get(recid);
    179180            Object oldValue = item==null? null: item.get() ;
     
    190191            }
    191192        }finally {
    192             locks.unlock(recid);
     193            Utils.unlock(locks,recid);
    193194        }
    194195    }
Note: See TracChangeset for help on using the changeset viewer.