From 706a2ade11d0e3eedd3afa7b1cbca5001b1b9287 Mon Sep 17 00:00:00 2001 From: Eric Petit Date: Mon, 29 Jan 2007 12:16:56 +0000 Subject: [PATCH] Ugly workaround for the deadlock introduced in [1445] --- libtransmission/peer.c | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/libtransmission/peer.c b/libtransmission/peer.c index dde73e049..bdc685c04 100644 --- a/libtransmission/peer.c +++ b/libtransmission/peer.c @@ -209,10 +209,22 @@ int tr_peerRead( tr_peer_t * peer ) /* Try to read */ for( ;; ) { - if( tor && ( ( !tor->customSpeedLimit && !tr_rcCanGlobalTransfer( tor->handle, 0 ) ) - || ( tor->customSpeedLimit && !tr_rcCanTransfer( tor->download ) ) ) ) + if( tor ) { - break; + if( !tor->customSpeedLimit ) + { + tr_lockUnlock( &tor->lock ); + if( !tr_rcCanGlobalTransfer( tor->handle, 0 ) ) + { + tr_lockLock( &tor->lock ); + break; + } + tr_lockLock( &tor->lock ); + } + else if( !tr_rcCanTransfer( tor->download ) ) + { + break; + } } if( peer->size < 1 ) @@ -386,8 +398,17 @@ writeBegin: /* Send pieces if we can */ while( ( p = blockPending( tor, peer, &size ) ) ) { - if( ( !tor->customSpeedLimit && !tr_rcCanGlobalTransfer( tor->handle, 1 ) ) - || ( tor->customSpeedLimit && !tr_rcCanTransfer( tor->upload ) ) ) + if( !tor->customSpeedLimit ) + { + tr_lockUnlock( &tor->lock ); + if( !tr_rcCanGlobalTransfer( tor->handle, 1 ) ) + { + tr_lockLock( &tor->lock ); + break; + } + tr_lockLock( &tor->lock ); + } + else if( !tr_rcCanTransfer( tor->upload ) ) { break; }