Skip to content
This repository was archived by the owner on Nov 3, 2023. It is now read-only.
Merged
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
42 changes: 26 additions & 16 deletions UiaDbus/UiaDbusSource/UiaDbusAutomationSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -702,36 +702,46 @@ private object DeserializeAutomationPropertyValue (string busName, int propId, o
private volatile static bool runMainLoop = false;
private Thread mainLoop = null;

private object mainLoopMethodsLock = new object ();

private void CheckMainLoop ()
{
if (mainLoopStarted)
return;
runMainLoop = true;
lock (mainLoopMethodsLock) {
if (mainLoopStarted)
return;
runMainLoop = true;

Log.Info ("UiaDbusAutomationSource: Starting dbus main loop");
mainLoop = new Thread (new ThreadStart (MainLoop));
mainLoop.IsBackground = true;
mainLoop.Start ();
mainLoopStarted = true;
Log.Info ("UiaDbusAutomationSource: Starting dbus main loop");
mainLoop = new Thread (new ThreadStart (MainLoop));
mainLoop.IsBackground = true;
mainLoop.Start ();
mainLoopStarted = true;
}
}

private void AbortMainLoop ()
{
runMainLoop = false;
if (mainLoop != null) {
Log.Info ("UiaDbusAutomationSource: Stopping dbus main loop");
mainLoop.Abort ();
lock (mainLoopMethodsLock) {
runMainLoop = false;
if (mainLoop != null) {
Log.Info ("UiaDbusAutomationSource: Stopping dbus main loop");
mainLoop.Abort ();
mainLoop = null;
}
mainLoopStarted = false;
}
mainLoopStarted = false;
mainLoop = null;
}

private void MainLoop ()
{
// TODO: Why does it not work if I uncomment this and
// do bus.Iterate (); ?
//Bus bus = Bus.Session;
while (runMainLoop) {
while (true) {
lock (mainLoopMethodsLock)
if (!runMainLoop)
break;

// TODO: Likely crash source (ndesk-dbus bugs?)
try {
Bus.Session.Iterate ();
Expand All @@ -741,7 +751,7 @@ private void MainLoop ()
"The ThreadAbortException has been catched in the Iterate(). Assume normal program exit.{0}{1}",
Environment.NewLine, ex.StackTrace);
} catch (Exception e) {
Log.Error ("UiaDbusSource: Exception in iterate: " + e);
Log.Error ("UiaDbusSource iterate error: " + e);
}
}
}
Expand Down