-
Notifications
You must be signed in to change notification settings - Fork 388
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make MarkExecuted method thread safe
- Loading branch information
Showing
3 changed files
with
15 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,37 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
|
||
using Coverlet.Core.Attributes; | ||
using Coverlet.Core.Extensions; | ||
|
||
namespace Coverlet.Core | ||
{ | ||
public static class CoverageTracker | ||
{ | ||
private static Dictionary<string, List<string>> _markers; | ||
private static bool _registered; | ||
|
||
[ExcludeFromCoverage] | ||
public static void MarkExecuted(string path, string marker) | ||
static CoverageTracker() | ||
{ | ||
if (_markers == null) | ||
{ | ||
_markers = new Dictionary<string, List<string>>(); | ||
} | ||
|
||
if (!_markers.ContainsKey(path)) | ||
{ | ||
_markers.Add(path, new List<string>()); | ||
} | ||
_markers = new Dictionary<string, List<string>>(); | ||
AppDomain.CurrentDomain.ProcessExit += new EventHandler(CurrentDomain_ProcessExit); | ||
} | ||
|
||
if (!_registered) | ||
[ExcludeFromCoverage] | ||
public static void MarkExecuted(string path, string marker) | ||
{ | ||
lock (_markers) | ||
{ | ||
AppDomain.CurrentDomain.ProcessExit += new EventHandler(CurrentDomain_ProcessExit); | ||
_registered = true; | ||
_markers.TryAdd(path, new List<string>()); | ||
_markers[path].Add(marker); | ||
} | ||
|
||
_markers[path].Add(marker); | ||
} | ||
|
||
public static void CurrentDomain_ProcessExit(object sender, EventArgs e) | ||
{ | ||
foreach (var kvp in _markers) | ||
{ | ||
File.WriteAllLines(kvp.Key, kvp.Value); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters