Skip to content

Commit

Permalink
Makes AllPlugins single tone thread safe (#10121)
Browse files Browse the repository at this point in the history
  • Loading branch information
mykhailopylyp committed Mar 9, 2021
1 parent 38eb6ad commit 964286a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/modules/launcher/PowerLauncher/Plugin/PluginManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public static class PluginManager
{
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>();

Expand All @@ -44,7 +45,13 @@ public static List<PluginPair> AllPlugins
{
if (_allPlugins == null)
{
_allPlugins = PluginsLoader.Plugins(PluginConfig.Parse(Directories));
lock (AllPluginsLock)
{
if (_allPlugins == null)
{
_allPlugins = PluginsLoader.Plugins(PluginConfig.Parse(Directories));
}
}
}

return _allPlugins;
Expand Down
4 changes: 3 additions & 1 deletion src/modules/launcher/PowerLauncher/Plugin/PluginsLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ public static List<PluginPair> Plugins(List<PluginMetadata> metadatas)
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)
{
Expand Down

0 comments on commit 964286a

Please sign in to comment.