Community LockManager lock leak fix

Inline deadlockGuardedWait and change the WaitElement add to only happen once, as it could lead to leftover waits that never got notified, leading to a dead database.