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 'WakeupTask' in SingleThreadEventLoop::PollTask #63

Merged
merged 1 commit into from
Jul 1, 2021
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ private bool TryTakeTask(long delayNanos, out IRunnable task)
{
const long MaxDelayMilliseconds = int.MaxValue - 1;

if ((ulong)delayNanos > 0UL) // delayNanos >= 0
if ((ulong)delayNanos > 0UL) // delayNanos 为非负值
{
var timeout = PreciseTime.ToMilliseconds(delayNanos);
if (_blockingTaskQueue.TryTake(out task, (int)Math.Min(timeout, MaxDelayMilliseconds)))
Expand Down
11 changes: 7 additions & 4 deletions src/DotNetty.Transport/Channels/SingleThreadEventLoop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,16 @@ protected sealed override IRunnable PollTask()

Debug.Assert(InEventLoop);

if (_taskQueue.TryDequeue(out IRunnable task)) { return task; }
var taskQueue = _taskQueue;
var task = PollTaskFrom(taskQueue);
if (task is object) { return task; }
#if DEBUG
if (_tailTasks.IsEmpty) { _emptyEvent.Reset(); }
#else
_emptyEvent.Reset();
#endif
if (_taskQueue.TryDequeue(out task) || IsShuttingDown) // revisit queue as producer might have put a task in meanwhile
task = PollTaskFrom(taskQueue);
if (task is object || IsShuttingDown) // revisit queue as producer might have put a task in meanwhile
{
return task;
}
Expand All @@ -158,7 +161,7 @@ protected sealed override IRunnable PollTask()
if (ScheduledTaskQueue.TryPeek(out IScheduledRunnable nextScheduledTask))
{
var delayNanos = nextScheduledTask.DelayNanos;
if ((ulong)delayNanos > 0UL) // delayNanos >= 0
if ((ulong)delayNanos > 0UL) // delayNanos 为非负值
{
var timeout = PreciseTime.ToMilliseconds(delayNanos);
_emptyEvent.Wait((int)Math.Min(timeout, MaxDelayMilliseconds));
Expand All @@ -167,7 +170,7 @@ protected sealed override IRunnable PollTask()
else
{
if (!IsShuttingDown) { _emptyEvent.Wait(); }
_ = _taskQueue.TryDequeue(out task);
task = PollTaskFrom(taskQueue);
}
return task;
}
Expand Down
6 changes: 1 addition & 5 deletions src/DotNetty.Transport/Channels/SingleThreadEventLoopBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,7 @@ public void ExecuteAfterEventLoopIteration(IRunnable task)
Reject(task);
}

if (!(task is ILazyRunnable)
#if DEBUG
&& WakesUpForTask(task)
#endif
)
if (!(task is ILazyRunnable) && WakesUpForTask(task))
{
WakeUp(InEventLoop);
}
Expand Down