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/CacheHashTable.java

    r29363 r29484  
    1717package org.mapdb;
    1818
     19import java.util.concurrent.locks.ReentrantLock;
     20
    1921/**
    2022 * Fixed size cache which uses hash table.
     
    2931
    3032
    31     protected final Locks.RecidLocks locks = new Locks.SegmentedRecidLocks(16);
     33    protected final ReentrantLock[] locks = Utils.newLocks(32);
    3234
    3335    protected HashItem[] items;
     
    6365        final int pos = position(recid);
    6466        try{
    65             locks.lock(pos);
     67            Utils.lock(locks,pos);
    6668            checkClosed(items)[position(recid)] = new HashItem(recid, value);
    6769        }finally{
    68             locks.unlock(pos);
     70            Utils.unlock(locks,pos);
    6971        }
    7072        return recid;
     
    8183
    8284        try{
    83             locks.lock(pos);
     85            Utils.lock(locks,pos);
    8486            //not in cache, fetch and add
    8587            final A value = getWrappedEngine().get(recid, serializer);
     
    8890            return value;
    8991        }finally{
    90             locks.unlock(pos);
     92            Utils.unlock(locks,pos);
    9193        }
    9294    }
     
    100102        final int pos = position(recid);
    101103        try{
    102             locks.lock(pos);
     104            Utils.lock(locks,pos);
    103105            checkClosed(items)[pos] = new HashItem(recid, value);
    104106            getWrappedEngine().update(recid, value, serializer);
    105107        }finally {
    106             locks.unlock(pos);
     108            Utils.unlock(locks,pos);
    107109        }
    108110    }
     
    113115        try{
    114116            HashItem[] items2 = checkClosed(items);
    115             locks.lock(pos);
     117            Utils.lock(locks,pos);
    116118            HashItem item = items2[pos];
    117119            if(item!=null && item.key == recid){
     
    131133            }
    132134        }finally {
    133             locks.unlock(pos);
     135            Utils.unlock(locks,pos);
    134136        }
    135137    }
     
    139141        final int pos = position(recid);
    140142        try{
    141             locks.lock(recid);
     143            Utils.lock(locks,pos);
    142144            getWrappedEngine().delete(recid,serializer);
    143145            HashItem[] items2 = checkClosed(items);
     
    146148            items[pos] = null;
    147149        }finally {
    148             locks.unlock(recid);
     150            Utils.unlock(locks,pos);
    149151        }
    150152
Note: See TracChangeset for help on using the changeset viewer.