Skip to content

Commit

Permalink
Remove unnecessary lock
Browse files Browse the repository at this point in the history
  • Loading branch information
limebell committed Feb 10, 2020
1 parent 96d96b5 commit c3867e1
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions Libplanet/Net/Swarm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public class Swarm<T> : IDisposable
private readonly int _appProtocolVersion;

private readonly AsyncLock _blockSyncMutex;
private readonly AsyncLock _txSyncMutex;
private readonly AsyncLock _runningMutex;

private readonly ILogger _logger;
Expand Down Expand Up @@ -112,7 +111,6 @@ internal Swarm(
BlockReceived = new AsyncAutoResetEvent();

_blockSyncMutex = new AsyncLock();
_txSyncMutex = new AsyncLock();
_runningMutex = new AsyncLock();

_appProtocolVersion = appProtocolVersion;
Expand Down Expand Up @@ -1481,9 +1479,7 @@ out IReadOnlyList<HashDigest<SHA256>> hashes

case TxIds txIds:
{
Task.Run(
async () => await ProcessTxIds(txIds, _cancellationToken),
_cancellationToken);
ProcessTxIds(txIds);
break;
}

Expand Down Expand Up @@ -1798,9 +1794,7 @@ private void TransferTxs(GetTxs getTxs)
}
}

private async Task ProcessTxIds(
TxIds message,
CancellationToken cancellationToken = default(CancellationToken))
private void ProcessTxIds(TxIds message)
{
if (!(message.Remote is BoundPeer peer))
{
Expand All @@ -1826,13 +1820,9 @@ private async Task ProcessTxIds(
}

_logger.Debug("Txs to require: [{txIds}]", string.Join(", ", newTxIds));

using (await _txSyncMutex.LockAsync(cancellationToken))
foreach (var txid in newTxIds)
{
foreach (var txid in newTxIds)
{
_demandTxIds.TryAdd(txid, peer);
}
_demandTxIds.TryAdd(txid, peer);
}
}

Expand Down

0 comments on commit c3867e1

Please sign in to comment.