Skip to content

Commit

Permalink
chore: disable parallelization when debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
ovska committed Jun 12, 2024
1 parent 0e6f789 commit 349c4d1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
9 changes: 9 additions & 0 deletions Pack3r.Core/Global.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,13 @@ public static void EnsureQPathLength(ReadOnlyMemory<char> path)
public static string GetVersion() => typeof(Global).Assembly.GetName().Version?.ToString(3) ?? "?.?.?";

public static string Disclaimer() => $"// Modified by Pack3r {GetVersion()}";

public static ParallelOptions ParallelOptions(CancellationToken cancellationToken)
{
return new ParallelOptions
{
MaxDegreeOfParallelism = Debugger.IsAttached ? 1 : -1,
CancellationToken = cancellationToken,
};
}
}
2 changes: 1 addition & 1 deletion Pack3r.Core/Parsers/ShaderParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class ShaderParser(

using (var progress = progressManager.Create("Parsing shader files", max: null))
{
await Parallel.ForEachAsync(map.AssetSources, cancellationToken, async (source, ct) =>
await Parallel.ForEachAsync(map.AssetSources, Global.ParallelOptions(cancellationToken), async (source, ct) =>
{
var whitelist = whitelistsBySource.GetValueOrDefault(source);
Expand Down
2 changes: 1 addition & 1 deletion Pack3r.Core/Services/AssetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ private async Task ParseResources(Map map, CancellationToken cancellationToken)
// Parse resources referenced by map/mapscript/soundscript/speakerscript in parallel
ConcurrentDictionary<Resource, object?> referencedResources = [];

await Parallel.ForEachAsync(resourceParsers, cancellationToken, async (parser, ct) =>
await Parallel.ForEachAsync(resourceParsers, Global.ParallelOptions(cancellationToken), async (parser, ct) =>
{
string path = parser.GetPath(map);
Expand Down

0 comments on commit 349c4d1

Please sign in to comment.