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

@@ -14,7 +14,7 @@ namespace HermesSocketServer.Socket.Handlers
private readonly HashSet<string> _emotes;
private readonly string[] _array;
private readonly ILogger _logger;
private readonly object _lock;
private readonly Mutex _mutex;
private int _index;
@@ -24,7 +24,7 @@ namespace HermesSocketServer.Socket.Handlers
_emotes = new HashSet<string>(EMOTE_BUFFER_SIZE);
_array = new string[EMOTE_BUFFER_SIZE];
_logger = logger;
_lock = new object();
_mutex = new Mutex();
_index = -1;
}
@@ -36,8 +36,9 @@ namespace HermesSocketServer.Socket.Handlers
if (data.Emotes == null || !data.Emotes.Any())
return;
lock (_lock)
try
{
_mutex.WaitOne();
foreach (var entry in data.Emotes)
{
if (_emotes.Contains(entry.Key))
@@ -59,6 +60,10 @@ namespace HermesSocketServer.Socket.Handlers
_array[_index] = entry.Key;
}
}
finally
{
_mutex.ReleaseMutex();
}
if (!data.Emotes.Any())
return;