Makes AllPlugins single tone thread safe (#10121)

This commit is contained in:
Mykhailo Pylyp 2021-03-09 18:31:30 +02:00 committed by GitHub
parent 38eb6ad062
commit 964286ab99
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 2 deletions

View File

@ -24,6 +24,7 @@ namespace PowerLauncher.Plugin
{
private static readonly IFileSystem FileSystem = new FileSystem();
private static readonly IDirectory Directory = FileSystem.Directory;
private static readonly object AllPluginsLock = new object();
private static IEnumerable<PluginPair> _contextMenuPlugins = new List<PluginPair>();
@ -44,7 +45,13 @@ namespace PowerLauncher.Plugin
{
if (_allPlugins == null)
{
_allPlugins = PluginsLoader.Plugins(PluginConfig.Parse(Directories));
lock (AllPluginsLock)
{
if (_allPlugins == null)
{
_allPlugins = PluginsLoader.Plugins(PluginConfig.Parse(Directories));
}
}
}
return _allPlugins;

View File

@ -27,7 +27,9 @@ namespace PowerLauncher.Plugin
public static IEnumerable<PluginPair> CSharpPlugins(List<PluginMetadata> source)
{
var plugins = new List<PluginPair>();
var metadatas = source.Where(o => o.Language.ToUpperInvariant() == AllowedLanguage.CSharp);
var metadatas = source
.Where(o => o.Language.ToUpperInvariant() == AllowedLanguage.CSharp)
.ToList();
foreach (var metadata in metadatas)
{