diff --git a/Projects/Server.Tests/Fixtures/ServerFixture.cs b/Projects/Server.Tests/Fixtures/ServerFixture.cs index c049212a0..2cbd5b5ce 100644 --- a/Projects/Server.Tests/Fixtures/ServerFixture.cs +++ b/Projects/Server.Tests/Fixtures/ServerFixture.cs @@ -30,6 +30,8 @@ internal class ServerFixture : IDisposable // Load the world World.Load(); + + World.ExitSerializationThreads(); } public void Dispose() diff --git a/Projects/Server/Main.cs b/Projects/Server/Main.cs index d167da164..a39a93814 100644 --- a/Projects/Server/Main.cs +++ b/Projects/Server/Main.cs @@ -398,6 +398,8 @@ public static class Core World.WaitForWriteCompletion(); + World.ExitSerializationThreads(); + if (!_crashed) { EventSink.InvokeShutdown(); @@ -587,7 +589,7 @@ public static class Core } finally { - World.SleepSerializationThreads(); + World.ExitSerializationThreads(); } } diff --git a/Projects/Server/World/World.cs b/Projects/Server/World/World.cs index dc3ab9988..0309bfcc1 100644 --- a/Projects/Server/World/World.cs +++ b/Projects/Server/World/World.cs @@ -383,11 +383,11 @@ public static class World } } - internal static void SleepSerializationThreads() + public static void ExitSerializationThreads() { for (var i = 0; i < _threadWorkers.Length; i++) { - _threadWorkers[i].Sleep(); + _threadWorkers[i].Exit(); } } @@ -524,6 +524,7 @@ public static class World private readonly AutoResetEvent _startEvent; // Main thread tells the thread to start working private readonly AutoResetEvent _stopEvent; // Main thread waits for the worker finish draining private bool _pause; + private bool _exit; private readonly ConcurrentQueue _entities; public SerializationThreadWorker() @@ -546,6 +547,13 @@ public static class World _stopEvent.WaitOne(); } + public void Exit() + { + _exit = true; + Wake(); + Sleep(); + } + public void Push(IGenericSerializable entity) { _entities.Enqueue(entity); @@ -576,7 +584,7 @@ public static class World worker._stopEvent.Set(); // Allow the main thread to continue now that we are finished worker._pause = false; - if (Core.Closing) + if (Core.Closing || worker._exit) { return; } diff --git a/Projects/UOContent.Tests/Fixtures/ServerFixture.cs b/Projects/UOContent.Tests/Fixtures/ServerFixture.cs index 574bbb5a4..351e7555b 100644 --- a/Projects/UOContent.Tests/Fixtures/ServerFixture.cs +++ b/Projects/UOContent.Tests/Fixtures/ServerFixture.cs @@ -37,6 +37,8 @@ namespace Server.Tests // Load the world World.Load(); + + World.ExitSerializationThreads(); } public void Dispose()