Changeset 3fc312a6


Ignore:
Timestamp:
Dec 5, 2011 12:59:58 AM (9 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
51899e9
Parents:
e9d0d79
Message:

locking tweaks

File:
1 edited

Legend:

Unmodified
Added
Removed
  • router/java/src/net/i2p/router/transport/FIFOBandwidthRefiller.java

    re9d0d79 r3fc312a6  
    44import java.util.List;
    55import java.util.concurrent.atomic.AtomicInteger;
     6import java.util.concurrent.locks.ReentrantReadWriteLock;
    67
    78import net.i2p.I2PAppContext;
     
    304305    /** the actual length of the period (nominally REPLENISH_FREQUENCY) */
    305306    private final long[] _times = new long[PERIODS];
     307    private final ReentrantReadWriteLock _updateLock = new ReentrantReadWriteLock(false);
    306308
    307309    /**
     
    321323     *  @since 0.8.12
    322324     */
    323     synchronized int getCurrentParticipatingBandwidth() {
     325    int getCurrentParticipatingBandwidth() {
     326        _updateLock.readLock().lock();
     327        try {
     328            return locked_getCurrentParticipatingBandwidth();
     329        } finally {
     330            _updateLock.readLock().unlock();
     331        }
     332    }
     333
     334    private int locked_getCurrentParticipatingBandwidth() {
    324335        int current = _currentParticipating.get();
    325336        long totalTime = (_limiter.now() - _lastPartUpdateTime) + _lastTotalTime;
     
    338349     *  @since 0.8.12
    339350     */
    340     private synchronized void updateParticipating(long now) {
     351    private void updateParticipating(long now) {
     352        _updateLock.writeLock().lock();
     353        try {
     354            locked_updateParticipating(now);
     355        } finally {
     356            _updateLock.writeLock().unlock();
     357        }
     358    }
     359
     360    private void locked_updateParticipating(long now) {
    341361        long elapsed = now - _lastPartUpdateTime;
    342362        if (elapsed <= 0) {
Note: See TracChangeset for help on using the changeset viewer.