Skip to content

Commit

Permalink
Make TempRoot thread-safe
Browse files Browse the repository at this point in the history
  • Loading branch information
khyperia committed Dec 1, 2017
1 parent 23ca701 commit d641eaa
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 19 deletions.
10 changes: 3 additions & 7 deletions src/Compilers/Server/VBCSCompilerTests/CompilerServerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,14 @@ private static void ReferenceNetstandardDllIfCoreClr(List<string> arguments)
#endif
}

private static readonly object s_createFilesLock = new object();
private static void CreateFiles(TempDirectory currentDirectory, IEnumerable<KeyValuePair<string, string>> files)
{
if (files != null)
{
lock (s_createFilesLock)
foreach (var pair in files)
{
foreach (var pair in files)
{
TempFile file = currentDirectory.CreateFile(pair.Key);
file.WriteAllText(pair.Value);
}
TempFile file = currentDirectory.CreateFile(pair.Key);
file.WriteAllText(pair.Value);
}
}
}
Expand Down
15 changes: 3 additions & 12 deletions src/Test/Utilities/Portable/TempFiles/TempRoot.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Collections.Generic;
using System.Collections.Concurrent;
using System.IO;
using System.Runtime.CompilerServices;

namespace Microsoft.CodeAnalysis.Test.Utilities
{
public sealed class TempRoot : IDisposable
{
private readonly List<IDisposable> _temps = new List<IDisposable>();
private readonly ConcurrentBag<IDisposable> _temps = new ConcurrentBag<IDisposable>();
public static readonly string Root;

static TempRoot()
Expand All @@ -20,16 +20,7 @@ static TempRoot()

public void Dispose()
{
if (_temps != null)
{
DisposeAll(_temps);
_temps.Clear();
}
}

private static void DisposeAll(IEnumerable<IDisposable> temps)
{
foreach (var temp in temps)
while (_temps.TryTake(out var temp))
{
try
{
Expand Down

0 comments on commit d641eaa

Please sign in to comment.