Improve the locking implementation in LockableWindow.

Before: Running all kernel tests took 1 minute and 13 seconds.
Now: Running all kernel tests take 56 seconds.

On my machine. The code is also simpler.