Skip to content

Commit

Permalink
refactor runners
Browse files Browse the repository at this point in the history
  • Loading branch information
sicusa committed Feb 24, 2024
1 parent 1e6c4b4 commit 322461e
Show file tree
Hide file tree
Showing 8 changed files with 156 additions and 124 deletions.
4 changes: 2 additions & 2 deletions Sia/Entities/Extensions/EntityHostExtensions.Handle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static unsafe void Handle<TRunner>(

runner.Run(count, new(host, handler), static (in HandleData data, (int, int) range) => {
data.Handler(data.Host, range.Item1, range.Item2);
});
}).WaitAndReturn();
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand All @@ -32,7 +32,7 @@ public static unsafe void Handle<TRunner, TData>(

runner.Run(count, new(host, userData, handler), static (in HandleData<TData> data, (int, int) range) => {
data.Handler(data.Host, data.UserData, range.Item1, range.Item2);
});
}).WaitAndReturn();
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand Down
4 changes: 2 additions & 2 deletions Sia/Entities/Extensions/EntityQueryExtensions.Handle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static unsafe void Handle<TRunner>(
slotIndex = 0;
}
}
});
}).WaitAndReturn();
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand Down Expand Up @@ -93,7 +93,7 @@ public static unsafe void Handle<TRunner, TData>(
host = hosts[++hostIndex];
slotIndex = 0;
}
});
}).WaitAndReturn();
}

#region CurrentThreadRunner
Expand Down
24 changes: 20 additions & 4 deletions Sia/Runners/CurrentThreadRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,32 @@ public sealed class CurrentThreadRunner : IRunner
private CurrentThreadRunner() {}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Run(Action action) => action();
public IRunnerBarrier Run(Action action)
{
action();
return RunnerBarriers.Empty;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Run<TData>(in TData data, InAction<TData> action) => action(data);
public IRunnerBarrier Run<TData>(in TData data, InAction<TData> action)
{
action(data);
return RunnerBarriers.Empty;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Run(int taskCount, GroupAction action) => action((0, taskCount));
public IRunnerBarrier Run(int taskCount, GroupAction action)
{
action((0, taskCount));
return RunnerBarriers.Empty;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Run<TData>(int taskCount, in TData data, GroupAction<TData> action) => action(data, (0, taskCount));
public IRunnerBarrier Run<TData>(int taskCount, in TData data, GroupAction<TData> action)
{
action(data, (0, taskCount));
return RunnerBarriers.Empty;
}

public void Dispose() {}
}
2 changes: 1 addition & 1 deletion Sia/Runners/Interfaces/IJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ namespace Sia;

public interface IJob
{
void Throw(Exception e);
IRunnerBarrier Barrier { get; }
void Invoke();
}
8 changes: 4 additions & 4 deletions Sia/Runners/Interfaces/IRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ namespace Sia;

public interface IRunner : IDisposable
{
void Run(Action action);
void Run<TData>(in TData data, InAction<TData> action);
void Run(int taskCount, GroupAction action);
void Run<TData>(int taskCount, in TData data, GroupAction<TData> action);
IRunnerBarrier Run(Action action);
IRunnerBarrier Run<TData>(in TData data, InAction<TData> action);
IRunnerBarrier Run(int taskCount, GroupAction action);
IRunnerBarrier Run<TData>(int taskCount, in TData data, GroupAction<TData> action);
}
10 changes: 10 additions & 0 deletions Sia/Runners/Interfaces/IRunnerBarrier.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Sia;

public interface IRunnerBarrier
{
Exception? Exception { get; }

void Signal();
void Throw(Exception e);
void WaitAndReturn();
}
Loading

0 comments on commit 322461e

Please sign in to comment.