this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

internal/core/adt: remove taskPos field from scheduler

taskPos was a struct field tracking the index of the next
unprocessed task. Convert it to a local variable in
process(), which is the only caller. This reduces scheduler
state and is a prerequisite for letting process() handle
only the tasks required by its needs argument in future.

Also add a sanity check in insertTask that panics when a
task has no completes condition, catching invalid task
registrations early.

Signed-off-by: Marcel van Lohuizen <mpvl@gmail.com>
Change-Id: I02972bf15d3014d594a363da5d33698ed942fdb3
Reviewed-on: https://cue.gerrithub.io/c/cue-lang/cue/+/1236063
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>

+8 -7
+8 -7
internal/core/adt/sched.go
··· 280 280 // tasks lists all tasks that were scheduled for this scheduler. 281 281 // The list only contains tasks that are associated with this node. 282 282 // TODO: rename to queue and taskPos to nextQueueIndex. 283 - tasks []*task 284 - taskPos int 283 + tasks []*task 285 284 286 285 // blocking is a list of tasks that are blocked on the completion of 287 286 // the indicate conditions. This can hold tasks from other nodes or tasks ··· 428 427 s.state = schedRUNNING 429 428 // Use variable instead of range, because s.tasks may grow during processes. 430 429 430 + taskPos := 0 431 + 431 432 processNextTask: 432 - for s.taskPos < len(s.tasks) { 433 - t := s.tasks[s.taskPos] 434 - s.taskPos++ 433 + for taskPos < len(s.tasks) { 434 + t := s.tasks[taskPos] 435 + taskPos++ 435 436 436 437 if t.state != taskREADY { 437 438 // TODO(perf): Figure out how it is possible to reach this and if we ··· 512 513 513 514 // The running of tasks above may result in more tasks being added to the 514 515 // queue. Process these first before continuing. 515 - if s.taskPos < len(s.tasks) { 516 + if taskPos < len(s.tasks) { 516 517 goto processNextTask 517 518 } 518 519 ··· 679 680 // Sort by priority. This code is optimized for the case that there are 680 681 // very few tasks with higher priority. This loop will almost always 681 682 // terminate within 0 or 1 iterations. 682 - for i := len(s.tasks) - 1; i > s.taskPos; i-- { 683 + for i := len(s.tasks) - 1; i > 0; i-- { 683 684 if s.tasks[i-1].run.priority <= s.tasks[i].run.priority { 684 685 break 685 686 }