Skip to content

Commit

Permalink
Remove the modulo operation
Browse files Browse the repository at this point in the history
  • Loading branch information
vasilmkd committed Aug 27, 2021
1 parent 7b34f6e commit 701eb9f
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions core/jvm/src/main/scala/cats/effect/unsafe/WorkerThread.scala
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,17 @@ private final class WorkerThread(
case 0 =>
// Alternate between checking the overflow and batched queues with a
// 2:1 ration in favor of the overflow queue, for now.
((fairness % 3): @switch) match {
(fairness: @switch) match {
case 0 =>
// Dequeue a fiber from the overflow queue.
val fiber = overflow.poll(rnd)
if (fiber ne null) {
// Run the fiber.
fiber.run()
}
fairness = 1

case 1 =>
// Look into the batched queue for a batch of fibers.
val batch = batched.poll(rnd)
if (batch ne null) {
Expand All @@ -266,17 +275,18 @@ private final class WorkerThread(
val fiber = queue.enqueueBatch(batch)
fiber.run()
}
fairness = 2

case _ =>
case 2 =>
// Dequeue a fiber from the overflow queue.
val fiber = overflow.poll(rnd)
if (fiber ne null) {
// Run the fiber.
fiber.run()
}
fairness = 0
}

fairness += 1
// Transition to executing fibers from the local queue.
state = 7

Expand Down

0 comments on commit 701eb9f

Please sign in to comment.