Skip to content

Commit

Permalink
a
Browse files Browse the repository at this point in the history
  • Loading branch information
metalgearsloth committed Nov 22, 2023
1 parent 21ed429 commit 2ecc72c
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions Robust.Shared/Threading/ParallelManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public interface IParallelManager
/// Takes in a job that gets flushed.
/// </summary>
/// <param name="job"></param>
JobHandle Process(IRobustJob job);
ValueTask Process(IRobustJob job);

/// <summary>
/// Takes in a parallel job and runs it the specified amount.
Expand All @@ -38,7 +38,7 @@ public interface IParallelManager
/// <summary>
/// Takes in a parallel job and runs it without blocking.
/// </summary>
JobHandle Process(IParallelRobustJob jobs, int amount);
ValueTask Process(IParallelRobustJob jobs, int amount);

/// <summary>
/// Waits for the specified job handles to finish.
Expand All @@ -64,6 +64,10 @@ public void Initialize()
{
_cfg.OnValueChanged(CVars.ThreadParallelCount, UpdateCVar, true);

// TODO: Finish porting the other big parallel methods.
// TODO: Try using ValueTask returns and see if it's okay.
// If it is then try swapping JobScheduler back out for Threadpool

_scheduler = new JobScheduler(new JobScheduler.Config()
{
ThreadCount = ParallelProcessCount,
Expand All @@ -89,7 +93,7 @@ private void UpdateCVar(int value)
}
}

public JobHandle Process(IRobustJob job)
public ValueTask Process(IRobustJob job)
{
var handle = _scheduler.Schedule(job);
_scheduler.Flush();
Expand All @@ -99,7 +103,7 @@ public JobHandle Process(IRobustJob job)
public void ProcessNow(IParallelRobustJob job, int amount)
{
var handle = Process(job, amount);
handle.Complete();
handle.AsTask().Wait();
}

public void ProcessSerialNow(IParallelRobustJob jobs, int amount)
Expand All @@ -110,7 +114,7 @@ public void ProcessSerialNow(IParallelRobustJob jobs, int amount)
}
}

public JobHandle Process(IParallelRobustJob job, int amount)
public ValueTask Process(IParallelRobustJob job, int amount)
{
var handle = _scheduler.Schedule(job, amount);
_scheduler.Flush();
Expand Down

0 comments on commit 2ecc72c

Please sign in to comment.