This patch refactors some code in WaitOnLock slightly. The old code was slow, and I believe it was off-by-one (it allocates one byte of memory more than needed).
Barring any objections I'll apply this to HEAD later today.
-Neil