Remove lock for linq queries
Queries do not modify state in any way and then there is no reason to
lock prevent concurrent access (read access).
MODIFY
WalletWasabi/WabiSabi/Backend/Banning/Prison.cs
WalletWasabi/WabiSabi/Backend/Banning/Prison.cs
@@ -30,12 +30,9 @@ namespace WalletWasabi.WabiSabi.Backend.Banning
public Guid ChangeId { get; private set; } = Guid.NewGuid();
public (int noted, int banned) CountInmates()
- {
- lock (Lock)
{
return (Inmates.Count(x => x.Value.Punishment == Punishment.Noted), Inmates.Count(x => x.Value.Punishment == Punishment.Banned));
}
- }
public void Note(Alice alice, Guid lastDisruptedRoundId)
{
@@ -70,13 +67,14 @@ namespace WalletWasabi.WabiSabi.Backend.Banning
}
public bool TryRelease(OutPoint utxo, [NotNullWhen(returnValue: true)] out Inmate? inmate)
- {
- lock (Lock)
{
if (Inmates.TryGetValue(utxo, out inmate))
+ {
+ lock (Lock)
{
Inmates.Remove(utxo);
ChangeId = Guid.NewGuid();
+ }
return true;
}
else
@@ -84,7 +82,6 @@ namespace WalletWasabi.WabiSabi.Backend.Banning
return false;
}
}
- }
public IEnumerable<Inmate> ReleaseEligibleInmates(TimeSpan time)
{
@@ -111,19 +108,13 @@ namespace WalletWasabi.WabiSabi.Backend.Banning
}
public bool TryGet(OutPoint utxo, [NotNullWhen(returnValue: true)] out Inmate? inmate)
- {
- lock (Lock)
{
return Inmates.TryGetValue(utxo, out inmate);
}
- }
public IEnumerable<Inmate> GetInmates()
- {
- lock (Lock)
{
return Inmates.Select(x => x.Value).ToList();
}
}
}
-}

Remove lock for linq queries

Queries do not modify state in any way and then there is no reason to
lock prevent concurrent access (read access).