Change thread affinity of DS4Device objects

Drastically improves performance. Might be able to remove the
need for the separate input thread later.
This commit is contained in:
Travis Nickles 2017-08-26 04:25:42 -05:00
parent 150476d6aa
commit 6190ddff9b
2 changed files with 55 additions and 30 deletions

View File

@ -107,7 +107,7 @@ namespace DS4Windows
}
}
public bool Start(bool showlog = true)
public bool Start(object tempui, bool showlog = true)
{
if (x360Bus.Open() && x360Bus.Start())
{
@ -141,7 +141,7 @@ namespace DS4Windows
task.Start();
DS4Controllers[i] = device;
device.setUiContext(SynchronizationContext.Current);
device.setUiContext(tempui as SynchronizationContext);
device.Removal += this.On_DS4Removal;
device.Removal += DS4Devices.On_Removal;
device.SyncChange += this.On_SyncChange;

View File

@ -16,6 +16,7 @@ using Microsoft.Win32.TaskScheduler;
using System.Security.Principal;
using System.Threading;
using System.Drawing.Drawing2D;
using TaskRunner = System.Threading.Tasks.Task;
using static DS4Windows.Global;
namespace DS4Windows
@ -416,7 +417,7 @@ namespace DS4Windows
}
}
System.Threading.Tasks.Task.Run(() => { UpdateTheUpdater(); });
TaskRunner.Run(() => { UpdateTheUpdater(); });
this.StartWindowsCheckBox.CheckedChanged += new EventHandler(this.StartWindowsCheckBox_CheckedChanged);
new ToolTip().SetToolTip(StartWindowsCheckBox, Properties.Resources.RunAtStartup);
@ -465,14 +466,11 @@ namespace DS4Windows
private void blankControllerTab()
{
bool nocontrollers = true;
for (Int32 Index = 0, PadsLen = Pads.Length; Index < PadsLen; Index++)
for (int Index = 0, PadsLen = Pads.Length;
Index < PadsLen; Index++)
{
// Make sure a controller exists
if (Index < ControlService.DS4_CONTROLLER_COUNT)
{
Pads[Index].Text = "";
statPB[Index].Visible = false; toolTip1.SetToolTip(statPB[Index], "");
Batteries[Index].Text = Properties.Resources.NA;
Pads[Index].Text = Properties.Resources.Disconnected;
@ -480,8 +478,8 @@ namespace DS4Windows
}
}
lbNoControllers.Visible = nocontrollers;
tLPControllers.Visible = !nocontrollers;
lbNoControllers.Visible = true;
tLPControllers.Visible = false;
}
private void UpdateTheUpdater()
@ -946,11 +944,18 @@ namespace DS4Windows
btnStartStop_Clicked();
}
public void btnStartStop_Clicked(bool log = true)
private void serviceStartup(bool log)
{
if (btnStartStop.Text == Properties.Resources.StartText)
var uiContext = SynchronizationContext.Current;
TaskRunner.Run(() =>
{
Program.rootHub.Start(uiContext, log);
this.Invoke((System.Action)(() => { serviceStartupFinish(); }));
});
}
private void serviceStartupFinish()
{
Program.rootHub.Start(log);
if (SwipeProfiles && !hotkeysTimer.Enabled)
{
hotkeysTimer.Start();
@ -963,10 +968,18 @@ namespace DS4Windows
btnStartStop.Text = Properties.Resources.StopText;
}
else if (btnStartStop.Text == Properties.Resources.StopText)
private void serviceShutdown(bool log)
{
TaskRunner.Run(() =>
{
blankControllerTab();
Program.rootHub.Stop(log);
this.Invoke((System.Action)(() => { serviceShutdownFinish(); }));
});
}
private void serviceShutdownFinish()
{
hotkeysTimer.Stop();
autoProfilesTimer.Stop();
btnStartStop.Text = Properties.Resources.StartText;
@ -974,6 +987,18 @@ namespace DS4Windows
populateFullNotifyText();
}
public void btnStartStop_Clicked(bool log = true)
{
if (btnStartStop.Text == Properties.Resources.StartText)
{
serviceStartup(log);
}
else if (btnStartStop.Text == Properties.Resources.StopText)
{
blankControllerTab();
serviceShutdown(log);
}
startToolStripMenuItem.Text = btnStartStop.Text;
}
@ -1004,7 +1029,7 @@ namespace DS4Windows
if (!inHotPlug)
{
inHotPlug = true;
System.Threading.Tasks.Task.Run(() => { InnerHotplug2(uiContext); });
TaskRunner.Run(() => { InnerHotplug2(uiContext); });
}
}
}
@ -1032,7 +1057,7 @@ namespace DS4Windows
while (loopHotplug == true)
{
Program.rootHub.HotPlug(uiContext);
//Tasks.Task.Run(() => { Program.rootHub.HotPlug(uiContext); });
//TaskRunner.Run(() => { Program.rootHub.HotPlug(uiContext); });
lock (hotplugCounterLock)
{
hotplugCounter--;