Add unbounded task scheduler for divisor testing
This commit is contained in:
1 parent
c4e56bf753
commit
70637c3fba
2 files changed
+36
-1
No files matched your search
@@ -0,0 +1,34 @@
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PerfectNumbers.Core;
|
||||
|
||||
public sealed class UnboundedTaskScheduler : TaskScheduler
|
||||
{
|
||||
public static UnboundedTaskScheduler Instance { get; } = new();
|
||||
|
||||
private UnboundedTaskScheduler()
|
||||
{
|
||||
}
|
||||
|
||||
public override int MaximumConcurrencyLevel => int.MaxValue;
|
||||
|
||||
protected override void QueueTask(Task task)
|
||||
{
|
||||
ThreadPool.UnsafeQueueUserWorkItem(static state =>
|
||||
{
|
||||
(UnboundedTaskScheduler Scheduler, Task Task) tuple = ((UnboundedTaskScheduler, Task))state!;
|
||||
tuple.Scheduler.TryExecuteTask(tuple.Task);
|
||||
}, (this, task));
|
||||
}
|
||||
|
||||
protected override bool TryExecuteTaskInline(Task task, bool taskWasPreviouslyQueued)
|
||||
{
|
||||
return TryExecuteTask(task);
|
||||
}
|
||||
|
||||
protected override IEnumerable<Task>? GetScheduledTasks()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user