Skip to content

Commit

Permalink
use a thread safe queue
Browse files Browse the repository at this point in the history
  • Loading branch information
Jnnshschl committed Nov 3, 2019
1 parent e17a58f commit 0ec3427
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions AmeisenNavigation.Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using AmeisenNavigationWrapper;
using Newtonsoft.Json;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
Expand All @@ -28,7 +29,7 @@ internal static class Program

private static Thread LoggingThread { get; set; }

private static Queue<LogEntry> LogQueue { get; set; }
private static ConcurrentQueue<LogEntry> LogQueue { get; set; }

private static Settings Settings { get; set; }

Expand All @@ -39,7 +40,7 @@ public static void Main()

PrintHeader();

LogQueue = new Queue<LogEntry>();
LogQueue = new ConcurrentQueue<LogEntry>();
Settings = LoadConfigFile();

SetupLogging();
Expand Down Expand Up @@ -133,7 +134,7 @@ public static List<Vector3> GetPath(Vector3 start, Vector3 end, int mapId, PathR
path = ChaikinCurve.Perform(path);
}

//path = NodeReduction.Perform(path);
//// bugged atm path = NodeReduction.Perform(path);

sw.Stop();
LogQueue.Enqueue(new LogEntry($"[{clientIp}] ", ConsoleColor.Green, $"Building Path with {path.Count} Nodes took {sw.ElapsedMilliseconds}ms ({sw.ElapsedTicks} ticks)", LogLevel.INFO));
Expand Down Expand Up @@ -222,9 +223,8 @@ public static void LoggingThreadRoutine()
{
while (!stopServer || LogQueue.Count > 0)
{
if (LogQueue.Count > 0)
if (LogQueue.TryDequeue(out LogEntry logEntry))
{
LogEntry logEntry = LogQueue.Dequeue();
if (logEntry.LogLevel >= Settings.LogLevel)
{
string logString = ColoredPrint(logEntry.ColoredPart, logEntry.Color, logEntry.UncoloredPart, logEntry.LogLevel);
Expand Down

0 comments on commit 0ec3427

Please sign in to comment.