Changed various locking mechanism.
This commit is contained in:
@@ -14,7 +14,7 @@ namespace HermesSocketServer.Socket.Handlers
|
||||
private readonly long[] _array;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly object _lock;
|
||||
private readonly Mutex _lock;
|
||||
private int _index;
|
||||
|
||||
public ChatterHandler(Database database, ILogger logger)
|
||||
@@ -24,7 +24,7 @@ namespace HermesSocketServer.Socket.Handlers
|
||||
_chatters = new HashSet<long>(CHATTER_BUFFER_SIZE);
|
||||
_array = new long[CHATTER_BUFFER_SIZE];
|
||||
_index = -1;
|
||||
_lock = new object();
|
||||
_lock = new Mutex();
|
||||
}
|
||||
|
||||
public async Task Execute<T>(WebSocketUser sender, T message, HermesSocketManager sockets)
|
||||
@@ -32,8 +32,9 @@ namespace HermesSocketServer.Socket.Handlers
|
||||
if (message is not ChatterMessage data || sender.Id == null)
|
||||
return;
|
||||
|
||||
lock (_lock)
|
||||
try
|
||||
{
|
||||
_lock.WaitOne();
|
||||
if (_chatters.Contains(data.Id))
|
||||
return;
|
||||
|
||||
@@ -43,11 +44,16 @@ namespace HermesSocketServer.Socket.Handlers
|
||||
_index = -1;
|
||||
|
||||
var previous = _array[++_index];
|
||||
if (previous != 0) {
|
||||
if (previous != 0)
|
||||
{
|
||||
_chatters.Remove(previous);
|
||||
}
|
||||
_array[_index] = data.Id;
|
||||
}
|
||||
finally
|
||||
{
|
||||
_lock.ReleaseMutex();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user