/// <summary> /// Add a task to the thread queue. When a thread is available, it will /// dequeue this task and run it. Once complete, the task will be marked /// complete, but your application won't be called back until the next /// time Update() is called (so that callbacks are from the main thread). /// </summary> /// <param name="function">The function to call within the thread.</param> /// <param name="completion">The callback to report results to, or null. If /// you care about which particular task has completed, use a different instance /// for this delegate per task (typically, a delegate on the task itself).</param> /// <param name="ctx">A previously allocated TaskContext, to allow for waiting /// on the task, or null. It cannot have been already used.</param> /// <returns>A Task identifier for the operation in question. Note: because /// of the threaded behavior, the task may have already completed when it /// is returned. However, if you AddTask() from the main thread, the completion /// function will not yet have been called.</returns> public Task AddTask(TaskFunction function, TaskComplete completion, TaskContext ctx) { if (function == null) { throw new System.ArgumentNullException("function"); } Worker w; lock (this) { if (disposed_) { throw new System.ObjectDisposedException("ParallelThreadPool"); } qDepth_++; w = NewWorker(function, completion); if (ctx != null) { ctx.Init(w); } if (workList_ == null) { workList_ = w; } else { workListEnd_.next_ = w; } workListEnd_ = w; } workEvent_.Set(); return(w); }
/// <summary> /// Add a task to the thread queue. When a thread is available, it will /// dequeue this task and run it. Once complete, the task will be marked /// complete, but your application won't be called back until the next /// time Update() is called (so that callbacks are from the main thread). /// </summary> /// <param name="function">The function to call within the thread.</param> /// <param name="completion">The callback to report results to, or null. If /// you care about which particular task has completed, use a different instance /// for this delegate per task (typically, a delegate on the task itself).</param> /// <param name="ctx">A previously allocated TaskContext, to allow for waiting /// on the task, or null. It cannot have been already used.</param> /// <returns>A Task identifier for the operation in question. Note: because /// of the threaded behavior, the task may have already completed when it /// is returned. However, if you AddTask() from the main thread, the completion /// function will not yet have been called.</returns> public ITask AddTask(TaskFunction function, TaskComplete completion, TaskContext ctx) { if (function == null) { throw new ArgumentNullException("function"); } Worker w; lock (this) { if (_disposed) { throw new ObjectDisposedException("ParallelThreadPool"); } _qDepth++; w = NewWorker(function, completion); if (ctx != null) { ctx.Init(w); } if (_workList == null) { _workList = w; } else { _workListEnd.Next = w; } _workListEnd = w; } _workEvent.Set(); return(w); }
public ITask AddTask(TaskFunction function, TaskComplete completion, TaskContext ctx) { //Just cycle to the next free one. lock (_nextThreadTargetLock) _nextThreadTarget = (ThreadTarget)(((int)(_nextThreadTarget) + 1) % _nThreads); return(AddTask(_nextThreadTarget, function, completion, ctx)); }
public void Schedule(TaskFunction Task) { lock (m_mtx) { m_queue.Enqueue(Task); Monitor.PulseAll(m_mtx); } }
private IQueue <int> CheckAndGet(TaskFunction taskFunction) { var functionReturn = taskFunction(null); functionReturn.Should().NotBeNull(); functionReturn.Should().BeAssignableTo <IQueue <int> >(); return((IQueue <int>)functionReturn); }
public static T GetSubject <T>(this TaskFunction taskFunction, params object[] parameters) { var functionReturn = taskFunction(parameters); functionReturn.Should().NotBeNull(); functionReturn.Should().BeAssignableTo <T>(); return((T)functionReturn); }
private IFileReader GetSubject(TaskFunction taskFunction) { var functionReturn = taskFunction(new[] { fileMock.Object }); functionReturn.Should().NotBeNull(); functionReturn.Should().BeAssignableTo <IFileReader>(); return((IFileReader)functionReturn); }
private IRemoteClient GetSubject(TaskFunction taskFunction) { var functionReturn = taskFunction(new[] { remoteServiceMock.Object }); functionReturn.Should().NotBeNull(); functionReturn.Should().BeAssignableTo <IRemoteClient>(); return((IRemoteClient)functionReturn); }
public void Test3_Unique(TaskFunction taskFunction) { var functionReturn = taskFunction(new object[] { "123456789" }); functionReturn.Should().BeOfType <int>(); var result = (int)functionReturn; result.Should().Be(1); }
public void Test2_TwoSequences(TaskFunction taskFunction) { var functionReturn = taskFunction(new object[] { "12333444456" }); functionReturn.Should().BeOfType <int>(); var result = (int)functionReturn; result.Should().Be(4); }
public void Test1_FirstNameLastNameProvided(TaskFunction taskFunction) { var functionReturn = taskFunction(new object[] { "eugene levchenkov" }); functionReturn.Should().BeOfType <string>(); var result = (string)functionReturn; result.Should().Be("Eugene L."); }
public void Test2_NonUniqueString(TaskFunction taskFunction) { var functionReturn = taskFunction(new object[] { "121459789", '1', '9' }); functionReturn.Should().BeOfType <int>(); var result = (int)functionReturn; result.Should().Be(8); }
public void Test1_Simple(TaskFunction taskFunction) { var functionReturn = taskFunction(new object[] { "12333456" }); functionReturn.Should().BeOfType <int>(); var result = (int)functionReturn; result.Should().Be(3); }
public void Test2_StringDoesNotContainFinishChar(TaskFunction taskFunction) { var functionReturn = taskFunction(new object[] { "121459789", '1', 'b' }); functionReturn.Should().BeOfType <int>(); var result = (int)functionReturn; result.Should().Be(0); }
public void Test1_SsnProvided(TaskFunction taskFunction) { var functionReturn = taskFunction(new object[] { "123456789" }); functionReturn.Should().BeOfType <string>(); var result = (string)functionReturn; result.Should().Be("*****6789"); }
public void Test2_AllTheSame(TaskFunction taskFunction) { var functionReturn = taskFunction(new object[] { new[] { 1, 1, 1, 1 } }); functionReturn.Should().BeOfType <int[]>(); var result = (int[])functionReturn; result.Should().HaveCount(0); }
public void Test1_EmailProvided(TaskFunction taskFunction) { var functionReturn = taskFunction(new object[] { "*****@*****.**" }); functionReturn.Should().BeOfType <string>(); var result = (string)functionReturn; result.Should().Be("e*****@yandex.by"); }
public Form01() { InitializeComponent(); textBoxDelta.Text = delta.ToString(); taskFuntions = new TaskFunction[3]; taskFuntions[0] = new TaskFunction(Task1); taskFuntions[1] = new TaskFunction(Task3); taskFuntions[2] = new TaskFunction(Task9); }
public void Test1_EmptyData_ShouldBeSuccess(TaskFunction taskFunction) { remoteServiceMock.Setup(x => x.SendData(It.IsAny <string>())).Throws <Exception>(); var subject = GetSubject(taskFunction); var result = subject.SendData(Array.Empty <string>()); result.Should().NotBeNull("Should be an object"); result.IsSuccess.Should().BeTrue("Should be success."); }
public void Test3_Sequence(TaskFunction taskFunction) { var functionReturn = taskFunction(new object[] { new[] { 1, 1, 2, 3, 4, 1, 2, 4 } }); functionReturn.Should().BeOfType <int[]>(); var result = (int[])functionReturn; result.Should().HaveCount(1); result.Should().Contain(3); }
public void Test1(TaskFunction taskFunction) { var functionReturn = taskFunction(new object[] { new List <int> { 1, 2, 3 } }); functionReturn.Should().BeOfType <List <int> >(); var result = (List <int>)functionReturn; result.Should().ContainInOrder(3, 2, 1); }
public void Test3_Logout_UserNameProvided(TaskFunction taskFunction) { var functionReturn = taskFunction(new object[] { loggerMock.Object, userRepositoryMock.Object }); functionReturn.Should().NotBeNull(); functionReturn.Should().BeAssignableTo <IUserManager>(); var manager = (IUserManager)functionReturn; manager.Logout("First"); loggerMock.Verify(x => x.LogInfo(It.IsAny <string>())); }
public void Test1_OnePushOnePop_ShouldBeEmpty(TaskFunction taskFunction) { var queue = CheckAndGet(taskFunction); queue.IsEmpty.Should().BeTrue("Initialized collection should be empty."); queue.Count.Should().Be(0, "Initialized collection should have count 0."); queue.Enqueue(1); queue.Peek().Should().Be(1, "Enqueue element 1, Peek should return 1."); queue.Dequeue().Should().Be(1, "Enqueue element 1, Dequeue should return 1."); queue.IsEmpty.Should().BeTrue("Enqueue element 1, Denqueue element 1. Collection should be empty."); queue.Count.Should().Be(0, "Enqueue element 1, Denqueue element 1. Collection should have count 0."); }
public void Test1(TaskFunction taskFunction) { var subject = taskFunction.GetSubject <int[][]>(2); subject.Should().NotBeNull(); var line = subject[0]; line.Should().BeEquivalentTo(new[] { 1, 2 }); line = subject[1]; line.Should().BeEquivalentTo(new[] { 0, 1 }); }
public void Test1_OnePushOnePop_ShouldBeEmpty(TaskFunction taskFunction) { var queue = CheckAndGet(taskFunction); queue.IsEmpty.Should().BeTrue(); queue.Count.Should().Be(0); queue.Enqueue(1); queue.Peek().Should().Be(1); queue.Dequeue().Should().Be(1); queue.IsEmpty.Should().BeTrue(); queue.Count.Should().Be(0); }
private IList <TestResult> RunTests(Exercise exercise, TaskFunction taskFunction) { var assemblyName = "TaskChecker.Tests"; var testNames = GetTestNames(exercise); var testRunner = new TestRunner(assemblyName); var result = new List <TestResult>(); foreach (var testName in testNames) { result.AddRange(testRunner.Run(testName, taskFunction)); } return(result); }
public void Test1(TaskFunction taskFunction) { var matrix = new [, ] { { 1, 2, 3, 4 }, { 1, 2, 3, 4 }, { 1, 2, 3, 4 }, { 1, 2, 3, 4 }, }; var subject = taskFunction.GetSubject <IMatrix>(matrix); subject.MainDiagonal.Should().BeEquivalentTo(new[] { 1, 2, 3, 4 }); subject.SideDiagonal.Should().BeEquivalentTo(new [] { 1, 2, 3, 4 }); }
public void Test2(TaskFunction taskFunction) { var matrix = new[, ] { { 1, 2, 3, 9 }, { 1, 4, 8, 10 }, { 5, 7, 11, 14 }, { 6, 12, 13, 15 }, }; var subject = taskFunction.GetSubject <IMatrix>(matrix); subject.MainDiagonal.Should().BeEquivalentTo(new[] { 1, 4, 11, 15 }); subject.SideDiagonal.Should().BeEquivalentTo(new[] { 6, 7, 8, 9 }); }
Worker NewWorker(TaskFunction tf, TaskComplete tc) { if (freeList_ == null) { freeList_ = new Worker(null, null); } Worker ret = freeList_; freeList_ = ret.next_; ret.function_ = tf; ret.completion_ = tc; ret.context_ = null; ret.error_ = null; ret.next_ = null; return(ret); }
public void Test2_LoginWithFalsePassword_ShouldNotLogin(TaskFunction taskFunction) { userRepositoryMock .Setup(x => x.CheckPassword(It.IsAny <string>(), It.IsAny <string>())) .Returns(false); var functionReturn = taskFunction(new object[] { loggerMock.Object, userRepositoryMock.Object }); functionReturn.Should().NotBeNull(); functionReturn.Should().BeAssignableTo <IUserManager>(); var manager = (IUserManager)functionReturn; manager.Login("First", "qwaszx@1"); loggerMock.Verify(x => x.LogError(It.IsAny <string>())); }
/// <summary> /// Add a task to the thread queue. When a thread is available, it will /// dequeue this task and run it. Once complete, the task will be marked /// complete, but your application won't be called back until the next /// time Update() is called (so that callbacks are from the main thread). /// </summary> /// <param name="function">The function to call within the thread.</param> /// <param name="completion">The callback to report results to, or null. If /// you care about which particular task has completed, use a different instance /// for this delegate per task (typically, a delegate on the task itself).</param> /// <param name="ctx">A previously allocated TaskContext, to allow for waiting /// on the task, or null. It cannot have been already used.</param> /// <returns>A Task identifier for the operation in question. Note: because /// of the threaded behavior, the task may have already completed when it /// is returned. However, if you AddTask() from the main thread, the completion /// function will not yet have been called.</returns> public Task AddTask(TaskFunction function, TaskComplete completion, TaskContext ctx, object argument) { if (function == null) throw new System.ArgumentNullException("function"); Worker w; lock (this) { if (disposed_) throw new System.ObjectDisposedException("ParallelThreadPool"); qDepth_++; w = NewWorker(function, completion, argument); if (ctx != null) ctx.Init(w); if (workList_ == null) workList_ = w; else workListEnd_.next_ = w; workListEnd_ = w; } workEvent_.Set(); return w; }
Worker NewWorker(TaskFunction tf, TaskComplete tc, object argument) { if (freeList_ == null) freeList_ = new Worker(null, null); Worker ret = freeList_; freeList_ = ret.next_; ret.function_ = tf; ret.completion_ = tc; ret.context_ = null; ret.error_ = null; ret.next_ = null; ret.argument = argument; return ret; }
internal Worker(TaskFunction function, TaskComplete completion) { function_ = function; completion_ = completion; error_ = null; }
public static TaskHandle CreateTask(object self, TaskFunction fn, TaskCallback Callback, TaskPriority priority, string name) { Task t = new Task(self, fn, Callback, priority, name); return var.Cast<int, TaskHandle>(t.Id); }
public static extern TaskHandle CreateTask(object self, TaskFunction fn, TaskCallback Callback, TaskPriority priority, string name);