Scheduler structure & performance improvements
Some performance refactoring, bugfixes, and a little bit of code tidying in the scheduler. Functionally the scheduler is unchanged, but the management of threads, and when work is done, is tweaked.
Edited by Jonathan Mace