Skip to content

Commit

Permalink
Use a dedicated first-worker
Browse files Browse the repository at this point in the history
Instead of cloning an empty buffer and then pushing with push-worker.
  • Loading branch information
lizmat committed Nov 1, 2017
1 parent 2377624 commit 5d0ccf7
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/core/ThreadPoolScheduler.pm
Expand Up @@ -325,8 +325,7 @@ my class ThreadPoolScheduler does Scheduler {
unless $!general-queue.DEFINITE {
# We don't have any workers yet, so start one.
$!general-queue := nqp::create(Queue);
$!general-workers := push-worker(
nqp::create(IterationBuffer),
$!general-workers := first-worker(
GeneralWorker.new(
queue => $!general-queue,
scheduler => self
Expand All @@ -346,8 +345,7 @@ my class ThreadPoolScheduler does Scheduler {
unless $!timer-queue.DEFINITE {
# We don't have any workers yet, so start one.
$!timer-queue := nqp::create(Queue);
$!timer-workers := push-worker(
nqp::create(IterationBuffer),
$!timer-workers := first-worker(
TimerWorker.new(
queue => $!timer-queue,
scheduler => self
Expand All @@ -370,8 +368,7 @@ my class ThreadPoolScheduler does Scheduler {
if $!affinity-workers.elems == 0 {
# We don't have any affinity workers yet, so start one
# and return its queue.
$!affinity-workers := push-worker(
nqp::create(IterationBuffer),
$!affinity-workers := first-worker(
AffinityWorker.new(
scheduler => self
)
Expand Down Expand Up @@ -435,6 +432,14 @@ my class ThreadPoolScheduler does Scheduler {
}
}

# Initializing a worker list with a worker, is straightforward and devoid
# of concurrency issues, as we're already in protected code when we do this.
sub first-worker(\first) is raw {
my $workers := nqp::create(IterationBuffer);
nqp::push($workers,first);
$workers
}

# Since the worker lists can be changed during copying, we need to
# just take whatever we can get and assume that it may be gone by
# the time we get to it.
Expand Down

0 comments on commit 5d0ccf7

Please sign in to comment.