mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2025-12-13 10:08:31 +00:00
Merge pull request #213 from DarthAffe/SDK/Wooting
Wooting - Fixed race condition during SDK load/unload
This commit is contained in:
commit
faf7535eaf
@ -27,6 +27,8 @@ namespace RGB.NET.Devices.Wooting.Generic
|
|||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet)
|
protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet)
|
||||||
|
{
|
||||||
|
lock (_WootingSDK.SdkLock)
|
||||||
{
|
{
|
||||||
foreach ((object key, Color color) in dataSet)
|
foreach ((object key, Color color) in dataSet)
|
||||||
{
|
{
|
||||||
@ -36,6 +38,7 @@ namespace RGB.NET.Devices.Wooting.Generic
|
|||||||
|
|
||||||
_WootingSDK.ArrayUpdateKeyboard();
|
_WootingSDK.ArrayUpdateKeyboard();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,6 +16,7 @@ namespace RGB.NET.Devices.Wooting.Native
|
|||||||
#region Library management
|
#region Library management
|
||||||
|
|
||||||
private static IntPtr _dllHandle = IntPtr.Zero;
|
private static IntPtr _dllHandle = IntPtr.Zero;
|
||||||
|
internal static object SdkLock = new();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Reloads the SDK.
|
/// Reloads the SDK.
|
||||||
@ -52,6 +53,16 @@ namespace RGB.NET.Devices.Wooting.Native
|
|||||||
{
|
{
|
||||||
if (_dllHandle == IntPtr.Zero) return;
|
if (_dllHandle == IntPtr.Zero) return;
|
||||||
|
|
||||||
|
Reset();
|
||||||
|
Close();
|
||||||
|
|
||||||
|
_getDeviceInfoPointer = null;
|
||||||
|
_keyboardConnectedPointer = null;
|
||||||
|
_arrayUpdateKeyboardPointer = null;
|
||||||
|
_arraySetSinglePointer = null;
|
||||||
|
_resetPointer = null;
|
||||||
|
_closePointer = null;
|
||||||
|
|
||||||
// ReSharper disable once EmptyEmbeddedStatement - DarthAffe 20.02.2016: We might need to reduce the internal reference counter more than once to set the library free
|
// ReSharper disable once EmptyEmbeddedStatement - DarthAffe 20.02.2016: We might need to reduce the internal reference counter more than once to set the library free
|
||||||
while (FreeLibrary(_dllHandle)) ;
|
while (FreeLibrary(_dllHandle)) ;
|
||||||
_dllHandle = IntPtr.Zero;
|
_dllHandle = IntPtr.Zero;
|
||||||
@ -116,3 +127,4 @@ namespace RGB.NET.Devices.Wooting.Native
|
|||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,11 +54,16 @@ namespace RGB.NET.Devices.Wooting
|
|||||||
#region Methods
|
#region Methods
|
||||||
|
|
||||||
protected override void InitializeSDK()
|
protected override void InitializeSDK()
|
||||||
|
{
|
||||||
|
lock (_WootingSDK.SdkLock)
|
||||||
{
|
{
|
||||||
_WootingSDK.Reload();
|
_WootingSDK.Reload();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected override IEnumerable<IRGBDevice> LoadDevices()
|
protected override IEnumerable<IRGBDevice> LoadDevices()
|
||||||
|
{
|
||||||
|
lock (_WootingSDK.SdkLock)
|
||||||
{
|
{
|
||||||
if (_WootingSDK.KeyboardConnected())
|
if (_WootingSDK.KeyboardConnected())
|
||||||
{
|
{
|
||||||
@ -76,18 +81,19 @@ namespace RGB.NET.Devices.Wooting
|
|||||||
yield return device;
|
yield return device;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override void Dispose()
|
public override void Dispose()
|
||||||
{
|
{
|
||||||
base.Dispose();
|
base.Dispose();
|
||||||
|
|
||||||
try { _WootingSDK.Close(); }
|
lock (_WootingSDK.SdkLock)
|
||||||
catch { /* Unlucky.. */ }
|
{
|
||||||
|
|
||||||
try { _WootingSDK.UnloadWootingSDK(); }
|
try { _WootingSDK.UnloadWootingSDK(); }
|
||||||
catch { /* at least we tried */ }
|
catch { /* at least we tried */ }
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user