mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2025-12-12 17:48: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
|
||||
|
||||
/// <inheritdoc />
|
||||
public abstract IEnumerable<Led> GetLeds();
|
||||
public abstract IList<Led> GetLeds();
|
||||
|
||||
/// <inheritdoc />
|
||||
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"/>.
|
||||
/// </summary>
|
||||
/// <returns>The list containing all <see cref="Led"/> of this <see cref="ILedGroup"/>.</returns>
|
||||
IEnumerable<Led> GetLeds();
|
||||
IList<Led> GetLeds();
|
||||
|
||||
/// <summary>
|
||||
/// 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;
|
||||
|
||||
foreach (Led led in leds)
|
||||
if ((led != null) && !ContainsLed(led))
|
||||
GroupLeds.Add(led);
|
||||
lock (GroupLeds)
|
||||
foreach (Led led in leds)
|
||||
if ((led != null) && !ContainsLed(led))
|
||||
GroupLeds.Add(led);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -111,9 +112,10 @@ namespace RGB.NET.Groups
|
||||
{
|
||||
if (leds == null) return;
|
||||
|
||||
foreach (Led led in leds)
|
||||
if (led != null)
|
||||
GroupLeds.Remove(led);
|
||||
lock (GroupLeds)
|
||||
foreach (Led led in leds)
|
||||
if (led != null)
|
||||
GroupLeds.Remove(led);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -121,7 +123,11 @@ namespace RGB.NET.Groups
|
||||
/// </summary>
|
||||
/// <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>
|
||||
public bool ContainsLed(Led led) => (led != null) && GroupLeds.Contains(led);
|
||||
public bool ContainsLed(Led led)
|
||||
{
|
||||
lock (GroupLeds)
|
||||
return (led != null) && GroupLeds.Contains(led);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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>
|
||||
public void MergeLeds(ILedGroup groupToMerge)
|
||||
{
|
||||
foreach (Led led in groupToMerge.GetLeds())
|
||||
if (!GroupLeds.Contains(led))
|
||||
GroupLeds.Add(led);
|
||||
lock (GroupLeds)
|
||||
foreach (Led led in groupToMerge.GetLeds())
|
||||
if (!GroupLeds.Contains(led))
|
||||
GroupLeds.Add(led);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -139,7 +146,11 @@ namespace RGB.NET.Groups
|
||||
/// Gets a list containing the <see cref="T:RGB.NET.Core.Led" /> from this group.
|
||||
/// </summary>
|
||||
/// <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
|
||||
}
|
||||
|
||||
@ -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" />.
|
||||
/// </summary>
|
||||
/// <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;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user