refactor: replace Mutex with SemaphoreSlim
Mutex uses system mutexes and SemaphoreSlim does not.
This commit is contained in:
parent
e01bb199c2
commit
070a99f612
|
@ -176,7 +176,7 @@ internal class Tab {
|
|||
public uint Unread;
|
||||
|
||||
[NonSerialized]
|
||||
public Mutex MessagesMutex = new();
|
||||
public SemaphoreSlim MessagesMutex = new(1, 1);
|
||||
|
||||
[NonSerialized]
|
||||
public List<Message> Messages = new();
|
||||
|
@ -195,13 +195,13 @@ internal class Tab {
|
|||
}
|
||||
|
||||
internal void AddMessage(Message message, bool unread = true) {
|
||||
this.MessagesMutex.WaitOne();
|
||||
this.MessagesMutex.Wait();
|
||||
this.Messages.Add(message);
|
||||
while (this.Messages.Count > Store.MessagesLimit) {
|
||||
this.Messages.RemoveAt(0);
|
||||
}
|
||||
|
||||
this.MessagesMutex.ReleaseMutex();
|
||||
this.MessagesMutex.Release();
|
||||
|
||||
if (unread) {
|
||||
this.Unread += 1;
|
||||
|
@ -209,9 +209,9 @@ internal class Tab {
|
|||
}
|
||||
|
||||
internal void Clear() {
|
||||
this.MessagesMutex.WaitOne();
|
||||
this.MessagesMutex.Wait();
|
||||
this.Messages.Clear();
|
||||
this.MessagesMutex.ReleaseMutex();
|
||||
this.MessagesMutex.Release();
|
||||
}
|
||||
|
||||
internal Tab Clone() {
|
||||
|
|
|
@ -707,7 +707,7 @@ internal sealed class ChatLog : IUiComponent {
|
|||
}
|
||||
|
||||
try {
|
||||
tab.MessagesMutex.WaitOne();
|
||||
tab.MessagesMutex.Wait();
|
||||
|
||||
var reset = false;
|
||||
if (this._lastResize.IsRunning && this._lastResize.Elapsed.TotalSeconds > 0.25) {
|
||||
|
@ -841,7 +841,7 @@ internal sealed class ChatLog : IUiComponent {
|
|||
lastPos = ImGui.GetCursorPosY();
|
||||
}
|
||||
} finally {
|
||||
tab.MessagesMutex.ReleaseMutex();
|
||||
tab.MessagesMutex.Release();
|
||||
ImGui.PopStyleVar(this.Ui.Plugin.Config.PrettierTimestamps && this.Ui.Plugin.Config.MoreCompactPretty ? 2 : 1);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue