Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore WAKEUP_TASK in SingleThreadEventExecutor.PollTask #522

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 22 additions & 17 deletions src/DotNetty.Common/Concurrency/SingleThreadEventExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -489,31 +489,36 @@ IRunnable PollTask()
{
Contract.Assert(this.InEventLoop);

IRunnable task;
if (!this.taskQueue.TryDequeue(out task))
while (true)
{
this.emptyEvent.Reset();
if (!this.taskQueue.TryDequeue(out task) && !this.IsShuttingDown) // revisit queue as producer might have put a task in meanwhile
IRunnable task;
if (!this.taskQueue.TryDequeue(out task))
{
IScheduledRunnable nextScheduledTask = this.ScheduledTaskQueue.Peek();
if (nextScheduledTask != null)
this.emptyEvent.Reset();
if (!this.taskQueue.TryDequeue(out task) && !this.IsShuttingDown) // revisit queue as producer might have put a task in meanwhile
{
PreciseTimeSpan wakeupTimeout = nextScheduledTask.Deadline - PreciseTimeSpan.FromStart;
if (wakeupTimeout.Ticks > 0)
IScheduledRunnable nextScheduledTask = this.ScheduledTaskQueue.Peek();
if (nextScheduledTask != null)
{
double timeout = wakeupTimeout.ToTimeSpan().TotalMilliseconds;
this.emptyEvent.Wait((int)Math.Min(timeout, int.MaxValue - 1));
PreciseTimeSpan wakeupTimeout = nextScheduledTask.Deadline - PreciseTimeSpan.FromStart;
if (wakeupTimeout.Ticks > 0)
{
double timeout = wakeupTimeout.ToTimeSpan().TotalMilliseconds;
this.emptyEvent.Wait((int)Math.Min(timeout, int.MaxValue - 1));
}
}
else
{
this.emptyEvent.Wait();
this.taskQueue.TryDequeue(out task);
}
}
else
{
this.emptyEvent.Wait();
this.taskQueue.TryDequeue(out task);
}
}
if (task != WAKEUP_TASK)
{
return task;
}
}

return task;
}

sealed class NoOpRunnable : IRunnable
Expand Down