Changed various locking mechanism.

This commit is contained in:
Tom
2025-03-29 20:18:09 +00:00
parent c80f1f2aa0
commit c7904f120d
10 changed files with 282 additions and 143 deletions

View File

@@ -46,13 +46,26 @@ namespace HermesSocketServer.Store.Internal
private async Task GenerateQuery(IList<K> keys, Func<int, string> generate, Func<string, IEnumerable<K>, IEnumerable<V>, Task<int>> execute)
{
ImmutableList<K>? list = null;
lock (_lock)
_rwls.EnterUpgradeableReadLock();
try
{
if (!keys.Any())
return;
list = keys.ToImmutableList();
keys.Clear();
_rwls.EnterWriteLock();
try
{
list = keys.ToImmutableList();
keys.Clear();
}
finally
{
_rwls.ExitWriteLock();
}
}
finally
{
_rwls.ExitUpgradeableReadLock();
}
var query = generate(list.Count);