3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-02-07 06:44:16 +00:00

Fix lock inversion.

This commit is contained in:
Mike Hearn 2012-12-24 23:33:13 +00:00
parent b71015a297
commit eb7c4be136

View File

@ -1098,17 +1098,19 @@ public class PeerGroup extends AbstractIdleService {
} }
/** Given a list of Peers, return a Peer to be used as the download peer. */ /** Given a list of Peers, return a Peer to be used as the download peer. */
protected Peer selectDownloadPeer(List<Peer> peers) { protected Peer selectDownloadPeer(List<Peer> origPeers) {
synchronized (peers) { List<Peer> peers;
if (peers.isEmpty()) synchronized (origPeers) {
return null; peers = new ArrayList<Peer>(origPeers);
// Make sure we don't select a peer that is behind/synchronizing itself.
int mostCommonChainHeight = getMostCommonChainHeight();
for (Peer peer : peers) {
if (peer.getBestHeight() == mostCommonChainHeight) return peer;
}
throw new IllegalStateException("Unreachable");
} }
if (peers.isEmpty())
return null;
// Make sure we don't select a peer that is behind/synchronizing itself.
int mostCommonChainHeight = getMostCommonChainHeight();
for (Peer peer : peers) {
if (peer.getBestHeight() == mostCommonChainHeight) return peer;
}
throw new IllegalStateException("Unreachable");
} }
private static class PeerGroupThreadFactory implements ThreadFactory { private static class PeerGroupThreadFactory implements ThreadFactory {