This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public virtual int PollOne() | |
{ | |
checkIfDisposed(); | |
return runTasks(withoutCancelToken(), maxTasks: POLLONE_RUNONE_MAX_TASKS); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public virtual int Poll() | |
{ | |
checkIfDisposed(); | |
return runTasks(withoutCancelToken()); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public const int POLLONE_RUNONE_MAX_TASKS = 1; | |
public virtual int RunOne() | |
{ | |
checkIfDisposed(); | |
return runTasks(withGlobalCancelToken(), POLLONE_RUNONE_MAX_TASKS); | |
} | |
private CancellationToken withGlobalCancelToken() | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Unsafe test | |
[TestMethod] | |
public void RunOne_When_Zero_Tasks_Then_Method_Does_Not_Return() | |
{ | |
const int SCHEDULE_WORK_AFTER_MS = 3000; | |
const double RUN_MIN_DURATION_S = 2.0; | |
var time = StopWatchUtils.MeasureActionTime(() => | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[TestMethod] | |
public void RunOne_When_More_Tasks_Added_Then_Only_First_Task_Is_Executed() | |
{ | |
bool wasTask1Called = false; | |
bool wasTask2Called = false; | |
m_scheduler.Dispatch(() => | |
{ | |
wasTask1Called = true; | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.... | |
catch (OperationCanceledException e) | |
{ | |
Trace.WriteLine(e); | |
if (m_stopCancelTokenSource.IsCancellationRequested) | |
{ | |
break; | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private int runTasksCore(CancellationToken cancellationToken) | |
{ | |
bool searchForTask = true; | |
var usedCancellationToken = cancellationToken; | |
var serviceData = m_isServiceThreadFlags.Value; | |
while (searchForTask) | |
{ | |
searchForTask = false; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private int runTasks(CancellationToken cancellationToken, int maxTasks = UNLIMITED_MAX_TASKS) | |
{ | |
try | |
{ | |
setCurrentThreadAsServiceAllFlags(maxTasks); | |
return runTasksCore(cancellationToken); | |
} | |
finally | |
{ | |
resetThreadAsServiceAllFlags(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public virtual int Run() | |
{ | |
checkIfDisposed(); | |
return runTasks(withWorkCancelToken()); | |
} | |
private CancellationToken withWorkCancelToken() | |
{ | |
lock (m_workLockObject) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[TestMethod] | |
public async Task Run_When_Called_From_Multiple_Threads_Then_All_Tasks_Executed() | |
{ | |
const int NUMBER_OF_SCHEDULED_TASKS = 100; | |
const int DEFAULT_TASK_SLEEP = 100; | |
const int NUMBER_OF_WORKER_THREAD = 3; | |
var countDownEvent = new CountdownEvent(NUMBER_OF_WORKER_THREAD); | |
int executedTasks = 0; |