[arch][arm-m] Fix a bug with a mismatched acquire/release of the thread lock
[arch][arm-m] Fix a bug with a mismatched acquire/release of the thread lock

Release the thread lock before context switching to a thread that was
preempted and thus not holding the thread lock. Add a few asserts to
make sure this invariant is maintained in the context switch and PENDSV
handler.

This has never mattered before because the thread lock (and other
spinlocks) were not being tested for validity on by definition single
processor cortex-m systems. After adding some code to test the
spinlocks' values this discrepancy was uncovered.

hollanderic/lkstuff,littlekernel/lk,hollanderic/lkstuff,hollanderic/lkstuff,littlekernel/lk,littlekernel/lk,littlekernel/lk,hollanderic/lkstuff