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

    r29363 r29484  
    11package org.mapdb;
     2
     3import java.util.concurrent.locks.ReentrantLock;
    24
    35/**
     
    1012    protected LongMap<Object> cache;
    1113
    12     protected final Locks.RecidLocks locks = new Locks.SegmentedRecidLocks(16);
     14    protected final ReentrantLock[] locks = Utils.newLocks(32);
    1315
    1416
     
    2628        long recid =  super.put(value, serializer);
    2729        try{
    28             locks.lock(recid);
     30            Utils.lock(locks,recid);
    2931            checkClosed(cache).put(recid, value);
    3032        }finally {
    31             locks.unlock(recid);
     33            Utils.unlock(locks,recid);
    3234        }
    3335        return recid;
     
    4042        if(ret!=null) return (A) ret;
    4143        try{
    42             locks.lock(recid);
     44            Utils.lock(locks,recid);
    4345            ret = super.get(recid, serializer);
    4446            if(ret!=null) checkClosed(cache).put(recid, ret);
    4547            return (A) ret;
    4648        }finally {
    47             locks.unlock(recid);
     49            Utils.unlock(locks,recid);
    4850        }
    4951    }
     
    5254    public <A> void update(long recid, A value, Serializer<A> serializer) {
    5355        try{
    54             locks.lock(recid);
     56            Utils.lock(locks,recid);
    5557            checkClosed(cache).put(recid, value);
    5658            super.update(recid, value, serializer);
    5759        }finally {
    58             locks.unlock(recid);
     60            Utils.unlock(locks,recid);
    5961        }
    6062    }
     
    6365    public <A> void delete(long recid, Serializer<A> serializer){
    6466        try{
    65             locks.lock(recid);
     67            Utils.lock(locks,recid);
    6668            checkClosed(cache).remove(recid);
    6769            super.delete(recid,serializer);
    6870        }finally {
    69             locks.unlock(recid);
     71            Utils.unlock(locks,recid);
    7072        }
    7173    }
     
    7476    public <A> boolean compareAndSwap(long recid, A expectedOldValue, A newValue, Serializer<A> serializer) {
    7577        try{
    76             locks.lock(recid);
     78            Utils.lock(locks,recid);
    7779            Engine engine = getWrappedEngine();
    7880            LongMap cache2 = checkClosed(cache);
     
    8991            }
    9092        }finally {
    91             locks.unlock(recid);
     93            Utils.unlock(locks,recid);
    9294        }
    9395    }
Note: See TracChangeset for help on using the changeset viewer.