mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2025-12-13 10:08:31 +00:00
Added locks for groups
This commit is contained in:
parent
ad253fbeaa
commit
9de6a43907
@ -36,7 +36,7 @@ namespace RGB.NET.Core
|
|||||||
#region Methods
|
#region Methods
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public abstract IEnumerable<Led> GetLeds();
|
public abstract IList<Led> GetLeds();
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public virtual void OnAttach()
|
public virtual void OnAttach()
|
||||||
|
|||||||
@ -25,7 +25,7 @@ namespace RGB.NET.Core
|
|||||||
/// Gets a list containing all <see cref="Led"/> of this <see cref="ILedGroup"/>.
|
/// Gets a list containing all <see cref="Led"/> of this <see cref="ILedGroup"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>The list containing all <see cref="Led"/> of this <see cref="ILedGroup"/>.</returns>
|
/// <returns>The list containing all <see cref="Led"/> of this <see cref="ILedGroup"/>.</returns>
|
||||||
IEnumerable<Led> GetLeds();
|
IList<Led> GetLeds();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Called when the <see cref="ILedGroup"/> is attached to the <see cref="RGBSurface"/>.
|
/// Called when the <see cref="ILedGroup"/> is attached to the <see cref="RGBSurface"/>.
|
||||||
|
|||||||
@ -92,9 +92,10 @@ namespace RGB.NET.Groups
|
|||||||
{
|
{
|
||||||
if (leds == null) return;
|
if (leds == null) return;
|
||||||
|
|
||||||
foreach (Led led in leds)
|
lock (GroupLeds)
|
||||||
if ((led != null) && !ContainsLed(led))
|
foreach (Led led in leds)
|
||||||
GroupLeds.Add(led);
|
if ((led != null) && !ContainsLed(led))
|
||||||
|
GroupLeds.Add(led);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -111,9 +112,10 @@ namespace RGB.NET.Groups
|
|||||||
{
|
{
|
||||||
if (leds == null) return;
|
if (leds == null) return;
|
||||||
|
|
||||||
foreach (Led led in leds)
|
lock (GroupLeds)
|
||||||
if (led != null)
|
foreach (Led led in leds)
|
||||||
GroupLeds.Remove(led);
|
if (led != null)
|
||||||
|
GroupLeds.Remove(led);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -121,7 +123,11 @@ namespace RGB.NET.Groups
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="led">The LED which should be checked.</param>
|
/// <param name="led">The LED which should be checked.</param>
|
||||||
/// <returns><c>true</c> if the LED is contained by this ledgroup; otherwise, <c>false</c>.</returns>
|
/// <returns><c>true</c> if the LED is contained by this ledgroup; otherwise, <c>false</c>.</returns>
|
||||||
public bool ContainsLed(Led led) => (led != null) && GroupLeds.Contains(led);
|
public bool ContainsLed(Led led)
|
||||||
|
{
|
||||||
|
lock (GroupLeds)
|
||||||
|
return (led != null) && GroupLeds.Contains(led);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Merges the <see cref="Led"/> from the given ledgroup in this ledgroup.
|
/// Merges the <see cref="Led"/> from the given ledgroup in this ledgroup.
|
||||||
@ -129,9 +135,10 @@ namespace RGB.NET.Groups
|
|||||||
/// <param name="groupToMerge">The ledgroup to merge.</param>
|
/// <param name="groupToMerge">The ledgroup to merge.</param>
|
||||||
public void MergeLeds(ILedGroup groupToMerge)
|
public void MergeLeds(ILedGroup groupToMerge)
|
||||||
{
|
{
|
||||||
foreach (Led led in groupToMerge.GetLeds())
|
lock (GroupLeds)
|
||||||
if (!GroupLeds.Contains(led))
|
foreach (Led led in groupToMerge.GetLeds())
|
||||||
GroupLeds.Add(led);
|
if (!GroupLeds.Contains(led))
|
||||||
|
GroupLeds.Add(led);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@ -139,7 +146,11 @@ namespace RGB.NET.Groups
|
|||||||
/// Gets a list containing the <see cref="T:RGB.NET.Core.Led" /> from this group.
|
/// Gets a list containing the <see cref="T:RGB.NET.Core.Led" /> from this group.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>The list containing the <see cref="T:RGB.NET.Core.Led" />.</returns>
|
/// <returns>The list containing the <see cref="T:RGB.NET.Core.Led" />.</returns>
|
||||||
public override IEnumerable<Led> GetLeds() => GroupLeds;
|
public override IList<Led> GetLeds()
|
||||||
|
{
|
||||||
|
lock (GroupLeds)
|
||||||
|
return new List<Led>(GroupLeds);
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
@ -105,7 +105,7 @@ namespace RGB.NET.Groups
|
|||||||
/// Gets a list containing all <see cref="T:RGB.NET.Core.Led" /> of this <see cref="T:RGB.NET.Groups.RectangleLedGroup" />.
|
/// Gets a list containing all <see cref="T:RGB.NET.Core.Led" /> of this <see cref="T:RGB.NET.Groups.RectangleLedGroup" />.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>The list containing all <see cref="T:RGB.NET.Core.Led" /> of this <see cref="T:RGB.NET.Groups.RectangleLedGroup" />.</returns>
|
/// <returns>The list containing all <see cref="T:RGB.NET.Core.Led" /> of this <see cref="T:RGB.NET.Groups.RectangleLedGroup" />.</returns>
|
||||||
public override IEnumerable<Led> GetLeds() => _ledCache ??= RGBSurface.Instance.Leds.Where(led => led.AbsoluteLedRectangle.CalculateIntersectPercentage(Rectangle) >= MinOverlayPercentage).ToList();
|
public override IList<Led> GetLeds() => _ledCache ??= RGBSurface.Instance.Leds.Where(led => led.AbsoluteLedRectangle.CalculateIntersectPercentage(Rectangle) >= MinOverlayPercentage).ToList();
|
||||||
|
|
||||||
private void InvalidateCache() => _ledCache = null;
|
private void InvalidateCache() => _ledCache = null;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user