Skip to content

Commit

Permalink
Пофиксил закрытие сервера отладки, добавил Dispose там, где его не было
Browse files Browse the repository at this point in the history
(cherry picked from commit d85fb50)
  • Loading branch information
EvilBeaver committed Sep 15, 2023
1 parent fcb9dd5 commit 66c35d0
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
10 changes: 10 additions & 0 deletions src/OneScript.DebugProtocol/TcpServer/DefaultMessageServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ public DefaultMessageServer(ICommunicationChannel protocolChannel)
{
_protocolChannel = protocolChannel;
}

/// <summary>
/// Имя, назначаемое потоку сервера. Полезно для отладки и диагностики.
/// </summary>
public string ServerThreadName { get; set; }

public void Start()
{
Expand Down Expand Up @@ -85,6 +90,11 @@ private void RunCommandsLoop()
});

_messageThread.IsBackground = true;
if (ServerThreadName != default)
{
_messageThread.Name = ServerThreadName;
}

_messageThread.Start();
}

Expand Down
16 changes: 9 additions & 7 deletions src/OneScript.DebugServices/MachineWaitToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,28 @@ 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();

public void Set() => _threadEvent.Set();

public void Reset() => _threadEvent.Reset();

public void Dispose()
{
Machine.UnsetDebugMode();
_threadEvent.Dispose();
}
}
}
1 change: 1 addition & 0 deletions src/OneScript.DebugServices/ThreadManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public void Dispose()
foreach (var machineWaitToken in tokens)
{
machineWaitToken.Machine.MachineStopped -= Machine_MachineStopped;
machineWaitToken.Dispose();
}

_machinesOnThreads.Clear();
Expand Down
3 changes: 2 additions & 1 deletion src/ScriptEngine/ScriptingEngine.cs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -196,6 +196,7 @@ public void SetCodeStatisticsCollector(ICodeStatCollector collector)

public void Dispose()
{
DebugController?.Dispose();
AttachedScriptsFactory.SetInstance(null);
}

Expand Down

0 comments on commit 66c35d0

Please sign in to comment.