Browse Source
Merge pull request #1234 from SixLabors/js/fix-1230
Use ConcurrentDictionary for options properties.
pull/1574/head
Scott Williams
6 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with
22 additions and
6 deletions
-
src/ImageSharp/Configuration.cs
-
src/ImageSharp/GraphicOptionsDefaultsExtensions.cs
-
src/ImageSharp/Processing/DefaultImageProcessorContext{TPixel}.cs
-
tests/ImageSharp.Tests/GraphicOptionsDefaultsExtensionsTests.cs
-
tests/ImageSharp.Tests/Processing/FakeImageOperationsProvider.cs
|
|
|
@ -2,6 +2,7 @@ |
|
|
|
// Licensed under the Apache License, Version 2.0.
|
|
|
|
|
|
|
|
using System; |
|
|
|
using System.Collections.Concurrent; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Net.Http; |
|
|
|
using SixLabors.ImageSharp.Formats; |
|
|
|
@ -78,7 +79,7 @@ namespace SixLabors.ImageSharp |
|
|
|
/// Gets a set of properties for the Congiguration.
|
|
|
|
/// </summary>
|
|
|
|
/// <remarks>This can be used for storing global settings and defaults to be accessable to processors.</remarks>
|
|
|
|
public IDictionary<object, object> Properties { get; } = new Dictionary<object, object>(); |
|
|
|
public IDictionary<object, object> Properties { get; } = new ConcurrentDictionary<object, object>(); |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the currently registered <see cref="IImageFormat"/>s.
|
|
|
|
|
|
|
|
@ -71,11 +71,9 @@ namespace SixLabors.ImageSharp |
|
|
|
return go; |
|
|
|
} |
|
|
|
|
|
|
|
var configOptions = context.Configuration.GetGraphicsOptions(); |
|
|
|
|
|
|
|
// do not cache the fall back to config into the the processing context
|
|
|
|
// in case someone want to change the value on the config and expects it re trflow thru
|
|
|
|
return configOptions; |
|
|
|
return context.Configuration.GetGraphicsOptions(); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
@ -1,6 +1,7 @@ |
|
|
|
// Copyright (c) Six Labors.
|
|
|
|
// Licensed under the Apache License, Version 2.0.
|
|
|
|
|
|
|
|
using System.Collections.Concurrent; |
|
|
|
using System.Collections.Generic; |
|
|
|
using SixLabors.ImageSharp.PixelFormats; |
|
|
|
using SixLabors.ImageSharp.Processing.Processors; |
|
|
|
@ -41,7 +42,7 @@ namespace SixLabors.ImageSharp.Processing |
|
|
|
public Configuration Configuration { get; } |
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
public IDictionary<object, object> Properties { get; } = new Dictionary<object, object>(); |
|
|
|
public IDictionary<object, object> Properties { get; } = new ConcurrentDictionary<object, object>(); |
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
public Image<TPixel> GetResultImage() |
|
|
|
|
|
|
|
@ -1,7 +1,9 @@ |
|
|
|
// Copyright (c) Six Labors.
|
|
|
|
// Licensed under the Apache License, Version 2.0.
|
|
|
|
|
|
|
|
using System.Threading.Tasks; |
|
|
|
using SixLabors.ImageSharp.PixelFormats; |
|
|
|
using SixLabors.ImageSharp.Processing; |
|
|
|
using SixLabors.ImageSharp.Tests.Processing; |
|
|
|
using SixLabors.ImageSharp.Tests.TestUtilities; |
|
|
|
using Xunit; |
|
|
|
@ -168,5 +170,18 @@ namespace SixLabors.ImageSharp.Tests |
|
|
|
Assert.NotNull(options); |
|
|
|
Assert.IsType<GraphicsOptions>(options); |
|
|
|
} |
|
|
|
|
|
|
|
[Theory] |
|
|
|
[WithBlankImages(100, 100, PixelTypes.Rgba32)] |
|
|
|
public void CanGetGraphicsOptionsMultiThreaded<TPixel>(TestImageProvider<TPixel> provider) |
|
|
|
where TPixel : unmanaged, IPixel<TPixel> |
|
|
|
{ |
|
|
|
// Could not get fake operations to trigger #1230 so using a real image.
|
|
|
|
Parallel.For(0, 10, _ => |
|
|
|
{ |
|
|
|
using Image<TPixel> image = provider.GetImage(); |
|
|
|
image.Mutate(x => x.BackgroundColor(Color.White)); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -1,6 +1,7 @@ |
|
|
|
// Copyright (c) Six Labors.
|
|
|
|
// Licensed under the Apache License, Version 2.0.
|
|
|
|
|
|
|
|
using System.Collections.Concurrent; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Linq; |
|
|
|
using SixLabors.ImageSharp.PixelFormats; |
|
|
|
@ -56,7 +57,7 @@ namespace SixLabors.ImageSharp.Tests.Processing |
|
|
|
|
|
|
|
public Configuration Configuration { get; } |
|
|
|
|
|
|
|
public IDictionary<object, object> Properties { get; } = new Dictionary<object, object>(); |
|
|
|
public IDictionary<object, object> Properties { get; } = new ConcurrentDictionary<object, object>(); |
|
|
|
|
|
|
|
public Image<TPixel> GetResultImage() |
|
|
|
{ |
|
|
|
|