Disable interrupts before ending ISR.
Apparently __sync_bool_compare_and_swap is not 100% reliable...
Check that locking is possible before using scheduler functions.
Fixed various concurrency issues in scheduler.