Skip to content

Commit

Permalink
Merge pull request #83 from mtuchkov/schedulefix
Browse files Browse the repository at this point in the history
Hotfix: poll task from the queue.
  • Loading branch information
nayato committed Apr 15, 2016
2 parents e9d3fce + 30806f5 commit db6ae6c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
11 changes: 7 additions & 4 deletions src/DotNetty.Common/Concurrency/SingleThreadEventExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -403,11 +403,14 @@ IRunnable PollTask()
IScheduledRunnable nextScheduledTask = this.ScheduledTaskQueue.Peek();
if (nextScheduledTask != null)
{
TimeSpan wakeUpTimeout = (nextScheduledTask.Deadline - PreciseTimeSpan.FromStart).ToTimeSpan();
if (this.emptyEvent.Wait(wakeUpTimeout))
PreciseTimeSpan wakeupTimeout = nextScheduledTask.Deadline - PreciseTimeSpan.FromStart;
if (wakeupTimeout.Ticks > 0)
{
// woken up before the next scheduled task was due
task = this.taskQueue.Dequeue();
if (this.emptyEvent.Wait(wakeupTimeout.ToTimeSpan()))
{
// woken up before the next scheduled task was due
task = this.taskQueue.Dequeue();
}
}
}
else
Expand Down
6 changes: 6 additions & 0 deletions src/DotNetty.Common/PreciseTimeSpan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,16 @@ public struct PreciseTimeSpan : IComparable<PreciseTimeSpan>, IEquatable<Precise
readonly long ticks;

PreciseTimeSpan(long ticks)
: this()
{
this.ticks = ticks;
}

public long Ticks
{
get { return this.ticks; }
}

public static readonly PreciseTimeSpan Zero = new PreciseTimeSpan(0);

public static readonly PreciseTimeSpan MinusOne = new PreciseTimeSpan(-1);
Expand Down
2 changes: 1 addition & 1 deletion test/DotNetty.Common.Tests/ThreadLocalPoolTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void MaxCapacityTest()
Random rand = new Random();
for (int i = 0; i < 50; i++)
{
this.MaxCapacityTest(rand.Next((1000) + 256)); // 256 - 1256
this.MaxCapacityTest(rand.Next(1000) + 256); // 256 - 1256
}
}

Expand Down

0 comments on commit db6ae6c

Please sign in to comment.