From 66c35d0a87d7b3e31ffcebc666677c3f777c0cb0 Mon Sep 17 00:00:00 2001 From: EvilBeaver Date: Fri, 15 Sep 2023 22:08:25 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D1=84=D0=B8=D0=BA=D1=81=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=B7=D0=B0=D0=BA=D1=80=D1=8B=D1=82=D0=B8=D0=B5=20?= =?UTF-8?q?=D1=81=D0=B5=D1=80=D0=B2=D0=B5=D1=80=D0=B0=20=D0=BE=D1=82=D0=BB?= =?UTF-8?q?=D0=B0=D0=B4=D0=BA=D0=B8,=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2?= =?UTF-8?q?=D0=B8=D0=BB=20Dispose=20=D1=82=D0=B0=D0=BC,=20=D0=B3=D0=B4?= =?UTF-8?q?=D0=B5=20=D0=B5=D0=B3=D0=BE=20=D0=BD=D0=B5=20=D0=B1=D1=8B=D0=BB?= =?UTF-8?q?=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (cherry picked from commit d85fb5074acb1835157abdb00278ca2d272d1fb0) --- .../TcpServer/DefaultMessageServer.cs | 10 ++++++++++ src/OneScript.DebugServices/MachineWaitToken.cs | 16 +++++++++------- src/OneScript.DebugServices/ThreadManager.cs | 1 + src/ScriptEngine/ScriptingEngine.cs | 3 ++- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/OneScript.DebugProtocol/TcpServer/DefaultMessageServer.cs b/src/OneScript.DebugProtocol/TcpServer/DefaultMessageServer.cs index 022d44625..cfe81ab1b 100644 --- a/src/OneScript.DebugProtocol/TcpServer/DefaultMessageServer.cs +++ b/src/OneScript.DebugProtocol/TcpServer/DefaultMessageServer.cs @@ -21,6 +21,11 @@ public DefaultMessageServer(ICommunicationChannel protocolChannel) { _protocolChannel = protocolChannel; } + + /// + /// Имя, назначаемое потоку сервера. Полезно для отладки и диагностики. + /// + public string ServerThreadName { get; set; } public void Start() { @@ -85,6 +90,11 @@ private void RunCommandsLoop() }); _messageThread.IsBackground = true; + if (ServerThreadName != default) + { + _messageThread.Name = ServerThreadName; + } + _messageThread.Start(); } diff --git a/src/OneScript.DebugServices/MachineWaitToken.cs b/src/OneScript.DebugServices/MachineWaitToken.cs index 732fa143a..6b2e3bc80 100644 --- a/src/OneScript.DebugServices/MachineWaitToken.cs +++ b/src/OneScript.DebugServices/MachineWaitToken.cs @@ -5,20 +5,16 @@ This Source Code Form is subject to the terms of the at http://mozilla.org/MPL/2.0/. ----------------------------------------------------------*/ +using System; using System.Threading; using ScriptEngine.Machine; namespace OneScript.DebugServices { - public class MachineWaitToken + public class MachineWaitToken: IDisposable { - private ManualResetEventSlim _threadEvent; + private ManualResetEventSlim _threadEvent = new ManualResetEventSlim(); - public MachineWaitToken() - { - _threadEvent = new ManualResetEventSlim(); - } - public MachineInstance Machine { get; set; } public void Wait() => _threadEvent.Wait(); @@ -26,5 +22,11 @@ public MachineWaitToken() public void Set() => _threadEvent.Set(); public void Reset() => _threadEvent.Reset(); + + public void Dispose() + { + Machine.UnsetDebugMode(); + _threadEvent.Dispose(); + } } } \ No newline at end of file diff --git a/src/OneScript.DebugServices/ThreadManager.cs b/src/OneScript.DebugServices/ThreadManager.cs index 06033ed85..e19d28d0b 100644 --- a/src/OneScript.DebugServices/ThreadManager.cs +++ b/src/OneScript.DebugServices/ThreadManager.cs @@ -87,6 +87,7 @@ public void Dispose() foreach (var machineWaitToken in tokens) { machineWaitToken.Machine.MachineStopped -= Machine_MachineStopped; + machineWaitToken.Dispose(); } _machinesOnThreads.Clear(); diff --git a/src/ScriptEngine/ScriptingEngine.cs b/src/ScriptEngine/ScriptingEngine.cs index f627292e9..8a5bc73bb 100644 --- a/src/ScriptEngine/ScriptingEngine.cs +++ b/src/ScriptEngine/ScriptingEngine.cs @@ -1,4 +1,4 @@ -/*---------------------------------------------------------- +/*---------------------------------------------------------- This Source Code Form is subject to the terms of the Mozilla Public License, v.2.0. If a copy of the MPL was not distributed with this file, You can obtain one @@ -196,6 +196,7 @@ public void SetCodeStatisticsCollector(ICodeStatCollector collector) public void Dispose() { + DebugController?.Dispose(); AttachedScriptsFactory.SetInstance(null); }