Clean up some possible thread safety issues.

This commit is contained in:
ragnarok
2005-10-21 00:10:13 +00:00
committed by zzz
parent 8458e4e0af
commit 3816c79193
2 changed files with 8 additions and 6 deletions

View File

@ -511,7 +511,7 @@ public class PeerCoordinator implements PeerListener
{
// Unchoke some random other peer
unchokePeer();
synchronized(wantedPieces) {
// Don't count disconnected peers for the rarest-first calculations
for(Iterator iter = wantedPieces.iterator(); iter.hasNext(); ) {
Piece piece = (Piece)iter.next();
@ -519,6 +519,7 @@ public class PeerCoordinator implements PeerListener
}
}
}
}
if (listener != null)
listener.peerChange(this, peer);

View File

@ -2,6 +2,7 @@ package org.klomp.snark;
import java.util.Set;
import java.util.HashSet;
import java.util.Collections;
public class Piece implements Comparable {
@ -11,7 +12,7 @@ public class Piece implements Comparable {
public Piece(int id) {
this.id = id;
this.peers = new HashSet();
this.peers = Collections.synchronizedSet(new HashSet());
this.requested = false;
}