Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

Commit

Permalink
Implemented TaskQueue to speed up HID report parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
nefarius committed Dec 19, 2015
1 parent dd73c3f commit e78432e
Show file tree
Hide file tree
Showing 16 changed files with 77 additions and 29 deletions.
4 changes: 2 additions & 2 deletions ScpCleanWipe/Properties/CommonInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@

[assembly: ComVisible(false)]

[assembly: AssemblyVersion("1.6.210.15353")]
[assembly: AssemblyFileVersion("1.6.210.15353")]
[assembly: AssemblyVersion("1.6.211.15353")]
[assembly: AssemblyFileVersion("1.6.211.15353")]
11 changes: 9 additions & 2 deletions ScpControl/Bluetooth/BthDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Net.NetworkInformation;
using System.Reactive.Concurrency;
using System.Reactive.Linq;
using System.Threading.Tasks;
using ScpControl.ScpCore;
using ScpControl.Shared.Core;
using ScpControl.Sound;
Expand All @@ -22,6 +23,8 @@ public partial class BthDevice : BthConnection, IDsDevice

private IDisposable _outputReportTask;

private readonly TaskQueue _inputReportQueue = new TaskQueue();

#endregion

#region Protected fields
Expand Down Expand Up @@ -187,9 +190,13 @@ public virtual void Completed()

public event EventHandler<ScpHidReport> HidReportReceived;

protected virtual void OnHidReportReceived(ScpHidReport report)
protected void OnHidReportReceived(ScpHidReport report)
{
if (HidReportReceived != null) HidReportReceived(this, report);
_inputReportQueue.Enqueue(() => Task.Run(() =>
{
if (HidReportReceived != null)
HidReportReceived.Invoke(this, report);
}));
}

#endregion
Expand Down
4 changes: 2 additions & 2 deletions ScpControl/Properties/CommonInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@

[assembly: ComVisible(false)]

[assembly: AssemblyVersion("1.6.210.15353")]
[assembly: AssemblyFileVersion("1.6.210.15353")]
[assembly: AssemblyVersion("1.6.211.15353")]
[assembly: AssemblyFileVersion("1.6.211.15353")]
3 changes: 2 additions & 1 deletion ScpControl/ScpControl.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<AssemblyInfoVersionSettings>
</AssemblyInfoVersionSettings>
<PrimaryVersionType>AssemblyVersionAttribute</PrimaryVersionType>
<AssemblyVersion>1.6.210.15353</AssemblyVersion>
<AssemblyVersion>1.6.211.15353</AssemblyVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -225,6 +225,7 @@
<Compile Include="Utilities\OSVersionInfoClass.cs" />
<Compile Include="Utilities\PhysicalAddressExtensions.cs" />
<Compile Include="Utilities\PortableSettingsProvider.cs" />
<Compile Include="Utilities\TaskQueue.cs" />
<Compile Include="Value Converters\EnumDescriptionConverter.cs" />
<Compile Include="Value Converters\RadioBoolToIntConverter.cs" />
<Compile Include="Wcf\IScpCommandService.cs" />
Expand Down
10 changes: 8 additions & 2 deletions ScpControl/Usb/UsbDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public partial class UsbDevice : ScpDevice, IDsDevice

private IDisposable _outputReportTask;

private readonly TaskQueue _inputReportQueue = new TaskQueue();

#endregion

#region Private methods
Expand Down Expand Up @@ -80,9 +82,13 @@ private void HidWorker(object o)

public event EventHandler<ScpHidReport> HidReportReceived;

protected virtual void OnHidReportReceived(ScpHidReport report)
protected void OnHidReportReceived(ScpHidReport report)
{
if (HidReportReceived != null) HidReportReceived(this, report);
_inputReportQueue.Enqueue(() => Task.Run(() =>
{
if (HidReportReceived != null)
HidReportReceived.Invoke(this, report);
}));
}

#endregion
Expand Down
34 changes: 34 additions & 0 deletions ScpControl/Utilities/TaskQueue.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Threading.Tasks;

namespace ScpControl.Utilities
{
/// <summary>
/// A non-blocking event handling queue.
/// </summary>
/// <remarks>http://stackoverflow.com/a/32993768/490629</remarks>
public class TaskQueue
{
private Task _previous = Task.FromResult(false);
private readonly object _key = new object();

public Task<T> Enqueue<T>(Func<Task<T>> taskGenerator)
{
lock (_key)
{
var next = _previous.ContinueWith(t => taskGenerator()).Unwrap();
_previous = next;
return next;
}
}
public Task Enqueue(Func<Task> taskGenerator)
{
lock (_key)
{
var next = _previous.ContinueWith(t => taskGenerator()).Unwrap();
_previous = next;
return next;
}
}
}
}
4 changes: 2 additions & 2 deletions ScpDebugInfoCollector/Properties/CommonInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@

[assembly: ComVisible(false)]

[assembly: AssemblyVersion("1.6.210.15353")]
[assembly: AssemblyFileVersion("1.6.210.15353")]
[assembly: AssemblyVersion("1.6.211.15353")]
[assembly: AssemblyFileVersion("1.6.211.15353")]
4 changes: 2 additions & 2 deletions ScpDriverInstaller/Properties/CommonInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@

[assembly: ComVisible(false)]

[assembly: AssemblyVersion("1.6.210.15353")]
[assembly: AssemblyFileVersion("1.6.210.15353")]
[assembly: AssemblyVersion("1.6.211.15353")]
[assembly: AssemblyFileVersion("1.6.211.15353")]
4 changes: 2 additions & 2 deletions ScpGamepadAnalyzer/Properties/CommonInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@

[assembly: ComVisible(false)]

[assembly: AssemblyVersion("1.6.210.15353")]
[assembly: AssemblyFileVersion("1.6.210.15353")]
[assembly: AssemblyVersion("1.6.211.15353")]
[assembly: AssemblyFileVersion("1.6.211.15353")]
4 changes: 2 additions & 2 deletions ScpMonitor/Properties/CommonInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@

[assembly: ComVisible(false)]

[assembly: AssemblyVersion("1.6.210.15353")]
[assembly: AssemblyFileVersion("1.6.210.15353")]
[assembly: AssemblyVersion("1.6.211.15353")]
[assembly: AssemblyFileVersion("1.6.211.15353")]
4 changes: 2 additions & 2 deletions ScpPair/Properties/CommonInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@

[assembly: ComVisible(false)]

[assembly: AssemblyVersion("1.6.210.15353")]
[assembly: AssemblyFileVersion("1.6.210.15353")]
[assembly: AssemblyVersion("1.6.211.15353")]
[assembly: AssemblyFileVersion("1.6.211.15353")]
4 changes: 2 additions & 2 deletions ScpProfiler/Properties/CommonInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@

[assembly: ComVisible(false)]

[assembly: AssemblyVersion("1.6.210.15353")]
[assembly: AssemblyFileVersion("1.6.210.15353")]
[assembly: AssemblyVersion("1.6.211.15353")]
[assembly: AssemblyFileVersion("1.6.211.15353")]
4 changes: 2 additions & 2 deletions ScpServer/Properties/CommonInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@

[assembly: ComVisible(false)]

[assembly: AssemblyVersion("1.6.210.15353")]
[assembly: AssemblyFileVersion("1.6.210.15353")]
[assembly: AssemblyVersion("1.6.211.15353")]
[assembly: AssemblyFileVersion("1.6.211.15353")]
4 changes: 2 additions & 2 deletions ScpService/Properties/CommonInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@

[assembly: ComVisible(false)]

[assembly: AssemblyVersion("1.6.210.15353")]
[assembly: AssemblyFileVersion("1.6.210.15353")]
[assembly: AssemblyVersion("1.6.211.15353")]
[assembly: AssemblyFileVersion("1.6.211.15353")]
4 changes: 2 additions & 2 deletions ScpSettings/Properties/CommonInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@

[assembly: ComVisible(false)]

[assembly: AssemblyVersion("1.6.210.15353")]
[assembly: AssemblyFileVersion("1.6.210.15353")]
[assembly: AssemblyVersion("1.6.211.15353")]
[assembly: AssemblyFileVersion("1.6.211.15353")]
4 changes: 2 additions & 2 deletions ScpXInputBridge/Properties/CommonInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@

[assembly: ComVisible(false)]

[assembly: AssemblyVersion("1.6.210.15353")]
[assembly: AssemblyFileVersion("1.6.210.15353")]
[assembly: AssemblyVersion("1.6.211.15353")]
[assembly: AssemblyFileVersion("1.6.211.15353")]

0 comments on commit e78432e

Please sign in to comment.