Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions tests/ImageSharp.Tests/TestFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ public sealed class TestFile
/// <summary>
/// The image (lazy initialized value)
/// </summary>
private Image<Rgba32> image;
private volatile Image<Rgba32> image;

/// <summary>
/// Used to ensure image loading is threadsafe.
/// </summary>
private readonly object syncLock = new();

/// <summary>
/// The image bytes
Expand Down Expand Up @@ -65,7 +70,21 @@ public sealed class TestFile
/// <summary>
/// Gets the image with lazy initialization.
/// </summary>
private Image<Rgba32> Image => this.image ??= ImageSharp.Image.Load<Rgba32>(this.Bytes);
private Image<Rgba32> Image
{
get
{
if (this.image is null)
{
lock (this.syncLock)
{
this.image ??= ImageSharp.Image.Load<Rgba32>(this.Bytes);
}
}

return this.image;
}
}

/// <summary>
/// Gets the input image directory.
Expand Down