Skip to content

Commit

Permalink
Slight tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
metalgearsloth committed Nov 21, 2023
1 parent a99b718 commit 7e9168e
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions Robust.Shared/Threading/ParallelManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,13 @@ private void UpdateCVar(int value)
{
ParallelCountChanged?.Invoke();

// TODO: Need to check this / not sure what to do.
ThreadPool.SetMaxThreads(ParallelProcessCount, oldCompletion);
}
}

public Task Process(IRobustJob job)
{
// TODO: Does this have a race condition where it returns too early maybe?
// I think it would be better with a TCS.
var wrapper = new JobWrapper(job);
ThreadPool.UnsafeQueueUserWorkItem(wrapper, false);
return wrapper.Tcs.Task;
Expand Down Expand Up @@ -111,9 +110,10 @@ public Task[] Process(IParallelRobustJob job, int amount)
/// </summary>
private readonly record struct JobWrapper : IThreadPoolWorkItem
{
private readonly IRobustJob _job;
public readonly TaskCompletionSource Tcs = new();

private readonly IRobustJob _job;

public JobWrapper(IRobustJob job)
{
_job = job;
Expand All @@ -131,22 +131,22 @@ public void Execute()
/// </summary>
private readonly record struct ParallelJobWrapper : IThreadPoolWorkItem
{
private readonly IParallelRobustJob _job;
public readonly TaskCompletionSource Tcs = new();

public readonly int Start;
public readonly int End;
private readonly IParallelRobustJob _job;
private readonly int _start;
private readonly int _end;

public ParallelJobWrapper(IParallelRobustJob job, int start, int end)
{
_job = job;
Start = start;
End = end;
_start = start;
_end = end;
}

public void Execute()
{
for (var i = Start; i < End; i++)
for (var i = _start; i < _end; i++)
{
_job.Execute(i);
}
Expand Down

0 comments on commit 7e9168e

Please sign in to comment.