From 0d10004624629bfcc226b3d5e93ea047463d51b4 Mon Sep 17 00:00:00 2001 From: Travis Nickles Date: Wed, 15 Nov 2017 19:57:58 -0600 Subject: [PATCH] Output thread tweaks --- DS4Windows/DS4Library/DS4Device.cs | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/DS4Windows/DS4Library/DS4Device.cs b/DS4Windows/DS4Library/DS4Device.cs index 868acea..e78a6a6 100644 --- a/DS4Windows/DS4Library/DS4Device.cs +++ b/DS4Windows/DS4Library/DS4Device.cs @@ -163,7 +163,6 @@ namespace DS4Windows public event EventHandler Removal = null; public event EventHandler SyncChange = null; public event EventHandler SerialChange = null; - //public event EventHandler PublishRemoval = null; public HidDevice HidDevice => hDevice; public bool IsExclusive => HidDevice.IsExclusive; @@ -579,25 +578,20 @@ namespace DS4Windows int lastError = 0; while (!exitOutputThread) { - bool result = false; + bool result = false, currentRumble = false; - if (outputRumble) + if (currentRumble) { - lock (outputReportBuffer) - { - outputReportBuffer.CopyTo(outputReport, 0); - outputPendCount--; - outputRumble = false; - } - lock(outputReport) { result = writeOutput(); } + currentRumble = false; if (!result) { - outputRumble = true; + currentRumble = true; + exitOutputThread = true; int thisError = Marshal.GetLastWin32Error(); if (lastError != thisError) { @@ -608,11 +602,18 @@ namespace DS4Windows } } - if (!outputRumble) + if (!currentRumble) { lastError = 0; lock (outputReportBuffer) + { Monitor.Wait(outputReportBuffer); + outputReportBuffer.CopyTo(outputReport, 0); + outputPendCount--; + outputRumble = false; + } + + currentRumble = true; } } }