Skip to content

Commit

Permalink
use new lock class
Browse files Browse the repository at this point in the history
  • Loading branch information
diogotr7 committed Nov 23, 2024
1 parent cbf73e1 commit 66fd083
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/StarBreaker.Forge/DataForge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ public void Extract(string outputFolder, string? fileNameFilter = null, IProgres
var recordsByFileName = GetRecordsByFileName(fileNameFilter);
var total = recordsByFileName.Count;

var lockObj = new Lock();

Parallel.ForEach(recordsByFileName, kvp =>
{
var (fileName, record) = kvp;
Expand All @@ -89,7 +91,7 @@ public void Extract(string outputFolder, string? fileNameFilter = null, IProgres
ExtractSingleRecord(writer, record);
}

lock (recordsByFileName)
using (lockObj.EnterScope())
{
var currentProgress = Interlocked.Increment(ref progressValue);
//only report progress every 250 records and when we are done
Expand Down
4 changes: 2 additions & 2 deletions src/StarBreaker.P4k/P4kFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public void Extract(string outputDir, string? filter = null, IProgress<double>?

progress?.Report(0);

var lockObject = new object();
var lockObject = new Lock();

//TODO: Preprocessing step:
// 1. start with the list of total files
Expand All @@ -213,7 +213,7 @@ public void Extract(string outputDir, string? filter = null, IProgress<double>?
Interlocked.Increment(ref processedEntries);
if (processedEntries == numberOfEntries || processedEntries % fivePercent == 0)
{
lock (lockObject)
using (lockObject.EnterScope())
{
progress?.Report(processedEntries / (double)numberOfEntries);
}
Expand Down

0 comments on commit 66fd083

Please sign in to comment.