Skip to content
This repository was archived by the owner on Nov 3, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/framework/GuiUnit/TestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ public static IMainLoopIntegration MainLoop {
try { mainLoop = mainLoop ?? new XwtMainLoopIntegration (); } catch { }
try { mainLoop = mainLoop ?? new MonoMacMainLoopIntegration (); } catch { }
try { mainLoop = mainLoop ?? new GtkMainLoopIntegration (); } catch { }
mainLoop = mainLoop ?? new ConsoleMainLoop ();
return mainLoop;
} set {
mainLoop = value;
Expand Down
117 changes: 0 additions & 117 deletions src/framework/GuiUnit/XwtMainLoopIntegration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,122 +76,5 @@ public void Shutdown (int exitCode)
Application.GetMethod("Exit").Invoke(null, null);
}
}

class ConsoleMainLoop : System.Threading.SynchronizationContext, IMainLoopIntegration
{
System.Collections.Generic.Queue<InvokerHelper> work =
new System.Collections.Generic.Queue<InvokerHelper>();

System.Collections.Generic.Queue<Tuple<System.Threading.SendOrPostCallback, object>> contextWork =
new System.Collections.Generic.Queue<Tuple<System.Threading.SendOrPostCallback, object>>();

bool endLoop;

public void InitializeToolkit()
{
var runtime = Type.GetType("MonoDevelop.Core.Runtime, MonoDevelop.Core");
if (runtime == null)
return;

var property = runtime.GetProperty ("MainSynchronizationContext", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static);
if (property == null)
return;

System.Threading.SynchronizationContext.SetSynchronizationContext(this);
property.SetValue (null, System.Threading.SynchronizationContext.Current);
}

public void InvokeOnMainLoop (InvokerHelper helper)
{
lock (work)
{
work.Enqueue (helper);
System.Threading.Monitor.Pulse (work);
}
}

public void RunMainLoop ()
{
do
{
InvokerHelper next = null;
Tuple<System.Threading.SendOrPostCallback, object> nextContext = null;
lock (work)
{
if (work.Count > 0 && !endLoop)
next = work.Dequeue ();
else if (contextWork.Count > 0 && !endLoop)
nextContext = contextWork.Dequeue ();
else if (!endLoop)
System.Threading.Monitor.Wait (work);
}
if (next != null)
{
try
{
next.Invoke ();
}
catch (Exception ex)
{
Console.WriteLine (ex);
}
}
if (nextContext != null)
{
try
{
nextContext.Item1(nextContext.Item2);
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
} while (!endLoop);
}

public void Shutdown ()
{
lock (work)
{
endLoop = true;
System.Threading.Monitor.Pulse (work);
}
}

public override void Post (System.Threading.SendOrPostCallback d, object state)
{
lock (work)
{
contextWork.Enqueue (new Tuple<System.Threading.SendOrPostCallback, object>(d, state));
System.Threading.Monitor.Pulse (work);
}
}

public override void Send (System.Threading.SendOrPostCallback d, object state)
{
var evt = new System.Threading.ManualResetEventSlim (false);
Exception exception = null;
Post (s =>
{
try
{
d.Invoke (state);
}
catch (Exception ex)
{
exception = ex;
}
finally
{
System.Threading.Thread.MemoryBarrier ();
evt.Set ();
}
}, null);
evt.Wait ();
if (exception != null)
throw exception;
}
}
}