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

@@ -13,7 +13,7 @@ namespace HermesSocketServer.Socket.Handlers
private readonly HashSet<string> _history;
private readonly EmoteUsageMessage[] _array;
private readonly ILogger _logger;
private readonly object _lock;
private readonly Mutex _mutex;
private int _index;
@@ -21,9 +21,9 @@ namespace HermesSocketServer.Socket.Handlers
{
_database = database;
_logger = logger;
_history = new HashSet<string>(101);
_array = new EmoteUsageMessage[100];
_lock = new object();
_history = new HashSet<string>(1001);
_array = new EmoteUsageMessage[1000];
_mutex = new Mutex();
_index = -1;
}
@@ -33,7 +33,7 @@ namespace HermesSocketServer.Socket.Handlers
if (message is not EmoteUsageMessage data || sender.Id == null)
return;
lock (_lock)
try
{
if (_history.Contains(data.MessageId))
{
@@ -50,6 +50,10 @@ namespace HermesSocketServer.Socket.Handlers
_array[_index] = data;
}
finally
{
_mutex.ReleaseMutex();
}
int rows = 0;
string sql = "INSERT INTO \"EmoteUsageHistory\" (timestamp, \"broadcasterId\", \"emoteId\", \"chatterId\") VALUES (@time, @broadcaster, @emote, @chatter)";