public static bool SetProxyScheduler(this Task task, IProxyScheduler proxyScheduler) { if (task == null) { throw new ArgumentNullException(nameof(task)); } if (proxyScheduler == null) { throw new ArgumentNullException(nameof(proxyScheduler)); } return(_taskSchedulerExternalProxyService.AddTaskProxySchedulerPair(task, proxyScheduler)); }
private void init(TaskScheduler controlScheduler, int maxTasksConcurrency) { if (maxTasksConcurrency <= 0) { throw new ArgumentOutOfRangeException(nameof(maxTasksConcurrency)); } m_maxConcurrentTaskBatch = Math.Min(CONCURRENT_TASK_BATCH_LIMIT, maxTasksConcurrency); m_exclusiveTaskAdded = new ThreadSafeSwitch(); m_concurrentTaskAdded = new ThreadSafeSwitch(); m_ownControlTaskScheduler = (controlScheduler == null); if (m_ownControlTaskScheduler) { var ioControlService = new IoServiceScheduler(); m_ioControlScheduler = new IoServiceThreadPoolScheduler(ioControlService, CONTROL_SCHEDULER_CONCURRENCY); var controlProxyScheduler = new ProxyScheduler(m_ioControlScheduler); m_controlTaskFactory = new TaskFactory(controlProxyScheduler.AsTplScheduler()); } else { m_controlTaskFactory = new TaskFactory(controlScheduler); } var ioService = new IoServiceScheduler(); m_threadPoolScheduler = new IoServiceThreadPoolScheduler(ioService, maxTasksConcurrency); m_concurrentAccumulateScheduler = new AccumulateTasksSchedulerDecorator(m_threadPoolScheduler, _ => taskAdded(m_concurrentTaskAdded)); var strandScheduler = new StrandSchedulerDecorator(m_threadPoolScheduler); var innerStrandProxyScheduler = new ProxyScheduler(strandScheduler); m_strandAccumulateScheduler = new AccumulateTasksSchedulerDecorator(strandScheduler, _ => taskAdded(m_exclusiveTaskAdded)); m_strandProxyScheduler = new ProxyScheduler(m_strandAccumulateScheduler); m_concurrentProxyScheduler = new ProxyScheduler(m_concurrentAccumulateScheduler); m_processTaskLoop = null; m_completedTcs = new TaskCompletionSource <Object>(); m_stopCts = new CancellationTokenSource(); m_isDisposed = false; }
public bool AddTaskProxySchedulerPair(Task task, IProxyScheduler scheduler) { if (task == null) { throw new ArgumentNullException(nameof(task)); } if (scheduler == null) { throw new ArgumentNullException(nameof(scheduler)); } var schedulerAssociatedNow = false; m_taskSchedulerDictionary.GetValue(task, _ => { schedulerAssociatedNow = true; return(scheduler); }); return(schedulerAssociatedNow); }
public override void InitializeTest() { m_scheduler = new CurrentThreadScheduler(); m_proxyScheduler = new ProxyScheduler(m_scheduler); base.InitializeTest(); }