1
0
mirror of https://github.com/DarthAffe/RGB.NET.git synced 2025-12-13 10:08:31 +00:00

Added locks around device provider instance usages

This commit is contained in:
Darth Affe 2023-06-18 19:54:57 +02:00
parent fdc69fdac5
commit 0609e49571
14 changed files with 336 additions and 108 deletions

View File

@ -16,11 +16,21 @@ public sealed class AsusDeviceProvider : AbstractRGBDeviceProvider
{ {
#region Properties & Fields #region Properties & Fields
// ReSharper disable once InconsistentNaming
private static readonly object _lock = new();
private static AsusDeviceProvider? _instance; private static AsusDeviceProvider? _instance;
/// <summary> /// <summary>
/// Gets the singleton <see cref="AsusDeviceProvider"/> instance. /// Gets the singleton <see cref="AsusDeviceProvider"/> instance.
/// </summary> /// </summary>
public static AsusDeviceProvider Instance => _instance ?? new AsusDeviceProvider(); public static AsusDeviceProvider Instance
{
get
{
lock (_lock)
return _instance ?? new AsusDeviceProvider();
}
}
private IAuraSdk2? _sdk; private IAuraSdk2? _sdk;
private IAuraSyncDeviceCollection? _devices; //HACK DarthAffe 05.04.2021: Due to some researches this might fix the access violation in the asus-sdk private IAuraSyncDeviceCollection? _devices; //HACK DarthAffe 05.04.2021: Due to some researches this might fix the access violation in the asus-sdk
@ -35,8 +45,11 @@ public sealed class AsusDeviceProvider : AbstractRGBDeviceProvider
/// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception> /// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception>
public AsusDeviceProvider() public AsusDeviceProvider()
{ {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(AsusDeviceProvider)}"); lock (_lock)
_instance = this; {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(AsusDeviceProvider)}");
_instance = this;
}
} }
#endregion #endregion
@ -82,14 +95,17 @@ public sealed class AsusDeviceProvider : AbstractRGBDeviceProvider
/// <inheritdoc /> /// <inheritdoc />
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)
{ {
base.Dispose(disposing); lock (_lock)
{
base.Dispose(disposing);
try { _sdk?.ReleaseControl(0); } try { _sdk?.ReleaseControl(0); }
catch { /* at least we tried */ } catch { /* at least we tried */ }
_devices = null; _devices = null;
_sdk = null; _sdk = null;
_instance = null; _instance = null;
}
} }
#endregion #endregion

View File

@ -17,11 +17,21 @@ public sealed class CoolerMasterDeviceProvider : AbstractRGBDeviceProvider
{ {
#region Properties & Fields #region Properties & Fields
// ReSharper disable once InconsistentNaming
private static readonly object _lock = new();
private static CoolerMasterDeviceProvider? _instance; private static CoolerMasterDeviceProvider? _instance;
/// <summary> /// <summary>
/// Gets the singleton <see cref="CoolerMasterDeviceProvider"/> instance. /// Gets the singleton <see cref="CoolerMasterDeviceProvider"/> instance.
/// </summary> /// </summary>
public static CoolerMasterDeviceProvider Instance => _instance ?? new CoolerMasterDeviceProvider(); public static CoolerMasterDeviceProvider Instance
{
get
{
lock (_lock)
return _instance ?? new CoolerMasterDeviceProvider();
}
}
/// <summary> /// <summary>
/// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications. /// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications.
@ -45,8 +55,11 @@ public sealed class CoolerMasterDeviceProvider : AbstractRGBDeviceProvider
/// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception> /// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception>
public CoolerMasterDeviceProvider() public CoolerMasterDeviceProvider()
{ {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(CoolerMasterDeviceProvider)}"); lock (_lock)
_instance = this; {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(CoolerMasterDeviceProvider)}");
_instance = this;
}
} }
#endregion #endregion
@ -96,12 +109,15 @@ public sealed class CoolerMasterDeviceProvider : AbstractRGBDeviceProvider
/// <inheritdoc /> /// <inheritdoc />
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)
{ {
base.Dispose(disposing); lock (_lock)
{
base.Dispose(disposing);
try { _CoolerMasterSDK.Reload(); } try { _CoolerMasterSDK.Reload(); }
catch { /* Unlucky.. */ } catch { /* Unlucky.. */ }
_instance = null; _instance = null;
}
} }
#endregion #endregion

View File

@ -17,11 +17,21 @@ public sealed class CorsairDeviceProvider : AbstractRGBDeviceProvider
{ {
#region Properties & Fields #region Properties & Fields
// ReSharper disable once InconsistentNaming
private static readonly object _lock = new();
private static CorsairDeviceProvider? _instance; private static CorsairDeviceProvider? _instance;
/// <summary> /// <summary>
/// Gets the singleton <see cref="CorsairDeviceProvider"/> instance. /// Gets the singleton <see cref="CorsairDeviceProvider"/> instance.
/// </summary> /// </summary>
public static CorsairDeviceProvider Instance => _instance ?? new CorsairDeviceProvider(); public static CorsairDeviceProvider Instance
{
get
{
lock (_lock)
return _instance ?? new CorsairDeviceProvider();
}
}
/// <summary> /// <summary>
/// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications. /// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications.
@ -80,8 +90,11 @@ public sealed class CorsairDeviceProvider : AbstractRGBDeviceProvider
/// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception> /// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception>
public CorsairDeviceProvider() public CorsairDeviceProvider()
{ {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(CorsairDeviceProvider)}"); lock (_lock)
_instance = this; {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(CorsairDeviceProvider)}");
_instance = this;
}
} }
#endregion #endregion
@ -302,12 +315,18 @@ public sealed class CorsairDeviceProvider : AbstractRGBDeviceProvider
/// <inheritdoc /> /// <inheritdoc />
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)
{ {
base.Dispose(disposing); lock (_lock)
{
base.Dispose(disposing);
try { _CUESDK.CorsairDisconnect(); } catch { /* at least we tried */ } try { _CUESDK.CorsairDisconnect(); }
try { _CUESDK.UnloadCUESDK(); } catch { /* at least we tried */ } catch { /* at least we tried */ }
_instance = null; try { _CUESDK.UnloadCUESDK(); }
catch { /* at least we tried */ }
_instance = null;
}
} }
#endregion #endregion

View File

@ -16,11 +16,21 @@ public sealed class DMXDeviceProvider : AbstractRGBDeviceProvider
{ {
#region Properties & Fields #region Properties & Fields
// ReSharper disable once InconsistentNaming
private static readonly object _lock = new();
private static DMXDeviceProvider? _instance; private static DMXDeviceProvider? _instance;
/// <summary> /// <summary>
/// Gets the singleton <see cref="DMXDeviceProvider"/> instance. /// Gets the singleton <see cref="DMXDeviceProvider"/> instance.
/// </summary> /// </summary>
public static DMXDeviceProvider Instance => _instance ?? new DMXDeviceProvider(); public static DMXDeviceProvider Instance
{
get
{
lock (_lock)
return _instance ?? new DMXDeviceProvider();
}
}
/// <summary> /// <summary>
/// Gets a list of all defined device-definitions. /// Gets a list of all defined device-definitions.
@ -37,8 +47,11 @@ public sealed class DMXDeviceProvider : AbstractRGBDeviceProvider
/// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception> /// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception>
public DMXDeviceProvider() public DMXDeviceProvider()
{ {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(DMXDeviceProvider)}"); lock (_lock)
_instance = this; {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(DMXDeviceProvider)}");
_instance = this;
}
} }
#endregion #endregion
@ -89,9 +102,12 @@ public sealed class DMXDeviceProvider : AbstractRGBDeviceProvider
/// <inheritdoc /> /// <inheritdoc />
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)
{ {
base.Dispose(disposing); lock (_lock)
{
base.Dispose(disposing);
_instance = null; _instance = null;
}
} }
#endregion #endregion

View File

@ -16,11 +16,21 @@ public sealed class DebugDeviceProvider : AbstractRGBDeviceProvider
{ {
#region Properties & Fields #region Properties & Fields
// ReSharper disable once InconsistentNaming
private static readonly object _lock = new();
private static DebugDeviceProvider? _instance; private static DebugDeviceProvider? _instance;
/// <summary> /// <summary>
/// Gets the singleton <see cref="DebugDeviceProvider"/> instance. /// Gets the singleton <see cref="DebugDeviceProvider"/> instance.
/// </summary> /// </summary>
public static DebugDeviceProvider Instance => _instance ?? new DebugDeviceProvider(); public static DebugDeviceProvider Instance
{
get
{
lock (_lock)
return _instance ?? new DebugDeviceProvider();
}
}
private List<(IDeviceLayout layout, Action<IEnumerable<Led>>? updateLedsAction)> _fakeDeviceDefinitions = new(); private List<(IDeviceLayout layout, Action<IEnumerable<Led>>? updateLedsAction)> _fakeDeviceDefinitions = new();
@ -34,8 +44,11 @@ public sealed class DebugDeviceProvider : AbstractRGBDeviceProvider
/// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception> /// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception>
public DebugDeviceProvider() public DebugDeviceProvider()
{ {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(DebugDeviceProvider)}"); lock (_lock)
_instance = this; {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(DebugDeviceProvider)}");
_instance = this;
}
} }
#endregion #endregion
@ -68,11 +81,14 @@ public sealed class DebugDeviceProvider : AbstractRGBDeviceProvider
/// <inheritdoc /> /// <inheritdoc />
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)
{ {
base.Dispose(disposing); lock (_lock)
{
base.Dispose(disposing);
_fakeDeviceDefinitions.Clear(); _fakeDeviceDefinitions.Clear();
_instance = null; _instance = null;
}
} }
#endregion #endregion

View File

@ -20,11 +20,21 @@ public class LogitechDeviceProvider : AbstractRGBDeviceProvider
{ {
#region Properties & Fields #region Properties & Fields
// ReSharper disable once InconsistentNaming
private static readonly object _lock = new();
private static LogitechDeviceProvider? _instance; private static LogitechDeviceProvider? _instance;
/// <summary> /// <summary>
/// Gets the singleton <see cref="LogitechDeviceProvider"/> instance. /// Gets the singleton <see cref="LogitechDeviceProvider"/> instance.
/// </summary> /// </summary>
public static LogitechDeviceProvider Instance => _instance ?? new LogitechDeviceProvider(); public static LogitechDeviceProvider Instance
{
get
{
lock (_lock)
return _instance ?? new LogitechDeviceProvider();
}
}
/// <summary> /// <summary>
/// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications. /// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications.
@ -112,7 +122,7 @@ public class LogitechDeviceProvider : AbstractRGBDeviceProvider
{ 0x0A78, RGBDeviceType.Speaker, "G560", LedMappings.ZoneSpeaker, (LogitechDeviceType.Speaker, 4, 0) }, { 0x0A78, RGBDeviceType.Speaker, "G560", LedMappings.ZoneSpeaker, (LogitechDeviceType.Speaker, 4, 0) },
}; };
/// <summary> /// <summary>
/// Gets the HID-definitions for wireless per-zone-devices. /// Gets the HID-definitions for wireless per-zone-devices.
/// </summary> /// </summary>
@ -164,8 +174,12 @@ public class LogitechDeviceProvider : AbstractRGBDeviceProvider
/// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception> /// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception>
public LogitechDeviceProvider() public LogitechDeviceProvider()
{ {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(LogitechDeviceProvider)}"); lock (_lock)
_instance = this; {
if (_instance != null)
throw new InvalidOperationException($"There can be only one instance of type {nameof(LogitechDeviceProvider)}");
_instance = this;
}
} }
#endregion #endregion
@ -256,15 +270,18 @@ public class LogitechDeviceProvider : AbstractRGBDeviceProvider
/// <inheritdoc /> /// <inheritdoc />
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)
{ {
base.Dispose(disposing); lock (_lock)
{
base.Dispose(disposing);
try { _LogitechGSDK.LogiLedRestoreLighting(); } try { _LogitechGSDK.LogiLedRestoreLighting(); }
catch { /* at least we tried */ } catch { /* at least we tried */ }
try { _LogitechGSDK.UnloadLogitechGSDK(); } try { _LogitechGSDK.UnloadLogitechGSDK(); }
catch { /* at least we tried */ } catch { /* at least we tried */ }
_instance = null; _instance = null;
}
} }
#endregion #endregion

View File

@ -17,11 +17,21 @@ public class MsiDeviceProvider : AbstractRGBDeviceProvider
{ {
#region Properties & Fields #region Properties & Fields
// ReSharper disable once InconsistentNaming
private static readonly object _lock = new();
private static MsiDeviceProvider? _instance; private static MsiDeviceProvider? _instance;
/// <summary> /// <summary>
/// Gets the singleton <see cref="MsiDeviceProvider"/> instance. /// Gets the singleton <see cref="MsiDeviceProvider"/> instance.
/// </summary> /// </summary>
public static MsiDeviceProvider Instance => _instance ?? new MsiDeviceProvider(); public static MsiDeviceProvider Instance
{
get
{
lock (_lock)
return _instance ?? new MsiDeviceProvider();
}
}
/// <summary> /// <summary>
/// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications. /// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications.
@ -45,8 +55,11 @@ public class MsiDeviceProvider : AbstractRGBDeviceProvider
/// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception> /// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception>
public MsiDeviceProvider() public MsiDeviceProvider()
{ {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(MsiDeviceProvider)}"); lock (_lock)
_instance = this; {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(MsiDeviceProvider)}");
_instance = this;
}
} }
#endregion #endregion
@ -100,12 +113,15 @@ public class MsiDeviceProvider : AbstractRGBDeviceProvider
/// <inheritdoc /> /// <inheritdoc />
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)
{ {
base.Dispose(disposing); lock (_lock)
{
base.Dispose(disposing);
try { _MsiSDK.UnloadMsiSDK(); } try { _MsiSDK.UnloadMsiSDK(); }
catch { /* at least we tried */ } catch { /* at least we tried */ }
_instance = null; _instance = null;
}
} }
#endregion #endregion

View File

@ -17,11 +17,21 @@ public sealed class NovationDeviceProvider : AbstractRGBDeviceProvider
{ {
#region Properties & Fields #region Properties & Fields
// ReSharper disable once InconsistentNaming
private static readonly object _lock = new();
private static NovationDeviceProvider? _instance; private static NovationDeviceProvider? _instance;
/// <summary> /// <summary>
/// Gets the singleton <see cref="NovationDeviceProvider"/> instance. /// Gets the singleton <see cref="NovationDeviceProvider"/> instance.
/// </summary> /// </summary>
public static NovationDeviceProvider Instance => _instance ?? new NovationDeviceProvider(); public static NovationDeviceProvider Instance
{
get
{
lock (_lock)
return _instance ?? new NovationDeviceProvider();
}
}
#endregion #endregion
@ -33,8 +43,11 @@ public sealed class NovationDeviceProvider : AbstractRGBDeviceProvider
/// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception> /// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception>
private NovationDeviceProvider() private NovationDeviceProvider()
{ {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(NovationDeviceProvider)}"); lock (_lock)
_instance = this; {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(NovationDeviceProvider)}");
_instance = this;
}
} }
#endregion #endregion
@ -70,9 +83,12 @@ public sealed class NovationDeviceProvider : AbstractRGBDeviceProvider
/// <inheritdoc /> /// <inheritdoc />
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)
{ {
base.Dispose(disposing); lock (_lock)
{
base.Dispose(disposing);
_instance = null; _instance = null;
}
} }
#endregion #endregion

View File

@ -14,6 +14,9 @@ public sealed class OpenRGBDeviceProvider : AbstractRGBDeviceProvider
{ {
#region Properties & Fields #region Properties & Fields
// ReSharper disable once InconsistentNaming
private static readonly object _lock = new();
private readonly List<OpenRgbClient> _clients = new(); private readonly List<OpenRgbClient> _clients = new();
private static OpenRGBDeviceProvider? _instance; private static OpenRGBDeviceProvider? _instance;
@ -21,7 +24,14 @@ public sealed class OpenRGBDeviceProvider : AbstractRGBDeviceProvider
/// <summary> /// <summary>
/// Gets the singleton <see cref="OpenRGBDeviceProvider"/> instance. /// Gets the singleton <see cref="OpenRGBDeviceProvider"/> instance.
/// </summary> /// </summary>
public static OpenRGBDeviceProvider Instance => _instance ?? new OpenRGBDeviceProvider(); public static OpenRGBDeviceProvider Instance
{
get
{
lock (_lock)
return _instance ?? new OpenRGBDeviceProvider();
}
}
/// <summary> /// <summary>
/// Gets a list of all defined device-definitions. /// Gets a list of all defined device-definitions.
@ -48,8 +58,11 @@ public sealed class OpenRGBDeviceProvider : AbstractRGBDeviceProvider
/// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception> /// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception>
public OpenRGBDeviceProvider() public OpenRGBDeviceProvider()
{ {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(OpenRGBDeviceProvider)}"); lock (_lock)
_instance = this; {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(OpenRGBDeviceProvider)}");
_instance = this;
}
} }
#endregion #endregion
@ -151,18 +164,21 @@ public sealed class OpenRGBDeviceProvider : AbstractRGBDeviceProvider
/// <inheritdoc /> /// <inheritdoc />
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)
{ {
base.Dispose(disposing); lock (_lock)
foreach (OpenRgbClient client in _clients)
{ {
try { client.Dispose(); } base.Dispose(disposing);
catch { /* at least we tried */ }
foreach (OpenRgbClient client in _clients)
{
try { client.Dispose(); }
catch { /* at least we tried */ }
}
_clients.Clear();
DeviceDefinitions.Clear();
_instance = null;
} }
_clients.Clear();
DeviceDefinitions.Clear();
_instance = null;
} }
#endregion #endregion

View File

@ -25,11 +25,21 @@ public sealed class PicoPiDeviceProvider : AbstractRGBDeviceProvider
#region Properties & Fields #region Properties & Fields
// ReSharper disable once InconsistentNaming
private static readonly object _lock = new();
private static PicoPiDeviceProvider? _instance; private static PicoPiDeviceProvider? _instance;
/// <summary> /// <summary>
/// Gets the singleton <see cref="PicoPiDeviceProvider"/> instance. /// Gets the singleton <see cref="PicoPiDeviceProvider"/> instance.
/// </summary> /// </summary>
public static PicoPiDeviceProvider Instance => _instance ?? new PicoPiDeviceProvider(); public static PicoPiDeviceProvider Instance
{
get
{
lock (_lock)
return _instance ?? new PicoPiDeviceProvider();
}
}
/// <summary> /// <summary>
/// Gets the HID-definitions for PicoPi-devices. /// Gets the HID-definitions for PicoPi-devices.
@ -57,8 +67,11 @@ public sealed class PicoPiDeviceProvider : AbstractRGBDeviceProvider
/// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception> /// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception>
public PicoPiDeviceProvider() public PicoPiDeviceProvider()
{ {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(PicoPiDeviceProvider)}"); lock (_lock)
_instance = this; {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(PicoPiDeviceProvider)}");
_instance = this;
}
} }
#endregion #endregion
@ -129,9 +142,12 @@ public sealed class PicoPiDeviceProvider : AbstractRGBDeviceProvider
/// <inheritdoc /> /// <inheritdoc />
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)
{ {
base.Dispose(disposing); lock (_lock)
{
base.Dispose(disposing);
_instance = null; _instance = null;
}
} }
#endregion #endregion

View File

@ -19,11 +19,21 @@ public sealed class RazerDeviceProvider : AbstractRGBDeviceProvider
{ {
#region Properties & Fields #region Properties & Fields
// ReSharper disable once InconsistentNaming
private static readonly object _lock = new();
private static RazerDeviceProvider? _instance; private static RazerDeviceProvider? _instance;
/// <summary> /// <summary>
/// Gets the singleton <see cref="RazerDeviceProvider"/> instance. /// Gets the singleton <see cref="RazerDeviceProvider"/> instance.
/// </summary> /// </summary>
public static RazerDeviceProvider Instance => _instance ?? new RazerDeviceProvider(); public static RazerDeviceProvider Instance
{
get
{
lock (_lock)
return _instance ?? new RazerDeviceProvider();
}
}
/// <summary> /// <summary>
/// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications. /// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications.
@ -254,7 +264,7 @@ public sealed class RazerDeviceProvider : AbstractRGBDeviceProvider
{ 0x0F13, RGBDeviceType.Unknown, "Lian Li O11", LedMappings.ChromaLink, RazerEndpointType.ChromaLink }, { 0x0F13, RGBDeviceType.Unknown, "Lian Li O11", LedMappings.ChromaLink, RazerEndpointType.ChromaLink },
{ 0x0F1D, RGBDeviceType.Unknown, "Mouse Bungee V3 Chroma", LedMappings.ChromaLink, RazerEndpointType.ChromaLink }, { 0x0F1D, RGBDeviceType.Unknown, "Mouse Bungee V3 Chroma", LedMappings.ChromaLink, RazerEndpointType.ChromaLink },
{ 0x0F1F, RGBDeviceType.LedController, "Addressable RGB Controller", LedMappings.ChromaLink, RazerEndpointType.ChromaLink }, { 0x0F1F, RGBDeviceType.LedController, "Addressable RGB Controller", LedMappings.ChromaLink, RazerEndpointType.ChromaLink },
}; };
#endregion #endregion
@ -267,8 +277,11 @@ public sealed class RazerDeviceProvider : AbstractRGBDeviceProvider
/// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception> /// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception>
public RazerDeviceProvider() public RazerDeviceProvider()
{ {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(RazerDeviceProvider)}"); lock (_lock)
_instance = this; {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(RazerDeviceProvider)}");
_instance = this;
}
} }
#endregion #endregion
@ -344,15 +357,18 @@ public sealed class RazerDeviceProvider : AbstractRGBDeviceProvider
/// <inheritdoc /> /// <inheritdoc />
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)
{ {
base.Dispose(disposing); lock (_lock)
{
base.Dispose(disposing);
TryUnInit(); TryUnInit();
// DarthAffe 03.03.2020: Fails with an access-violation - verify if an unload is already triggered by uninit // DarthAffe 03.03.2020: Fails with an access-violation - verify if an unload is already triggered by uninit
//try { _RazerSDK.UnloadRazerSDK(); } //try { _RazerSDK.UnloadRazerSDK(); }
//catch { /* at least we tried */ } //catch { /* at least we tried */ }
_instance = null; _instance = null;
}
} }
#endregion #endregion

View File

@ -20,11 +20,21 @@ public sealed class SteelSeriesDeviceProvider : AbstractRGBDeviceProvider
#region Properties & Fields #region Properties & Fields
// ReSharper disable once InconsistentNaming
private static readonly object _lock = new();
private static SteelSeriesDeviceProvider? _instance; private static SteelSeriesDeviceProvider? _instance;
/// <summary> /// <summary>
/// Gets the singleton <see cref="SteelSeriesDeviceProvider"/> instance. /// Gets the singleton <see cref="SteelSeriesDeviceProvider"/> instance.
/// </summary> /// </summary>
public static SteelSeriesDeviceProvider Instance => _instance ?? new SteelSeriesDeviceProvider(); public static SteelSeriesDeviceProvider Instance
{
get
{
lock (_lock)
return _instance ?? new SteelSeriesDeviceProvider();
}
}
private const int VENDOR_ID = 0x1038; private const int VENDOR_ID = 0x1038;
@ -93,8 +103,11 @@ public sealed class SteelSeriesDeviceProvider : AbstractRGBDeviceProvider
/// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception> /// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception>
public SteelSeriesDeviceProvider() public SteelSeriesDeviceProvider()
{ {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(SteelSeriesDeviceProvider)}"); lock (_lock)
_instance = this; {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(SteelSeriesDeviceProvider)}");
_instance = this;
}
} }
#endregion #endregion
@ -135,12 +148,15 @@ public sealed class SteelSeriesDeviceProvider : AbstractRGBDeviceProvider
/// <inheritdoc /> /// <inheritdoc />
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)
{ {
base.Dispose(disposing); lock (_lock)
{
base.Dispose(disposing);
try { SteelSeriesSDK.Dispose(); } try { SteelSeriesSDK.Dispose(); }
catch { /* shit happens */ } catch { /* shit happens */ }
_instance = null; _instance = null;
}
} }
#endregion #endregion

View File

@ -16,11 +16,21 @@ public sealed class WS281XDeviceProvider : AbstractRGBDeviceProvider
{ {
#region Properties & Fields #region Properties & Fields
// ReSharper disable once InconsistentNaming
private static readonly object _lock = new();
private static WS281XDeviceProvider? _instance; private static WS281XDeviceProvider? _instance;
/// <summary> /// <summary>
/// Gets the singleton <see cref="WS281XDeviceProvider"/> instance. /// Gets the singleton <see cref="WS281XDeviceProvider"/> instance.
/// </summary> /// </summary>
public static WS281XDeviceProvider Instance => _instance ?? new WS281XDeviceProvider(); public static WS281XDeviceProvider Instance
{
get
{
lock (_lock)
return _instance ?? new WS281XDeviceProvider();
}
}
/// <summary> /// <summary>
/// Gets a list of all defined device-definitions. /// Gets a list of all defined device-definitions.
@ -39,8 +49,11 @@ public sealed class WS281XDeviceProvider : AbstractRGBDeviceProvider
/// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception> /// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception>
public WS281XDeviceProvider() public WS281XDeviceProvider()
{ {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(WS281XDeviceProvider)}"); lock (_lock)
_instance = this; {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(WS281XDeviceProvider)}");
_instance = this;
}
} }
#endregion #endregion
@ -72,11 +85,14 @@ public sealed class WS281XDeviceProvider : AbstractRGBDeviceProvider
/// <inheritdoc /> /// <inheritdoc />
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)
{ {
base.Dispose(disposing); lock (_lock)
{
base.Dispose(disposing);
DeviceDefinitions.Clear(); DeviceDefinitions.Clear();
_instance = null; _instance = null;
}
} }
#endregion #endregion

View File

@ -16,11 +16,21 @@ public sealed class WootingDeviceProvider : AbstractRGBDeviceProvider
{ {
#region Properties & Fields #region Properties & Fields
// ReSharper disable once InconsistentNaming
private static readonly object _lock = new();
private static WootingDeviceProvider? _instance; private static WootingDeviceProvider? _instance;
/// <summary> /// <summary>
/// Gets the singleton <see cref="WootingDeviceProvider"/> instance. /// Gets the singleton <see cref="WootingDeviceProvider"/> instance.
/// </summary> /// </summary>
public static WootingDeviceProvider Instance => _instance ?? new WootingDeviceProvider(); public static WootingDeviceProvider Instance
{
get
{
lock (_lock)
return _instance ?? new WootingDeviceProvider();
}
}
/// <summary> /// <summary>
/// Gets a modifiable list of paths used to find the native SDK-dlls for x86 windows applications. /// Gets a modifiable list of paths used to find the native SDK-dlls for x86 windows applications.
@ -57,8 +67,11 @@ public sealed class WootingDeviceProvider : AbstractRGBDeviceProvider
/// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception> /// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception>
public WootingDeviceProvider() public WootingDeviceProvider()
{ {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(WootingDeviceProvider)}"); lock (_lock)
_instance = this; {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(WootingDeviceProvider)}");
_instance = this;
}
} }
#endregion #endregion
@ -96,15 +109,18 @@ public sealed class WootingDeviceProvider : AbstractRGBDeviceProvider
/// <inheritdoc /> /// <inheritdoc />
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)
{ {
base.Dispose(disposing); lock (_lock)
lock (_WootingSDK.SdkLock)
{ {
try { _WootingSDK.UnloadWootingSDK(); } base.Dispose(disposing);
catch { /* at least we tried */ }
}
_instance = null; lock (_WootingSDK.SdkLock)
{
try { _WootingSDK.UnloadWootingSDK(); }
catch { /* at least we tried */ }
}
_instance = null;
}
} }
#endregion #endregion