Skip to content
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