Protect again spurious wakeup

Enclose calls to wait in a while loop that re-checks the condition
that caused us to need to wait. This ensures that, in the event of a
spurious wakeup, the condition will be re-checked and we'll wait
again if it has not been satisfied.
Merge branch 'spurious-wakeup'