Browse Source

Remove locks from Scripting Console.

pull/1/head
mrward 15 years ago
parent
commit
ea5788a811
  1. 2
      src/AddIns/BackendBindings/Scripting/Project/ICSharpCode.Scripting.csproj
  2. 12
      src/AddIns/BackendBindings/Scripting/Project/Src/ILock.cs
  3. 39
      src/AddIns/BackendBindings/Scripting/Project/Src/ScriptingConsole.cs
  4. 35
      src/AddIns/BackendBindings/Scripting/Project/Src/StringListLock.cs
  5. 39
      src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleSendLineTests.cs
  6. 1
      src/AddIns/BackendBindings/Scripting/Test/ICSharpCode.Scripting.Tests.csproj
  7. 29
      src/AddIns/BackendBindings/Scripting/Test/Utils/FakeLock.cs
  8. 9
      src/AddIns/BackendBindings/Scripting/Test/Utils/TestableScriptingConsole.cs

2
src/AddIns/BackendBindings/Scripting/Project/ICSharpCode.Scripting.csproj

@ -69,7 +69,6 @@ @@ -69,7 +69,6 @@
<Compile Include="Src\IComponentCreator.cs" />
<Compile Include="Src\IComponentWalker.cs" />
<Compile Include="Src\IControlDispatcher.cs" />
<Compile Include="Src\ILock.cs" />
<Compile Include="Src\IMemberProvider.cs" />
<Compile Include="Src\IScriptingCodeDomSerializer.cs" />
<Compile Include="Src\IScriptingConsole.cs" />
@ -97,7 +96,6 @@ @@ -97,7 +96,6 @@
<Compile Include="Src\SendLineToScriptingConsoleCommand.cs" />
<Compile Include="Src\SendSelectedTextToScriptingConsoleCommand.cs" />
<Compile Include="Src\SendToScriptingConsoleCommand.cs" />
<Compile Include="Src\StringListLock.cs" />
<Compile Include="Src\ThreadSafeScriptingConsole.cs" />
<Compile Include="Src\ThreadSafeScriptingConsoleEvents.cs" />
</ItemGroup>

12
src/AddIns/BackendBindings/Scripting/Project/Src/ILock.cs

@ -1,12 +0,0 @@ @@ -1,12 +0,0 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
namespace ICSharpCode.Scripting
{
public interface ILock : IDisposable
{
}
}

39
src/AddIns/BackendBindings/Scripting/Project/Src/ScriptingConsole.cs

@ -37,7 +37,7 @@ namespace ICSharpCode.Scripting @@ -37,7 +37,7 @@ namespace ICSharpCode.Scripting
/// <summary>
/// Returns the next line typed in by the console user. If no line is available this method
/// will block.
/// will return null.
/// </summary>
public string ReadLine(int autoIndentSize)
{
@ -102,9 +102,7 @@ namespace ICSharpCode.Scripting @@ -102,9 +102,7 @@ namespace ICSharpCode.Scripting
/// </summary>
public bool IsLineAvailable {
get {
lock (unreadLines) {
return (unreadLines.Count > 0);
}
return (unreadLines.Count > 0);
}
}
@ -125,12 +123,10 @@ namespace ICSharpCode.Scripting @@ -125,12 +123,10 @@ namespace ICSharpCode.Scripting
string ReadLineFromTextEditor()
{
lock (unreadLines) {
if (IsLineAvailable) {
string line = unreadLines[0];
unreadLines.RemoveAt(0);
return line;
}
if (IsLineAvailable) {
string line = unreadLines[0];
unreadLines.RemoveAt(0);
return line;
}
return null;
}
@ -188,12 +184,10 @@ namespace ICSharpCode.Scripting @@ -188,12 +184,10 @@ namespace ICSharpCode.Scripting
void OnEnterKeyPressed()
{
using (ILock linesLock = CreateLock(unreadLines)) {
MoveCursorToEndOfLastTextEditorLine();
SaveLastTextEditorLine();
FireLineReceivedEvent();
}
MoveCursorToEndOfLastTextEditorLine();
SaveLastTextEditorLine();
FireLineReceivedEvent();
}
protected virtual void OnLineReceived()
@ -296,19 +290,12 @@ namespace ICSharpCode.Scripting @@ -296,19 +290,12 @@ namespace ICSharpCode.Scripting
public void SendLine(string line)
{
using (ILock linesLock = CreateLock(unreadLines)) {
unreadLines.Add(line);
}
unreadLines.Add(line);
FireLineReceivedEvent();
MoveCursorToEndOfLastTextEditorLine();
WriteTextIfFirstPromptHasBeenDisplayed(line + "\r\n");
}
protected virtual ILock CreateLock(List<string> lines)
{
return new StringListLock(lines);
}
protected virtual void FireLineReceivedEvent()
{
OnLineReceived();
@ -345,9 +332,7 @@ namespace ICSharpCode.Scripting @@ -345,9 +332,7 @@ namespace ICSharpCode.Scripting
string firstLine = GetFirstLineOfText(lines);
if (lines.Count > 1) {
using (ILock linesLock = CreateLock(unreadLines)) {
AddAllLinesButLastToUnreadLines(lines);
}
AddAllLinesButLastToUnreadLines(lines);
FireLineReceivedEvent();
}
lines.RemoveAt(0);

35
src/AddIns/BackendBindings/Scripting/Project/Src/StringListLock.cs

@ -1,35 +0,0 @@ @@ -1,35 +0,0 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
using System.Threading;
namespace ICSharpCode.Scripting
{
public class StringListLock : ILock
{
List<string> lines;
public StringListLock(List<string> lines)
{
this.lines = lines;
Lock();
}
void Lock()
{
Monitor.Enter(lines);
}
public void Dispose()
{
Unlock();
}
void Unlock()
{
Monitor.Exit(lines);
}
}
}

39
src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleSendLineTests.cs

@ -31,45 +31,6 @@ namespace ICSharpCode.Scripting.Tests.Console @@ -31,45 +31,6 @@ namespace ICSharpCode.Scripting.Tests.Console
TestableScriptingConsole.SendLine(text);
}
[Test]
public void SendLine_NoUnreadLines_CreatesLockForPreviousLines()
{
SendLineToConsole("test");
List<string> lines = TestableScriptingConsole.LockCreated.Lines;
List<string> expectedLines = TestableScriptingConsole.GetUnreadLinesList();
Assert.AreEqual(expectedLines, lines);
}
[Test]
public void SendLine_NoUnreadLines_LockForPreviousLinesIsDisposed()
{
SendLineToConsole("test");
bool disposed = TestableScriptingConsole.LockCreated.IsDisposed;
Assert.IsTrue(disposed);
}
[Test]
public void SendLine_NoUnreadLines_LineNotAddedBeforeLockCreated()
{
SendLineToConsole("test");
int count = TestableScriptingConsole.LockCreated.UnreadLineCountWhenLockCreated;
int expectedCount = 0;
Assert.AreEqual(expectedCount, count);
}
[Test]
public void SendLine_NoUnreadLines_LineAddedBeforeLockDisposed()
{
SendLineToConsole("test");
int count = TestableScriptingConsole.LockCreated.UnreadLineCountWhenLockDisposed;
int expectedCount = 1;
Assert.AreEqual(expectedCount, count);
}
[Test]
public void SendLine_NoUnreadLines_LineReceivedEventIsFired()
{

1
src/AddIns/BackendBindings/Scripting/Test/ICSharpCode.Scripting.Tests.csproj

@ -124,7 +124,6 @@ @@ -124,7 +124,6 @@
<Compile Include="Utils\FakeDesignerSerializationManager.cs" />
<Compile Include="Utils\FakeDocument.cs" />
<Compile Include="Utils\FakeDocumentLine.cs" />
<Compile Include="Utils\FakeLock.cs" />
<Compile Include="Utils\FakeScriptingConsole.cs" />
<Compile Include="Utils\FooItemCollection.cs" />
<Compile Include="Utils\MockComponentCreator.cs" />

29
src/AddIns/BackendBindings/Scripting/Test/Utils/FakeLock.cs

@ -1,29 +0,0 @@ @@ -1,29 +0,0 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
using ICSharpCode.Scripting;
namespace ICSharpCode.Scripting.Tests.Utils
{
public class FakeLock : ILock
{
public List<string> Lines;
public bool IsDisposed;
public int UnreadLineCountWhenLockCreated = -1;
public int UnreadLineCountWhenLockDisposed = -1;
public FakeLock(List<string> lines)
{
this.Lines = lines;
UnreadLineCountWhenLockCreated = lines.Count;
}
public void Dispose()
{
UnreadLineCountWhenLockDisposed = Lines.Count;
IsDisposed = true;
}
}
}

9
src/AddIns/BackendBindings/Scripting/Test/Utils/TestableScriptingConsole.cs

@ -11,7 +11,6 @@ namespace ICSharpCode.Scripting.Tests.Utils @@ -11,7 +11,6 @@ namespace ICSharpCode.Scripting.Tests.Utils
public class TestableScriptingConsole : ScriptingConsole
{
public FakeConsoleTextEditor FakeConsoleTextEditor;
public FakeLock LockCreated;
public bool IsLineReceivedEventFired;
public int UnreadLineCountWhenLineReceivedEventFired = -1;
@ -37,16 +36,10 @@ namespace ICSharpCode.Scripting.Tests.Utils @@ -37,16 +36,10 @@ namespace ICSharpCode.Scripting.Tests.Utils
return base.unreadLines.ToArray();
}
protected override ILock CreateLock(List<string> lines)
{
LockCreated = new FakeLock(lines);
return LockCreated;
}
protected override void FireLineReceivedEvent()
{
IsLineReceivedEventFired = true;
UnreadLineCountWhenLineReceivedEventFired = LockCreated.Lines.Count;
UnreadLineCountWhenLineReceivedEventFired = base.unreadLines.Count;
}
public void CallBaseFireLineReceivedEvent()

Loading…
Cancel
Save