Skip to content

Commit 09180c6

Browse files
committed
Merge pull request #20 from killswtch/ThreadSafety
Thread safety
2 parents 68bc49c + d49b662 commit 09180c6

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

Hudl.Ffmpeg/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@
3535
// You can specify all the values or you can default the Build and Revision Numbers
3636
// by using the '*' as shown below:
3737
// [assembly: AssemblyVersion("1.0.*")]
38-
[assembly: AssemblyInformationalVersion("2.1.3.0")]
39-
[assembly: AssemblyFileVersion("2.1.3.0")]
38+
[assembly: AssemblyInformationalVersion("2.1.4.0")]
39+
[assembly: AssemblyFileVersion("2.1.4.0")]
4040
[assembly: AssemblyVersion("1.0.0.0")]

Hudl.Ffmpeg/Resources/Resource.cs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace Hudl.FFmpeg.Resources
1111
/// </summary>
1212
public class Resource
1313
{
14+
private static readonly object AllTypesLock = new object();
1415
private static readonly List<Type> AllTypes = new List<Type>();
1516

1617
/// <summary>
@@ -78,18 +79,21 @@ public static IContainer From(string fullPath)
7879
private static IContainer From(string filePath, string fileName)
7980
{
8081
var fileExtension = Helpers.GetExtensionFromFullName(fileName);
81-
if (AllTypes.Count == 0)
82-
{
83-
AllTypes.AddRange(GetTypes<IContainer>());
84-
}
82+
lock (AllTypesLock)
83+
{
84+
if (AllTypes.Count == 0)
85+
{
86+
AllTypes.AddRange(GetTypes<IContainer>());
87+
}
88+
}
8589

86-
var correcTContainer = AllTypes.FirstOrDefault(t => t.Name.ToUpper() == fileExtension.ToUpper());
87-
if (correcTContainer == null)
90+
var correctContainer = AllTypes.FirstOrDefault(t => t.Name.ToUpper() == fileExtension.ToUpper());
91+
if (correctContainer == null)
8892
{
8993
throw new InvalidOperationException("Cannot derive resource type from path provided.");
9094
}
9195

92-
var newInstance = (IContainer)Activator.CreateInstance(correcTContainer);
96+
var newInstance = (IContainer)Activator.CreateInstance(correctContainer);
9397
newInstance.Path = filePath;
9498
newInstance.Name = fileName;
9599
return newInstance;

0 commit comments

Comments
 (0)