Scheduler Improvements

I've ported some scheduler improvements over from core. The particularly useful one is the scheduler locking, the others are mostly so that I could merge that easily.