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