forked from I2P_Developers/i2p.i2p
Clean up some possible thread safety issues.
This commit is contained in:
@ -511,11 +511,12 @@ public class PeerCoordinator implements PeerListener
|
|||||||
{
|
{
|
||||||
// Unchoke some random other peer
|
// Unchoke some random other peer
|
||||||
unchokePeer();
|
unchokePeer();
|
||||||
|
synchronized(wantedPieces) {
|
||||||
// Don't count disconnected peers for the rarest-first calculations
|
// Don't count disconnected peers for the rarest-first calculations
|
||||||
for(Iterator iter = wantedPieces.iterator(); iter.hasNext(); ) {
|
for(Iterator iter = wantedPieces.iterator(); iter.hasNext(); ) {
|
||||||
Piece piece = (Piece)iter.next();
|
Piece piece = (Piece)iter.next();
|
||||||
piece.removePeer(peer);
|
piece.removePeer(peer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package org.klomp.snark;
|
|||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
public class Piece implements Comparable {
|
public class Piece implements Comparable {
|
||||||
|
|
||||||
@ -11,7 +12,7 @@ public class Piece implements Comparable {
|
|||||||
|
|
||||||
public Piece(int id) {
|
public Piece(int id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.peers = new HashSet();
|
this.peers = Collections.synchronizedSet(new HashSet());
|
||||||
this.requested = false;
|
this.requested = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user