Skip to content

Commit

Permalink
Merge pull request eesast#371 from asdawej/patch
Browse files Browse the repository at this point in the history
fix(Logger): 🐛 too many threads in `Logger` & ensure `AddMoneyNaturally`
  • Loading branch information
DreamEnderKing authored May 11, 2024
2 parents 5b56b9d + 68619aa commit 3b43b98
Showing 2 changed files with 10 additions and 11 deletions.
5 changes: 4 additions & 1 deletion logic/Gaming/ActionManager.cs
Original file line number Diff line number Diff line change
@@ -301,7 +301,10 @@ public bool AddMoneyNaturally(Base team)
(
() =>
{
Thread.Sleep(GameData.CheckInterval);
while (!gameMap.Timer.IsGaming)
{
Thread.Sleep(1);
}
new FrameRateTaskExecutor<int>
(
loopCondition: () => gameMap.Timer.IsGaming,
16 changes: 6 additions & 10 deletions logic/Preparation/Utility/Logger.cs
Original file line number Diff line number Diff line change
@@ -16,12 +16,9 @@ public class LogQueue

private readonly Queue<string> logInfoQueue = new();

public async Task Commit(string info)
public void Commit(string info)
{
await Task.Run(() =>
{
lock (queueLock) logInfoQueue.Enqueue(info);
});
lock (queueLock) logInfoQueue.Enqueue(info);
}

public static bool IsClosed { get; private set; } = false;
@@ -79,7 +76,6 @@ private LogQueue()
).Start();
})
{ IsBackground = true }.Start();
var t = new Thread(() => { });
}
}

@@ -97,7 +93,7 @@ public void ConsoleLog(string msg, bool Duplicate = true)
if (!Background)
Console.WriteLine(info);
if (Duplicate)
_ = LogQueue.Global.Commit(info);
LogQueue.Global.Commit(info);
}
}
public void ConsoleLogDebug(string msg, bool Duplicate = true)
@@ -109,22 +105,22 @@ public void ConsoleLogDebug(string msg, bool Duplicate = true)
if (!Background)
Console.WriteLine(info);
if (Duplicate)
_ = LogQueue.Global.Commit(info);
LogQueue.Global.Commit(info);
}
#endif
}
public static void RawConsoleLog(string msg, bool Duplicate = true)
{
Console.WriteLine(msg);
if (Duplicate)
_ = LogQueue.Global.Commit(msg);
LogQueue.Global.Commit(msg);
}
public static void RawConsoleLogDebug(string msg, bool Duplicate = true)
{
#if DEBUG
Console.WriteLine(msg);
if (Duplicate)
_ = LogQueue.Global.Commit(msg);
LogQueue.Global.Commit(msg);
#endif
}

0 comments on commit 3b43b98

Please sign in to comment.